diff options
Diffstat (limited to 'files/tr/web/css/_colon_focus/index.html')
-rw-r--r-- | files/tr/web/css/_colon_focus/index.html | 117 |
1 files changed, 117 insertions, 0 deletions
diff --git a/files/tr/web/css/_colon_focus/index.html b/files/tr/web/css/_colon_focus/index.html new file mode 100644 index 0000000000..3ee30adbae --- /dev/null +++ b/files/tr/web/css/_colon_focus/index.html @@ -0,0 +1,117 @@ +--- +title: ':focus' +slug: 'Web/CSS/:focus' +tags: + - ':focus' + - CSS + - Layout + - Pseudo-class + - Reference + - Selector + - Web +translation_of: 'Web/CSS/:focus' +--- +<div>{{CSSRef}}</div> + +<p>The <strong><code>:focus</code></strong> <a href="/en-US/docs/Web/CSS">CSS</a> <a href="/en-US/docs/Web/CSS/Pseudo-classes" title="Pseudo-classes">pseudo-class</a> represents an element (such as a form input) that has received focus. It is generally triggered when the user clicks or taps on an element or selects it with the keyboard's <kbd>Tab</kbd> key.</p> + +<pre class="brush: css no-line-numbers notranslate">/* Selects any <input> when focused */ +input:focus { + color: red; +}</pre> + +<div class="blockIndicator note"> +<p><strong>Note:</strong> This pseudo-class applies only to the focused element itself. Use {{CSSxRef(":focus-within")}} if you want to select an element that <em>contains</em> a focused element.</p> +</div> + +<h2 id="Syntax">Syntax</h2> + +<pre class="syntaxbox notranslate">{{CSSSyntax}}</pre> + +<h2 id="Examples">Examples</h2> + +<h3 id="HTML">HTML</h3> + +<pre class="brush: html no-line-numbers notranslate"><input class="red-input" value="I'll be red when focused."><br> +<input class="blue-input" value="I'll be blue when focused."></pre> + +<h3 id="CSS">CSS</h3> + +<pre class="brush: css highlight[1, 6] notranslate">.red-input:focus { + background: yellow; + color: red; +} + +.blue-input:focus { + background: yellow; + color: blue; +}</pre> + +<h3 id="Result">Result</h3> + +<p>{{EmbedLiveSample("Examples")}}</p> + +<h2 id="Accessibility_concerns">Accessibility concerns</h2> + +<p>Make sure the visual focus indicator can be seen by people with low vision. This will also benefit anyone use a screen in a brightly lit space (like outside in the sun). <a href="https://www.w3.org/WAI/WCAG21/Understanding/non-text-contrast.html">WCAG 2.1 SC 1.4.11 Non-Text Contrast</a> requires that the visual focus indicator be at least 3 to 1.</p> + +<ul> + <li>Accessible Visual Focus Indicators: <a href="https://www.deque.com/blog/give-site-focus-tips-designing-usable-focus-indicators/">Give Your Site Some Focus! Tips for Designing Useful and Usable Focus Indicators</a></li> +</ul> + +<h3 id="focus_outline_none"><code>:focus { outline: none; }</code></h3> + +<p>Never just remove the focus outline (visible focus indicator) without replacing it with a focus outline that will pass <a href="https://www.w3.org/WAI/WCAG21/Understanding/non-text-contrast.html">WCAG 2.1 SC 1.4.11 Non-Text Contrast</a>.</p> + +<ul> + <li>Quick Tip: <a href="https://a11yproject.com/posts/never-remove-css-outlines/">Never remove CSS outlines</a></li> +</ul> + +<h2 id="Specifications">Specifications</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName("HTML WHATWG", "scripting.html#selector-focus", ":focus")}}</td> + <td>{{Spec2("HTML WHATWG")}}</td> + <td>Defines HTML-specific semantics.</td> + </tr> + <tr> + <td>{{SpecName("CSS4 Selectors", "#focus-pseudo", ":focus")}}</td> + <td>{{Spec2("CSS4 Selectors")}}</td> + <td>No change.</td> + </tr> + <tr> + <td>{{SpecName("CSS3 Selectors", "#the-user-action-pseudo-classes-hover-act", ":focus")}}</td> + <td>{{Spec2("CSS3 Selectors")}}</td> + <td>No change.</td> + </tr> + <tr> + <td>{{SpecName("CSS2.1", "selector.html#dynamic-pseudo-classes", ":focus")}}</td> + <td>{{Spec2("CSS2.1")}}</td> + <td>Initial definition.</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility">Browser compatibility</h2> + +<div> + + +<p>{{Compat("css.selectors.focus")}}</p> +</div> + +<h2 id="See_also">See also</h2> + +<ul> + <li>{{CSSxRef(":focus-visible")}} {{Experimental_Inline}}</li> + <li>{{CSSxRef(":focus-within")}}</li> +</ul> |