Slide 1

Slide 1 text

%FTJHOFE Writing CSS with Accessibility in Mind *ODMVTJPO GPS Manuel Matuzović @mmatuzo CSSConf Budapest 10/2017

Slide 2

Slide 2 text

Manuel Matuzović @mmatuzo

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

???

Slide 9

Slide 9 text

{ } Look ma, no CSS!

Slide 10

Slide 10 text

{ } Look ma, no CSS!

Slide 11

Slide 11 text

{ } Float? Flexbox? Grid? Pfff!

Slide 12

Slide 12 text

{ } Float? Flexbox? Grid? Pfff! ???

Slide 13

Slide 13 text

{ } Float? Flexbox? Grid? Pfff! Name: Manuel Matuzovic ???

Slide 14

Slide 14 text

{ } HTML tags and attributes for global page styles

Slide 15

Slide 15 text

{ } HTML tags and attributes for global page styles ...

Slide 16

Slide 16 text

CSS 2.1 ❤

Slide 17

Slide 17 text

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 text

CSS 3 ❤

Slide 19

Slide 19 text

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

Slide 20

Slide 20 text

CSS

Slide 21

Slide 21 text

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

Slide 22

Slide 22 text

With great power comes great responsibility Uncle Ben

Slide 23

Slide 23 text

. } a11y_1 font-size {

Slide 24

Slide 24 text

. } a11y_1 font-size {

Slide 25

Slide 25 text

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

Slide 26

Slide 26 text

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

Slide 27

Slide 27 text

. } a11y_2 line-height {

Slide 28

Slide 28 text

. } a11y_2 line-height {

Slide 29

Slide 29 text

No content

Slide 30

Slide 30 text

No content

Slide 31

Slide 31 text

No content

Slide 32

Slide 32 text

. } a11y_3 text-align {

Slide 33

Slide 33 text

No content

Slide 34

Slide 34 text

No content

Slide 35

Slide 35 text

No content

Slide 36

Slide 36 text

. } a11y_4 paragraph width {

Slide 37

Slide 37 text

No content

Slide 38

Slide 38 text

No content

Slide 39

Slide 39 text

DIBSBDUFST QFSMJOF

Slide 40

Slide 40 text

No content

Slide 41

Slide 41 text

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

Slide 42

Slide 42 text

:: } a11y_5 content {

Slide 43

Slide 43 text

No content

Slide 44

Slide 44 text

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

Slide 45

Slide 45 text

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

Slide 46

Slide 46 text

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

Slide 47

Slide 47 text

No content

Slide 48

Slide 48 text

No content

Slide 49

Slide 49 text

{ } Hiding content semantically

Slide 50

Slide 50 text

. } a11y_6 color contrast {

Slide 51

Slide 51 text

. } a11y_6 color contrast {

Slide 52

Slide 52 text

Colors & Color Contrast

Slide 53

Slide 53 text

Colors & Color Contrast ๏ ~285 million people are visually impaired

Slide 54

Slide 54 text

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

Slide 55

Slide 55 text

Colors & Color Contrast ๏ ~285 million people are visually impaired ๏ 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 text

Colors & Color Contrast ๏ ~285 million people are visually impaired ๏ 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 text

Colors & Color Contrast ๏ ~285 million people are visually impaired ๏ 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 text

[…] enough contrast between text and its background so that it can be read by people with moderately low vision […] https://www.w3.org/TR/UNDERSTANDING-WCAG20/visual-audio-contrast-contrast.html

Slide 59

Slide 59 text

Contrast ratio

Slide 60

Slide 60 text

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

Slide 61

Slide 61 text

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

Slide 62

Slide 62 text

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 text

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 text

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 text

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 text

No content

Slide 67

Slide 67 text

No content

Slide 68

Slide 68 text

No content

Slide 69

Slide 69 text

No content

Slide 70

Slide 70 text

No content

Slide 71

Slide 71 text

No content

Slide 72

Slide 72 text

No content

Slide 73

Slide 73 text

No content

Slide 74

Slide 74 text

No content

Slide 75

Slide 75 text

1. Use Chrome Canary 2. Enable experiments: chrome://flags/#enable-devtools- experiments (copy and paste this internal link into Canary) 3. From devtools, open settings (F1) 4. Open the experiments panel 5. Hit shift seven times (no, I'm not kidding) 6. Check the "Color contrast ratio line in color picker" https://remysharp.com/2017/08/17/contrast-ratio-in-devtools

Slide 76

Slide 76 text

No content

Slide 77

Slide 77 text

No content

Slide 78

Slide 78 text

No content

Slide 79

Slide 79 text

No content

Slide 80

Slide 80 text

No content

Slide 81

Slide 81 text

No content

Slide 82

Slide 82 text

No content

Slide 83

Slide 83 text

No content

Slide 84

Slide 84 text

No content

Slide 85

Slide 85 text

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 text

@ } print { media a11y_7

Slide 87

Slide 87 text

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

Slide 88

Slide 88 text

{ } @media print { } .header { position: static; } Add the @media declaration block to your CSS for print specific styles

Slide 89

Slide 89 text

{ } nav { display: none; } @media print { } .header { position: static; } Add the @media declaration block to your CSS for print specific styles

Slide 90

Slide 90 text

{ } body > *:not(main){ display: none; } Hiding all children of except for

Slide 91

Slide 91 text

{ } section { margin-bottom: 2cm; font-size: 14pt; padding: 8mm; } Using absolute units for print styles is absolutely fine

Slide 92

Slide 92 text

{ } 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 text

{ } 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 text

{ } 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 text

{ } 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 text

{ } 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 text

No content

Slide 98

Slide 98 text

No content

Slide 99

Slide 99 text

: } a11y_8 focus {

Slide 100

Slide 100 text

No content

Slide 101

Slide 101 text

No content

Slide 102

Slide 102 text

{ } Button If you need a button, use

Slide 103

Slide 103 text

{ } Button If you need a button, use
Button

Slide 104

Slide 104 text

{ } Button If you need a button, use
Button
Button

Slide 105

Slide 105 text

No content

Slide 106

Slide 106 text

No content

Slide 107

Slide 107 text

{ } *:focus { outline: none; } Don’t just remove the default outline (dotted outline, blue or orange ring) without providing alternate styles.

Slide 108

Slide 108 text

No content

Slide 109

Slide 109 text

No content

Slide 110

Slide 110 text

No content

Slide 111

Slide 111 text

No content

Slide 112

Slide 112 text

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

Slide 113

Slide 113 text

No content

Slide 114

Slide 114 text

No content

Slide 115

Slide 115 text

{ } 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 text

No content

Slide 117

Slide 117 text

No content

Slide 118

Slide 118 text

No content

Slide 119

Slide 119 text

{ } :focus { outline: none; } Applying focus styles only for appropriate input modalities

Slide 120

Slide 120 text

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

Slide 121

Slide 121 text

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

Slide 122

Slide 122 text

https://www.microsoft.com/en-us/design/inclusive

Slide 123

Slide 123 text

https://www.microsoft.com/en-us/design/inclusive

Slide 124

Slide 124 text

https://www.microsoft.com/en-us/design/inclusive

Slide 125

Slide 125 text

Permanent Temporary Situational https://www.microsoft.com/en-us/design/inclusive

Slide 126

Slide 126 text

. } a9y_11 derro {

Slide 127

Slide 127 text

. } a11y_9 order {

Slide 128

Slide 128 text

{ }
  • A delicious drink

Slide 129

Slide 129 text

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

Slide 130

Slide 130 text

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

Slide 131

Slide 131 text

{ } 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 text

{ } 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 text

{ } 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 text

No content

Slide 135

Slide 135 text

No content

Slide 136

Slide 136 text

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

Slide 137

Slide 137 text

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

Slide 138

Slide 138 text

{ } .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 text

{ } .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 text

No content

Slide 141

Slide 141 text

{ } 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 text

No content

Slide 143

Slide 143 text

No content

Slide 144

Slide 144 text

No content

Slide 145

Slide 145 text

No content

Slide 146

Slide 146 text

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 text

. } a11y_10 progressive enhancement {

Slide 148

Slide 148 text

. } a11y_10 progressive enhancement {

Slide 149

Slide 149 text

. } a11y_10 progressive enhancement {

Slide 150

Slide 150 text

No content

Slide 151

Slide 151 text

No content

Slide 152

Slide 152 text

No content

Slide 153

Slide 153 text

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 text

. } a11y_11 flat structures {

Slide 155

Slide 155 text

No content

Slide 156

Slide 156 text

{ }

Heading

  • Element 1
  • Element 2
  • Element 3
  • Element 4
  • Element 5
  • Element 6
A div with two direct child items (h2 and ul)

Slide 157

Slide 157 text

{ } .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 text

No content

Slide 159

Slide 159 text

{ }

Heading

Element 1
Element 2
Element 3
Element 4
Element 5
Element 6
Don’t flatten the structure of your document and compromise on semantics!

Slide 160

Slide 160 text

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

Slide 161

Slide 161 text

{ } 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 text

No content

Slide 163

Slide 163 text

{ } ul { display: grid; grid-template-columns: 120px repeat(2, 1fr); grid-gap: 20px; } Alternative: Defining a nested grid

Slide 164

Slide 164 text

{ } 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 text

{ }

Heading

Element 1
Element 2
Element 3
Element 4
Element 5
Element 6
Don’t flatten the structure of your document and compromise on semantics!

Slide 166

Slide 166 text

{ } Don’t flatten the structure of your document and compromise on semantics!

Slide 167

Slide 167 text

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

Slide 168

Slide 168 text

https://medium.com/@matuzo/

Slide 169

Slide 169 text

No content

Slide 170

Slide 170 text

5IBOLZPV Manuel Matuzović @mmatuzo CSSConf Budapest 10/2017