H IT W S S C E R O M N E V E G WRITIN
D IN M IN Y IT IL ACCESSIB
CSS Cafe September 17th, 2020
matuzo.at
@mmatuzo
Slide 2
Manuel Matuzovic HTML · CSS · a11y · performance City of Vienna · WACA webclerks · HTMHell · Frontend-Bookmarks manuel@matuzo.at · @mmatuzo
@mmatuzo
Slide 3
@mmatuzo
Slide 4
Writing even more CSS with accessibility in mind
• Progressive Enhancement • Respecting User Preferences • Improving Accessibility with CSS • CSS and Semantics @mmatuzo
Slide 5
Progressive Enhancement
@mmatuzo
Slide 6
Progressive Enhancement
@mmatuzo
Slide 7
Progressive Enhancement
@mmatuzo
Slide 8
progressive enhancement
HTML: Foundation / Semantic markup CSS: Design and visual improvements JS: Enhanced experience
@mmatuzo
progressive enhancement <head> <script type=”module”> “// Add the .js class to the <html> element document.documentElement.classList.add(‘js’) “</script> “</head>
@mmatuzo
font size body { “/* Don’t use px for font sizes “*/ font-size: 18px; }
@mmatuzo
Slide 24
font size
target font size base font size
18px 16px
rem size
1.125rem @mmatuzo
Slide 25
font size body { font-size: 1.125rem; “/* 16 * 1.125 = 18px “*/ }
@mmatuzo
Slide 26
Motion and Animation
@mmatuzo
Slide 27
motion and animation
@mmatuzo
Slide 28
Really, there are no words to describe just how bad a simple parallax effect, scrolljacking, or even background-attachment: fixed would make me feel. I would rather jump on one of those 20-G centrifuges astronauts use than look at a website with parallax scrolling. Facundo Corradini
@mmatuzo
Slide 29
The extreme, conscious, focused effort it took to read would make it such that anything moving on the screen would instantly break my focus, and force me to start the paragraph all over. And I mean anything. Facundo Corradini
@mmatuzo
Slide 30
motion and animation @keyframes walk { 0% { transform: translateX(100vw); } } img { animation: walk 10s linear infinite; } @media (prefers-reduced-motion: reduce) { img { animation: none; } }
@mmatuzo
Slide 31
motion and animation
<picture> <source srcset=”moonwalk.jpg” media=”(prefers-reduced-motion: reduce)” “/> <img src=”moonwalk.gif” alt=”Someone doing the moonwalk” “/> “</picture>
@mmatuzo
Slide 32
@mmatuzo
Slide 33
motion and animation img { animation: walk 10s linear infinite; } div { transition: transform 1s ease-in; } “/* has no effect in browsers that don’t support prefers-reduced-motion “*/ @media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
@mmatuzo
Slide 34
@mmatuzo
Slide 35
motion and animation “/* has no effect in browsers that don’t support prefers-reduced-motion “*/
@media (prefers-reduced-motion: no-preference) { img { animation: walk 10s linear infinite; } div { transition: transform 1s ease-in; } } @mmatuzo
Slide 36
motion and animation @media (prefers-reduced-motion: no-preference) { html { scroll-behavior: smooth; } }
@mmatuzo
Slide 37
Improving .a y with CSS @mmatuzo
Slide 38
Explaining user interfaces
@mmatuzo
Slide 39
Explaining user interfaces <a href=”menu.html”> Our Menu
Our Menu
“</a>
<a href=”menu.pdf” download> Our Menu
Our Menu
“</a>
@mmatuzo
Debugging accessibility Root element with empty or missing lang attribute.
html:not([lang]), html[lang=” “], html[lang=”“], html:not(:lang(en))
{
border: 10px solid red; }
@mmatuzo
Slide 53
Debugging accessibility Elements with the class .btn or .button that are not real HTML buttons.
.btn:not(button):not([type=”button”]):not([type=”submit”]), .button:not(button):not([type=”button”]):not([type=”submit”]) { outline: 2px dashed red; outline-offset: 2px; }
@mmatuzo
Slide 54
Debugging accessibility Elements with the class .btn or .button that are not real HTML buttons.
.btn:not(button):not([type=”button”]):not([type=”submit”]), .button:not(button):not([type=”button”]):not([type=”submit”]) { outline: 2px dashed red; outline-offset: 2px; }
@mmatuzo
Slide 55
Debugging accessibility Elements with the class .btn or .button that are not real HTML buttons.
.btn:not(button):not([type=”button”]):not([type=”submit”]), .button:not(button):not([type=”button”]):not([type=”submit”]) { outline: 2px dashed red; outline-offset: 2px; }
@mmatuzo
Slide 56
Debugging accessibility Elements with the class .btn or .button that are not real HTML buttons.
.btn:not(button):not([type=”button”]):not([type=”submit”]), .button:not(button):not([type=”button”]):not([type=”submit”]) { outline: 2px dashed red; outline-offset: 2px; }
@mmatuzo