Designed for Inclusion: Writing CSS with Accessibility in Mind

A presentation at CSS Conf Budapest in October 2017 in Budapest, Hungary by Manuel Matuzovic

Slide 1

Slide 1

%FTJHOFE Writing CSS with Accessibility in Mind *ODMVTJPO GPS Manuel Matuzovi ć

   @mmatuzo 

CSSConf Budapest 10/2017

Slide 2

Slide 2

Manuel Matuzovi ć @mmatuzo

Slide 3

Slide 3

Slide 4

Slide 4

Slide 5

Slide 5

Slide 6

Slide 6

Slide 7

Slide 7

Slide 8

Slide 8

???

Slide 9

Slide 9

{ }

<frameset cols = "17%,*,17%"

border

"0"

noresize

""

frameborder

"0"

</frameset> Look ma, no CSS!

Slide 10

Slide 10

{ }

<frameset cols = "17%,*,17%"

border

"0"

noresize

""

frameborder

"0"

</frameset> Look ma, no CSS! <frame noresize= "" scrolling= "auto" src= "left.html" > <frame name= "main" noresize= "" scrolling= "auto" src= "start.html" > <frame noresize= "" scrolling= "auto" src= "right.html" >

Slide 11

Slide 11

{ }

<table cellspacing = "0"

cellpadding

"0"

bordercolor

"#004400"

border

"1"

bgcolor

"#006700"

align

"left"

width

"442%"

Float? Flexbox? Grid? Pfff! <table> !

Slide 12

Slide 12

{ }

<table cellspacing = "0"

cellpadding

"0"

bordercolor

"#004400"

border

"1"

bgcolor

"#006700"

align

"left"

width

"442%"

Float? Flexbox? Grid? Pfff! <table> ! ???

Slide 13

Slide 13

{ }

<table cellspacing = "0"

cellpadding

"0"

bordercolor

"#004400"

border

"1"

bgcolor

"#006700"

align

"left"

width

"442%"

Float? Flexbox? Grid? Pfff! <table> !

<tbody> <tr> <td width= "23%" > Name: </td> <td> Manuel Matuzovic </td> </tr> </tbody> </table> ???

Slide 14

Slide 14

{ }

<body link = "004600"

text

"ffffff"

bgcolor

"005600"

alink

"004600"

vlink

"004600"

HTML tags and a

ributes for global page styles

Slide 15

Slide 15

{ }

<body link = "004600"

text

"ffffff"

bgcolor

"005600"

alink

"004600"

vlink

"004600"

HTML tags and a

ributes for global page styles

<font size= "4" face= "arial"

<table>
  ... 
</table> </font> </body>

Slide 16

Slide 16

CSS 2.1 ❤

Slide 17

Slide 17

CSS 2.1 float position text-align overflow border visibility background-repeat color font-size max-height margin line-height clip display ❤

Slide 18

Slide 18

CSS 3 ❤

Slide 19

Slide 19

CSS 3 border-radius box-shadow te xt-shadow background-size text-overflow transform transition column animation calc() gradients web fonts

Slide 20

Slide 20

CSS

Slide 21

Slide 21

CSS Flexbox Grid Custom properties (CSS variables) Feature queries (@supports) Filters Shapes blend-modes Scroll Snap   Points sticky :not()

Slide 22

Slide 22

With great power comes great responsibility Uncle Ben

Slide 23

Slide 23

. } a11y_1 font-size {

Slide 24

Slide 24

. } a11y_1 font-size {

Slide 25

Slide 25

Zeit Online 20px CSS-Tricks 21px Medium 21px CSSConf Budapest 20px Jeffrey Zeldman 24px Max Böck 22px

Slide 26

Slide 26

h

ps://blog.marvelapp.com/body-text-small/

Slide 27

Slide 27

. } a11y_2 line-height {

Slide 28

Slide 28

. } a11y_2 line-height {

Slide 29

Slide 29

Slide 30

Slide 30

Slide 31

Slide 31

Slide 32

Slide 32

. } a11y_3 text-align {

Slide 33

Slide 33

Slide 34

Slide 34

Slide 35

Slide 35

Slide 36

Slide 36

. } a11y_4 paragraph width {

Slide 37

Slide 37

Slide 38

Slide 38

Slide 39

Slide 39

DIBSBDUFST QFSMJOF

Slide 40

Slide 40

Slide 41

Slide 41

{ } p {

max-width : 65ch ; } ch represents the width of the glyph „0“ in the element’s font.

Slide 42

Slide 42

:: } a11y_5 content {

Slide 43

Slide 43

Slide 44

Slide 44

{ } h2::after {

content : "DON'T DO THIS" ; } Don’t add text via CSS.

Slide 45

Slide 45

{ } span ::before {

content : "\00d7" ; } ::before and ::after are great for adding icons and symbols

Slide 46

Slide 46

{ } span ::before {

content : "\00d7" ; } ::before and ::after are great for adding icons and symbols →

Slide 47

Slide 47

Slide 48

Slide 48

Slide 49

Slide 49

{ } <span aria-hidden

"true"

class

"icon icon--times"

</span>

Hiding content semantically

Slide 50

Slide 50

. } a11y_6
color contrast {

Slide 51

Slide 51

. } a11y_6 color contrast {

Slide 52

Slide 52

Colors & Color Contrast

Slide 53

Slide 53

Colors & Color Contrast ๏ ~285 million people are visually impaire d

Slide 54

Slide 54

Colors & Color Contrast ๏ ~285 million people are visually impaire d ๏ 39 million are blind and 246 million have low vision

Slide 55

Slide 55

Colors & Color Contrast ๏ ~285 million people are visually impaire d ๏ 39 million are blind and 246 million have low vision ๏ 7 to 12% of men and less than 1% of women have some form of color-vision deficiency

Slide 56

Slide 56

Colors & Color Contrast ๏ ~285 million people are visually impaire d ๏ 39 million are blind and 246 million have low vision ๏ 7 to 12% of men and less than 1% of women have some form of color-vision deficiency ๏ People dim their screens

Slide 57

Slide 57

Colors & Color Contrast ๏ ~285 million people are visually impaire d ๏ 39 million are blind and 246 million have low vision ๏ 7 to 12% of men and less than 1% of women have some form of color-vision deficiency ๏ People dim their screens ๏ People use their smartphones outside even when the sun is shining

Slide 58

Slide 58

[…] enough contrast between text and its background so that it can be read by people with moderately low vision

[…] h

ps://www.w3.org/TR/UNDERSTANDING-WCAG20/visual-audio-contrast-contrast.html

Slide 59

Slide 59

Contrast ratio

Slide 60

Slide 60

Contrast ratio ๏ 1:1 same color for text and background

Slide 61

Slide 61

Contrast ratio ๏ 1:1 same color for text and background ๏ 1:21 black text on white background and vice versa

Slide 62

Slide 62

Contrast ratio ๏ 1:1 same color for text and background ๏ 1:21 black text on white background and vice versa ๏ Minimum ratio for normal text less than 24px 4.5:1

Slide 63

Slide 63

Contrast ratio ๏ 1:1 same color for text and background ๏ 1:21 black text on white background and vice versa ๏ Minimum ratio for normal text less than 24px 4.5:1

๏ Minimum ratio for bold text less than 19px 3:1

Slide 64

Slide 64

Contrast ratio ๏ 1:1 same color for text and background ๏ 1:21 black text on white background and vice versa ๏ Minimum ratio for normal text less than 24px 4.5:1

๏ Minimum ratio for bold text less than 19px 3:1

๏ Larger text: 3:1

Slide 65

Slide 65

Contrast ratio ๏ 1:1 same color for text and background ๏ 1:21 black text on white background and vice versa ๏ Minimum ratio for normal text less than 24px 4.5:1

๏ Minimum ratio for bold text less than 19px 3:1

๏ Larger text: 3:1 ๏ Level AAA: At least 7:1 and 4.5:1

Slide 66

Slide 66

Slide 67

Slide 67

Slide 68

Slide 68

Slide 69

Slide 69

Slide 70

Slide 70

Slide 71

Slide 71

Slide 72

Slide 72

Slide 73

Slide 73

Slide 74

Slide 74

Slide 75

Slide 75

Use Chrome Canary 2. Enable experiments: chrome://flags/#enable-devtools- experiments (copy and paste this internal link into Canary) 3. From devtools, open se

ings (F1) 4. Open the experiments panel 5. Hit shi $ seven times (no, I'm not kidding) 6. Check the "Color contrast ratio line in color picker" h

ps://remysharp.com/2017/08/17/contrast-ratio-in-devtools

Slide 76

Slide 76

Slide 77

Slide 77

Slide 78

Slide 78

Slide 79

Slide 79

Slide 80

Slide 80

Slide 81

Slide 81

Slide 82

Slide 82

Slide 83

Slide 83

Slide 84

Slide 84

Slide 85

Slide 85

Though age has indeed taken its toll on my eyesight, it turns out that I was suffering from a design trend. Kevin Marks

Slide 86

Slide 86

@ } print { media a11y_7

Slide 87

Slide 87

{ } @ media print {

} Add the @media declaration block to your CSS for print specific styles

Slide 88

Slide 88

{ } @ media print {

} .header {

position : static; }

Add the @media declaration block to your CSS for print specific styles

Slide 89

Slide 89

{ }

nav {

display : none; } @ media print {

} .header {

position : static; }

Add the @media declaration block to your CSS for print specific styles

Slide 90

Slide 90

{ } body

*:not(main){

display : none; } Hiding all children of

<body> except for <main>

Slide 91

Slide 91

{ } section {

margin-bottom : 2cm ;

font-size : 14pt ;

padding : 8mm ; } Using absolute units for print styles is absolutely fine

Slide 92

Slide 92

{ } a [href^="http"]:not([href*="mywebsite.com"]):: after {

content : " ("

attr (href) ")" ; } Selecting all links with an absolute link except links to your site

Slide 93

Slide 93

{ } a [href^="http"]:not([href*="mywebsite.com"]):: after {

content : " ("

attr (href) ")" ; } a [href^="http"] Selecting all links with an absolute link except links to your site

Slide 94

Slide 94

{ } a [href^="http"]:not([href*="mywebsite.com"]):: after {

content : " ("

attr (href) ")" ; } :not([href*="mywebsite.com"]) Selecting all links with an absolute link except links to your site

Slide 95

Slide 95

{ } a [href^="http"]:not([href*="mywebsite.com"]):: after {

content : " ("

attr (href) ")" ; } Selecting all links with an absolute link except links to your site :: after

Slide 96

Slide 96

{ } a [href^="http"]:not([href*="mywebsite.com"]):: after {

content : " ("

attr (href) ")" ; } " ("

attr (href)

")" Selecting all links with an absolute link except links to your site

Slide 97

Slide 97

Slide 98

Slide 98

Slide 99

Slide 99

: } a11y_8 focus {

Slide 100

Slide 100

Slide 101

Slide 101

Slide 102

Slide 102

{ } <button> Button </button> If you need a bu

on, use <button>

Slide 103

Slide 103

{ } <button> Button </button> If you need a bu

on, use <button>

<div class= "btn" > Button </div>

Slide 104

Slide 104

{ } <button> Button </button> If you need a bu

on, use <button>

<div class= "btn" > Button </div> <div class= "btn" tabindex="0" > Button </div>

Slide 105

Slide 105

Slide 106

Slide 106

Slide 107

Slide 107

{ } *:focus {

outline : none; } D on’t just remove the default outline (do

ed outline, blue or orange ring) without providing alternate styles.

Slide 108

Slide 108

Slide 109

Slide 109

Slide 110

Slide 110

Slide 111

Slide 111

Slide 112

Slide 112

{ } input :focus {

outline : 2px solid #000000 ; } :focus pseudo class for custom focus styles

Slide 113

Slide 113

Slide 114

Slide 114

Slide 115

Slide 115

{ } form :focus-within {

box-shadow : 0

0

4px

6px #000000 ; } :focus-within select an element which has child elements that are currently focused.

Slide 116

Slide 116

Slide 117

Slide 117

Slide 118

Slide 118

Slide 119

Slide 119

{ } :focus {

outline : none; }

Applying focus styles only for appropriate input modalities

Slide 120

Slide 120

{ } :focus {

outline : none; }

:focus-ring {

outline : 2px solid blue; } Applying focus styles only for appropriate input modalities

Slide 121

Slide 121

h

ps://github.com/WICG/focus-ring

Slide 122

Slide 122

h

ps://www.microso $ .com/en-us/design/inclusive

Slide 123

Slide 123

h

ps://www.microso $ .com/en-us/design/inclusive

Slide 124

Slide 124

h

ps://www.microso $ .com/en-us/design/inclusive

Slide 125

Slide 125

Permanent Temporary Situational h

ps://www.microso $ .com/en-us/design/inclusive

Slide 126

Slide 126

. } a9y_11 derro {

Slide 127

Slide 127

. } a11y_9 order {

Slide 128

Slide 128

{ }

<ul> <li>

<a href= "#"

<img src= "/drink3.jpg" alt= "A delicious drink" />

</a> </li>

</ul>

Slide 129

Slide 129

{ } ul {

} A grid with as many 180px wide columns as possible

Slide 130

Slide 130

{ } ul {

} display : grid; A grid with as many 180px wide columns as possible

Slide 131

Slide 131

{ } ul {

} display : grid;

grid-template-columns : repeat (auto-fill, minmax(180px, 1fr)); A grid with as many 180px wide columns as possible

Slide 132

Slide 132

{ } ul {

} display : grid;

grid-template-columns : repeat (auto-fill, minmax(180px, 1fr));

grid-gap : 20px ; A grid with as many 180px wide columns as possible

Slide 133

Slide 133

{ } ul {

} display : grid;

grid-template-columns : repeat (auto-fill, minmax(180px, 1fr));

grid-gap : 20px ;

grid-auto-rows : 180px ; A grid with as many 180px wide columns as possible

Slide 134

Slide 134

Slide 135

Slide 135

Slide 136

Slide 136

{ } CSS Grid Layout explicit placement .long {

grid-row : span 2 ; }

Slide 137

Slide 137

{ } .large {

grid-row : span 2 ; } CSS Grid Layout explicit placement .long {

grid-row : span 2 ; }

Slide 138

Slide 138

{ } .large {

grid-row : span 2 ; } CSS Grid Layout explicit placement .long {

grid-row : span 2 ; } .large1 {

grid-column : span 2 / - 1 ; }

Slide 139

Slide 139

{ } .large {

grid-row : span 2 ; } CSS Grid Layout explicit placement .long {

grid-row : span 2 ; } .large1 {

grid-column : span 2 / - 1 ; } .large2 {

grid-column : 1 / span 2 ; }

Slide 140

Slide 140

Slide 141

Slide 141

{ } ul {

display : grid;

grid-template-columns : repeat (auto-fill, minmax(180px, 1fr));

grid-gap : 20px ;

grid-auto-rows : 180px ;

grid-auto-flow: dense ; } grid-auto-flow tries to fill the gaps in a grid

Slide 142

Slide 142

Slide 143

Slide 143

Slide 144

Slide 144

Slide 145

Slide 145

Slide 146

Slide 146

Properties that affect order ๏ Flexbox (flex-direction, order,…) ๏ position ๏ float ๏ Negative margins ๏ Grid (order, grid-auto-flow, grid-row, grid-column,…)

Slide 147

Slide 147

. } a11y_10 progressive enhancement {

Slide 148

Slide 148

. } a11y_10 progressive enhancement {

Slide 149

Slide 149

. } a11y_10 progressive enhancement {

Slide 150

Slide 150

Slide 151

Slide 151

Slide 152

Slide 152

Slide 153

Slide 153

You Don’t Have To Overwrite Everything ๏ display: inline-block ๏ display: table-cell ๏ vertical-align ๏ column-*   properties ๏ float …have no effect on grid- or flex-items

Slide 154

Slide 154

. } a11y_11 flat structures {

Slide 155

Slide 155

Slide 156

Slide 156

{ }

<div class = "wrapper" > <h2> Heading </h2> <ul> <li> Element 1 </li> <li> Element 2 </li> <li> Element 3 </li> <li> Element 4 </li> <li> Element 5 </li> <li> Element 6 </li> </ul> </div> A div with two direct child items ( h2 and ul )

Slide 157

Slide 157

{ } .wrapper {

display : grid;

grid-template-columns : 120px

repeat (2, 1fr);

grid-gap : 20px ; } h2 {

grid-column : 2 / - 1 ; } A grid with 3 columns

Slide 158

Slide 158

Slide 159

Slide 159

{ }

<div class = "wrapper" > <h2> Heading </h2> <div> Element 1 </div> <div> Element 2 </div> <div> Element 3 </div> <div> Element 4 </div> <div> Element 5 </div> <div> Element 6 </div> </div> Don’t fla # en the structure of your document and compromise on semantics !

Slide 160

Slide 160

{ } ul {

display : subg rid; } display: subgrid didn’t make it into level 1 of the specification.

Slide 161

Slide 161

{ } ul {

display : contents ; } display: contents causes an element's children to appear as if they were direct children of the element's parent .

Slide 162

Slide 162

Slide 163

Slide 163

{ } ul { display : grid;

grid-template-columns : 120px

repeat (2, 1fr);

grid-gap : 20px ; } Alternative: Defining a nested grid

Slide 164

Slide 164

{ } ul {

grid-column : 1 / - 1 ;

display : inherit;

grid-template-columns : inherit;

grid-gap : inherit;

display : contents; } It’s possible to inherit grid properties

Slide 165

Slide 165

{ }

<div class = "wrapper" > <h2> Heading </h2> <div> Element 1 </div> <div> Element 2 </div> <div> Element 3 </div> <div> Element 4 </div> <div> Element 5 </div> <div> Element 6 </div> </div> Don’t fla # en the structure of your document and compromise on semantics!

Slide 166

Slide 166

{ } Don’t fla

en the structure of your document and compromise on semantics!

Slide 167

Slide 167

Designing with constraints in mind is simply designing well. Aaron Gustafson

Slide 168

Slide 168

h

ps://medium.com/@matuzo/

Slide 169

Slide 169

Slide 170

Slide 170

5IBOLZPV $ Manuel Matuzovi ć

   @mmatuzo 

CSSConf Budapest 10/2017