Skip to content

Commit a2b2f22

Browse files
patrickhlaukealastcmbgower
authored
Add sufficient technique for 2.4.7 using :focus-visible (#3272)
Two years late, but: here's the technique I intended to write for #301 (comment) (but a recent lengthy discussion on mailing list reminded me that back in #301 the WG had indeed agreed this interpretation) [Preview of new techinque](https://raw.githack.com/w3c/wcag/patrickhlauke-focus-visible-technique/techniques/css/C45.html) --------- Co-authored-by: Alastair Campbell Co-authored-by: Mike Gower
1 parent ce91353 commit a2b2f22

File tree

7 files changed

+178
-27
lines changed

7 files changed

+178
-27
lines changed

techniques/css/C15.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,15 @@

Expected Results

100100
ul>
101101
section>
102102
section>
103+
<section id="related">
104+
<h2>Related Techniquesh2>
105+
<ul>
106+
<li><a href="../general/G165">G165a>li>
107+
<li><a href="../general/G195">G195a>li>
108+
<li><a href="C40">C40a>li>
109+
<li><a href="C45">C45a>li>
110+
ul>
111+
section>
103112
<section id="resources">
104113
<h2>Resourcesh2>
105114
<ul>

techniques/css/C40.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@

Related Techniques

7171
<ul>
7272
<li><a href="../general/G149">G149a>li>
7373
<li><a href="../general/G195">G195a>li>
74+
<li><a href="C15">C15a>li>
75+
<li><a href="../general/G165">G165a>li>
76+
<li><a href="C45">C45a>li>
7477
ul>
7578
section>
7679
<section id="resources">

techniques/css/C45.html

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
>
2+
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
3+
<head>
4+
<title>Using CSS :focus-visible to provide keyboard focus indicationtitle>
5+
<link rel="stylesheet" type="text/css" href="../../css/editors.css"/>
6+
head>
7+
<body>
8+
<h1>Using <abbr title="Cascading Style Sheets">CSSabbr> <code class="language-css">:focus-visiblecode> to provide keyboard focus indicationh1>
9+
<section id="meta">
10+
<h2>Metadatah2>
11+
<p id="id">p>
12+
<p id="technology">CSSp>
13+
<p id="type">p>
14+
section>
15+
<section id="applicability">
16+
<h2>When to Useh2>
17+
<p>All technologies that support CSS.p>
18+
section>
19+
<section id="description">
20+
<h2>Descriptionh2>
21+
<p>The objective of this technique is to provide custom styles for interactive elements when they receive keyboard focus. In this example, this is achieved using the CSS <code class="language-css">:focus-visiblecode> pseudo-class.p>
22+
<p>Styles defined with the regular <code class="language-css">:focuscode> pseudo-class are applied whenever an element has focus, regardless of how it received focus. In contrast, user agents apply additional heuristics and logic to decide when to show <code class="language-css">:focus-visiblecode> styles – in particular, browsers always show these styles when a user is navigating using the keyboard, but will generally <em>notem> show them as a result of a mouse/pointer interaction (with the exception of elements that also support keyboard input, such as <code><input>code> elements). This allows authors to provide strong visible focus indication for keyboard users, without forcing them on mouse/pointer users who may not necessarily want or need them (for instance, because they find them visually distracting).p>
23+
<p>This satisfies the requirement of providing a <q>mode of operation where the keyboard focus indicator is visibleq>.p>
24+
<div class="note">
25+
<p>This technique is only sufficient <em>ifem> it uses styles that provide a <em>visibleem> focus indicator.p>
26+
div>
27+
<div class="note">
28+
<p>There may be situations where mouse/pointer users could also benefit from having a visible focus indicator, even though they did not set focus to an element using the keyboard. As a best practice, consider still providing an explicit <code class="language-css">:focuscode> style for these cases.p>
29+
div>
30+
section>
31+
<section id="examples">
32+
<h2>Examplesh2>
33+
<section class="example">
34+
<h3>Using <abbr title="Cascading Style Sheets">CSSabbr> <code class="language-css">:focus-visiblecode> to provide keyboard focus indicationh3>
35+
<p>In this example, we have a standard <code><button>code> control in the HTML.p>
36+
<p>By default, in all modern browsers, this button does not show any focus indication when activated using a mouse/pointer. Browsers show their default focus outline/indication when a user sets focus on the button using <kbd>Tabkbd>.p>
37+
<p>In order to make this focus indication more prominent, we use the <code class="language-css">:focus-visiblecode> pseudo-class selector to define a more intentional and pronounced focus style.p>
38+
<p>Working example: <a href="../../working-examples/css-focus-visible/">Using CSS <code class="language-css">:focus-visiblecode> to provide keyboard focus indicationa>.p>
39+
<pre><code><!DOCTYPE html>
40+
<html lang="en">
41+
<head>
42+
<meta charset="utf-8">
43+
<meta name="viewport" content="width=device-width,
44+
initial-scale=1, shrink-to-fit=no">
45+
<title>Using CSS :focus-visible to
46+
provide keyboard focus indication</title>
47+
<style>
48+
/* Specific :focus-visible styles */
49+
50+
:focus-visible {
51+
outline: 5px solid red;
52+
}
53+
54+
</style>
55+
</head>
56+
<body>
57+
58+
<button>Example button</button>
59+
60+
</body>
61+
</html>code>pre>
62+
section>
63+
section>
64+
<section id="tests">
65+
<h2>Testsh2>
66+
<section class="test-procedure">
67+
<h3>Procedureh3>
68+
<p>For each user interface component that can receive keyboard focus:p>
69+
<ol>
70+
<li>Set focus to the interface component using the keyboard (generally, navigating to the component using <kbd>Tabkbd>/<kbd>Shift+Tabkbd>)li>
71+
<li>Verify that once the component has received focus, a focus indicator is visibleli>
72+
ol>
73+
section>
74+
<section class="test-results">
75+
<h3>Expected Resultsh3>
76+
<ul>
77+
<li>Check 2 is true.li>
78+
ul>
79+
section>
80+
section>
81+
<section id="related">
82+
<h2>Related Techniquesh2>
83+
<ol>
84+
<li><a href="C15">C15a>li>
85+
<li><a href="../general/G165">G165a>li>
86+
<li><a href="../general/G195">G195a>li>
87+
<li><a href="C40">C40a>li>
88+
ol>
89+
section>
90+
<section id="resources">
91+
<h2>Resourcesh2>
92+
<ol>
93+
<li><a href="https://www.w3.org/TR/selectors-4/#the-focus-visible-pseudo">CSS Selectors Level 4 - <code class="language-css">:focus-visiblecode> pseudo-classa>.li>
94+
<li><a href="https://developer.mozilla.org/en-US/docs/Web/CSS/:focus-visible"><abbr title="Mozilla Developer Network">MDNabbr> - <code class="language-css">:focus-visiblecode> pseudo-classa>.li>
95+
ol>
96+
section>
97+
body>
98+
html>

techniques/general/G165.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@
2727
ul>
2828
section>
2929
section><section id="related"><h2>Related Techniquesh2><ul>
30-
<li><a href="../general/G149">G149a>li>
30+
<li><a href="G149">G149a>li>
3131
<li><a href="../css/C15">C15a>li>
3232
<li><a href="../client-side-script/SCR31">SCR31a>li>
33+
<li><a href="../css/C15">C15a>li>
34+
<li><a href="G195">G195a>li>
35+
<li><a href="../css/C40">C40a>li>
36+
<li><a href="../css/C45">C45a>li>
3337
ul>section>body>html>

techniques/general/G195.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,10 @@

Menus

3939
ul>
4040
section>
4141
section><section id="related"><h2>Related Techniquesh2><ul>
42-
<li><a href="../general/G149">G149a>li>
43-
<li><a href="../general/G165">G165a>li>
42+
<li><a href="G149">G149a>li>
43+
<li><a href="G165">G165a>li>
4444
<li><a href="../css/C15">C15a>li>
4545
<li><a href="../client-side-script/SCR31">SCR31a>li>
46+
<li><a href="../C40">C40a>li>
47+
<li><a href="../C45">C45a>li>
4648
ul>section>body>html>

understanding/20/focus-visible.html

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,12 @@

Intent of Focus Visible

2727
p>
2828

2929
<p>“Mode of operation” accounts for user agents which may not always show a focus indicator, or only show the focus indicator when the keyboard is used. User agents may optimise when the focus indicator is shown, such as only showing it when a keyboard is used. Authors are responsible for providing at least one mode of operation where the focus is visible. In most cases there is only one mode of operation so this success criterion applies. The focus indicator must not be time limited, when the keyboard focus is shown it must remain.p>
30+
31+
<div class="note">
32+
<p>There may be situations where mouse/pointer users could also benefit from having a visible focus indicator, even though they did not set focus to an element using the keyboard. As a best practice, consider still providing an explicit focus indicator for these cases.p>
33+
div>
3034

31-
<p>Note that a keyboard focus indicator can take different forms.<span class="wcag22"> While Focus Visible does not specify what that form is, <a href="focus-appearance">2.4.13 Focus Appearance (Level AAA)a> provides guidance on creating a consistent, visible indicator.span>p>
35+
<p>Note that a keyboard focus indicator can take different forms. <span class="wcag22">While Focus Visible does not specify what that form is, <a href="focus-appearance">2.4.13 Focus Appearance (Level AAA)a> provides guidance on creating a consistent, visible indicator.span>p>
3236

3337
section>
3438
<section id="benefits">
@@ -83,52 +87,46 @@

Techniques for Focus Visible

8387

8488
<section id="sufficient">
8589
<h3>Sufficient Techniques for Focus Visibleh3>
86-
87-
8890
<ul>
89-
9091
<li>
92+
9193

9294
<a href="../Techniques/general/G149" class="general">Using user interface components that are highlighted by the user agent when they receive
9395
focus
9496
a>
95-
9697
li>
97-
9898
<li>
99+
99100

100101
<a href="../Techniques/css/C15" class="css">Using CSS to change the presentation of a user interface component when it receives
101102
focus
102103
a>
103-
104104
li>
105-
106105
<li>
106+
107107

108108
<a href="../Techniques/general/G165" class="general">G165: Using the default focus indicator for the platform so that high visibility default
109109
focus indicators will carry over
110110
a>
111-
112111
li>
113-
114112
<li>
113+
115114

116115
<a href="../Techniques/general/G195" class="general">Using an author-supplied, highly visible focus indicatora>
117116

118-
li>
119117

118+
li>
120119
<li>
121120
<a href="../../techniques/css/C40">Creating a two-color focus indicator to ensure sufficient contrasta>
122121
li>
123-
124122
<li>
125-
123+
<a href="../../techniques/css/C45">Using CSS :focus-visible to provide keyboard focus indicationa>
124+
li>
125+
<li>
126126
<a href="../Techniques/client-side-script/SCR31" class="script">Using script to change the background color or border of the element with focusa>
127-
127+
128128
li>
129-
130129
ul>
131-
132130
section>
133131

134132
<section id="advisory">
@@ -138,28 +136,21 @@

Additional Techniques (Advisory) for Focus Visible

138136

139137
<section id="failure">
140138
<h3>Failures for Focus Visibleh3>
141-
142-
143139
<ul>
144-
145140
<li>
141+
146142

147143
<a href="../Techniques/failures/F55" class="failure">Failure of Success Criterion 2.1.1, 2.4.7, and 3.2.1 due to using script to remove
148144
focus when focus is received
149145
a>
150-
151146
li>
152-
153147
<li>
154148

155149
<a href="../Techniques/failures/F78" class="failure">Failure due to styling element outlines and borders in a way that overrides or renders
156150
non-visible the default visual focus indicator
157151
a>
158-
159152
li>
160-
161153
ul>
162-
163154
section>
164155

165156
section>
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
6+
<title>Using CSS :focus-visible to provide keyboard focus indicationtitle>
7+
<style>
8+
9+
/* Specific :focus-visible styles */
10+
11+
:focus-visible {
12+
outline: 5px solid red;
13+
}
14+
15+
/* General styles for the example */
16+
17+
body {
18+
font-family: Noto Sans,Trebuchet MS,Helvetica Neue,Arial,sans-serif;
19+
background-color: #fafafc;
20+
color: #222;
21+
margin: 0;
22+
padding: 1em;
23+
}
24+
25+
pre {
26+
background-color: #f0f0f0;
27+
border: 1px solid #888;
28+
padding: 0.5em;
29+
}
30+
31+
style>
32+
head>
33+
34+
<body>
35+
<h1>Using <abbr title="Cascading Style Sheets">CSSabbr> <code class="language-css">:focus-visiblecode> to provide keyboard focus indicationh1>
36+
<p>In this example, we have a standard <code><button>code> control in the HTML.p>
37+
38+
<button>Example buttonbutton>
39+
40+
<p>By default, in all modern browsers, this button does not show any focus indication when activated using a mouse/pointer. Browsers show their default focus outline/indication when a user sets focus on the button using <kbd>Tabkbd>.p>
41+
<p>In order to make this focus indication more prominent, we use the <code class="language-css">:focus-visiblecode> pseudo-class selector to define a more intentional and pronounced focus style.p>
42+
<pre><code>:focus-visible { outline: 5px solid red; }code>pre>
43+
body>
44+
html>

0 commit comments

Comments
 (0)