SlideShare a Scribd company logo
ACCESSIBLE CODE
PATTERNS
francesco bedussi
inspired by
Inclusive design pattern by Heydon Pickering
unfortunately, we have a habit of
overengineering and overcomplicating
things
targeting a so-called average user is a
disastrus interface design strategy,
because average users do not exist
Heydon Pickering
average user
all the rest
ACCESSIBILITY, WHY?
It involves a lot of people: Though estimates vary,
most studies find that about one fi h (20%) of the
population has some kind of disability
Search engine spiders are severely "impaired", so an
accessible site is also a search engine friendly site
We have to. Governments (especially USA) are
enforcing accessibility by legislation
ACCESSIBILITY, FOR
WHOM?
Vision impairments
Limited fine motor control
Cognitive disabilities (rings a bell? :-P )
Hearing impairments
Older people (ourselves tomorrow)
CHECKLIST
People who don't use a mouse should be able to use
a site
People who don't look at a screen should be able to
use a site
A site's content should be visually legible
People should have control over automatic changes
to the page
PATTERNS VS
PRINCIPLES
INDEX
document
navigation
(menu) button
page
paragraph
list of products
filter widget
registration form
DOCUMENT
DOCUMENT
THE LANG ATTRIBUTE
on html element, on any inner element
:lang(en) pseudo-class
ALLOW PINCH-TO-ZOOM
DON'T
DO
<meta name="viewport" content="width=device-width,
initial-scale=1.0, minimum-scale=1.0,
maximum-scale=1.0, user-scalable=no">
<meta name="viewport" content="width=device-width,
initial-scale=1.0">
FONT SIZES
do
don't
html {
font-size: 100%;
}
html {
font-size: 16px;
}
responsive font-size
html { font-size: calc(1em + 1vw); }
Font loading
prefer FOUT over FOIT
load web fonts asynchronously
use proper title element
use the main element
BONUS: PRINT ONLY THE MAIN
ELEMENT
@media print {
body > *:not(main) {
display: none;
}
}
SKIP TO MAIN CONTENT
for sighted keyboard users
[href="#main"] {
position: absolute;
top: 0;
right: 100%; /* moves off screen*/
}
[href="#main"]:focus {
right: auto;
}
NAVIGATION
NAVIGATION
a menu should look like a menu
HOME ABOUT PRODUCTS CONTACTS
a menu is a nav containing an ul
identify the current page link...
...but not with color alone
A NAVIGATION EXAMPLE
<header role="banner">
<a href="#main">
<img src="images/logo.svg" alt="My project home">
</a>
<nav>
<ul>
<li><a href="#main">home</a></li>
<li><a href="/about">about</a></li>
<li><a href="/products">products</a></li>
</ul>
</nav>
</header>
TABLE OF CONTENTS
if you hijack the link to implement smooth scroll don't
forget to manage the focus
<nav class="toc" aria-labelledby="contents-heading">
<h2 id="contents-heading">Contents</h2>
<ul>
<li><a href="#history">Our history</a></li>
<li><a href="#services">The services we offer</a></li>
<li><a href="#office">Visit our office</a></li>
</ul>
</nav>
(MENU) BUTTON
(MENU) BUTTON
(hamburger) icon + label + button appearance
min touch target size: 48x48px
<nav aria-label="site">
<button aria-expanded="false">
<svg><use xlink:href="#navicon"></use></svg>
menu
</button>
<ul hidden>
<li><a href="#main">home</a></li>
<li><a href="/about">about</a></li>
<li><a href="/products">products</a></li>
</ul>
</nav>
critical JS (vanilla, to be included at the end of the
page)
(function() {
var button = document.querySelector('[aria-label="site"] button
var menu = button.nextElementSibling;
button.setAttribute('aria-expanded', 'false');
button.hidden = false;
menu.hidden = true;
button.addEventListener('click', function() {
var expanded = this.getAtrtribute('aria-expanded') === 'tru
this.setAttribute('aria-expanded', String(!expanded));
menu.hidden = expanded;
});
})();
PAGE
PAGE
HEADINGS
describe nested sections
one h1 per page
never skip a level
never use a heading for a subtitle
VIDEO
use captions: non-native speakers, for people
watching video with audio turned off (e.g. public
places), for deaf and hard of hearing
use keyboard and screen reader accessible players
(e.g. YouTube, it provides captions too)
provide a transcript (linearized version of captions)
VERTICAL FLOW
Use paragraph line-height as basis for vertical spacing:
e.g if the line-height is 1.5, then one unit of vertical
whitespace should be 1.5rem:
note the use of the
main * + * {
margin-top: 1.5rem;
}
owl selector
.VISUALLYHIDDEN
.visuallyHidden {
position: absolute;
width: 1px;
height: 1px;
overflow: hidden;
clip: rect(1px, 1px, 1px, 1px);
}
TRICKS
DEFENSIVE CODING
FORCEFEED.JS
allows you to feed the layout with random content of
different length
main :empty {
display: none;
}
PARAGRAPH
PARAGRAPH
the ideal length of a line is around 60 characters
main {max-width: 60rem;}
no justification
line height ~1.5
p { line-height: 1.5; /*unitless!*/}
avoid extremely high or extremely low contrast
keep the standard link style (blue, underlined)
whenever possible, eventually improve it
never ever just remove focus style, eventually
replace it
LIST OF PRODUCTS
LIST OF PRODUCTS
code products list as <ul>
use self-governing grid
.grid {display: flex; flex-wrap: wrap;}
.grid li {flex-grow: 1; flex-shrink: 1; flex-basis: 10em}
KEY INFORMATION
group key pieces of information in a definition list:
<dl>
<dt>Size:</dt>
<dd>90cm x 30xm</dd>
<dt>Price:</dt>
<dd>€35.95</dd>
</dl>
IMAGES
provide alt text only if it adds meaning
optimize & lazy load images
CTA
if the cta is a link do not style it as a button...
...but use some visual clue (e.g. color) common to
links, buttons, ctas to indicate their interactivity
if cta is a link style it using tag + class selector, e.g.
a.call-to-action
include the product name, eventually visually
hidden, in the cta label
buttons do not have an hand cursor
AVOID LINK WRAPPING PRODUCT
BLOCK
it doesn't have a dedicated label
produces unexpected behavior in some screen
readers
on touch device it can be pressed accidentally
USE MICRODATA TO ENHANCE
SERP
<main id="main" itemscope itemtype="http://schema.org/Product">
<h1>
<span itemprop="name">Naked man in garage forecourt</span
<a href="/artist/kenny-mulbarton">by Kenny Mulbarton</a
</h1>
<img itemprop="image" src="images/naked-forecourt-man.jpg"
<dl>
<dt>Size: </dt>
<dd>90cm &times; 30cm</dd>
<dt>Price: </dt>
<dd>
<span itemprop="offers" itemscope itemtype="http://sche
<meta itemprop="priceCurrency" content="EUR" />
€<span itemprop="price">35.95</span>
</span>
</dd>
LOADING MORE RESULTS
avoid infinite scroll
prefer a "load more" button
remember to manage focus
and to communicate that the loading is in progress
1. click on "load more"
2. the button is disabled and its label changed in
"loading"
3. a hidden live region announces "loading more
products"
4. the request is handled
5. on success the content is rendered
6. the live region announces "products loaded"
7. focus is moved to the first of the new products
8. the "load more" button reverts to its original status
A FILTER WIDGET
A FILTER WIDGET
leverage HTML behavior
visually hide radio buttons and style labels based on
radio buttons status
use live regions to communicate that the content is
being fetched
do not remove the submit button
A REGISTRATION
FORM
A REGISTRATION FORM
LOGIN/REGISTER TOOLBAR
<h1>Welcome</h1>
<div role="toolbar" aria-label="login or register">
<button aria-pressed="true">Login</button>
<button aria-pressed="false">Register</button>
</div>
<div id="forms">
<div id="login">
<form>
<!-- login form -->
</form>
</div>
<div id="register">
<form>
<!-- registration form -->
</form>
USE LABELS!!!
placeholders are not labels, they are hints on how to
fill in the field
<fieldset> are pointless without <legend>
use aria-required="true" and prefer it over
required html attribute
give the possibility to show password
mark error message containers as aria-
live="assertive"
use aria-invalid="true" on field that do not
pass the validation (it can be used as a CSS selector
as well)
provide a hint on why the field is invalid

More Related Content

Similar to Accessible code-patterns

Css 2c (2) (1) (1) (2)
Css 2c (2) (1) (1) (2)Css 2c (2) (1) (1) (2)
Css 2c (2) (1) (1) (2)
gng542
 
HTML5 and the dawn of rich mobile web applications pt 2
HTML5 and the dawn of rich mobile web applications pt 2HTML5 and the dawn of rich mobile web applications pt 2
HTML5 and the dawn of rich mobile web applications pt 2
James Pearce
 
GDI Seattle Intermediate HTML and CSS Class 1
GDI Seattle Intermediate HTML and CSS Class 1GDI Seattle Intermediate HTML and CSS Class 1
GDI Seattle Intermediate HTML and CSS Class 1
Heather Rock
 

Similar to Accessible code-patterns (20)

Create Responsive Website Design with Bootstrap 3
Create Responsive Website Design with Bootstrap 3Create Responsive Website Design with Bootstrap 3
Create Responsive Website Design with Bootstrap 3
 
“Good design is obvious. Great design is transparent.” — How we use Bootstrap...
“Good design is obvious. Great design is transparent.” — How we use Bootstrap...“Good design is obvious. Great design is transparent.” — How we use Bootstrap...
“Good design is obvious. Great design is transparent.” — How we use Bootstrap...
 
Semantic accessibility
Semantic accessibilitySemantic accessibility
Semantic accessibility
 
Joomla!Day 2013 Nürnberg; Vortrag von Johannes Hock
Joomla!Day 2013 Nürnberg; Vortrag von Johannes HockJoomla!Day 2013 Nürnberg; Vortrag von Johannes Hock
Joomla!Day 2013 Nürnberg; Vortrag von Johannes Hock
 
HTML5 apps for iOS (and probably beyond)
HTML5 apps for iOS (and probably beyond)HTML5 apps for iOS (and probably beyond)
HTML5 apps for iOS (and probably beyond)
 
Css 2c (2) (1) (1) (2)
Css 2c (2) (1) (1) (2)Css 2c (2) (1) (1) (2)
Css 2c (2) (1) (1) (2)
 
Responsive & Responsible Web Design in DNN
Responsive & Responsible Web Design in DNNResponsive & Responsible Web Design in DNN
Responsive & Responsible Web Design in DNN
 
Sperimentazioni lezione6 from_designtoapplication copy
Sperimentazioni lezione6 from_designtoapplication copySperimentazioni lezione6 from_designtoapplication copy
Sperimentazioni lezione6 from_designtoapplication copy
 
Xxx
XxxXxx
Xxx
 
Responsive design
Responsive designResponsive design
Responsive design
 
Keyboard and Interaction Accessibility Techniques
Keyboard and Interaction Accessibility TechniquesKeyboard and Interaction Accessibility Techniques
Keyboard and Interaction Accessibility Techniques
 
Day of code
Day of codeDay of code
Day of code
 
Building iPad apps with Flex - 360Flex
Building iPad apps with Flex - 360FlexBuilding iPad apps with Flex - 360Flex
Building iPad apps with Flex - 360Flex
 
HTML5 and the dawn of rich mobile web applications pt 2
HTML5 and the dawn of rich mobile web applications pt 2HTML5 and the dawn of rich mobile web applications pt 2
HTML5 and the dawn of rich mobile web applications pt 2
 
GDI Seattle Intermediate HTML and CSS Class 1
GDI Seattle Intermediate HTML and CSS Class 1GDI Seattle Intermediate HTML and CSS Class 1
GDI Seattle Intermediate HTML and CSS Class 1
 
P.S. I love you
P.S. I love youP.S. I love you
P.S. I love you
 
Web Accessibility for the 21st Century
Web Accessibility for the 21st CenturyWeb Accessibility for the 21st Century
Web Accessibility for the 21st Century
 
DG Group - Active Or Passive Website
DG Group - Active Or Passive WebsiteDG Group - Active Or Passive Website
DG Group - Active Or Passive Website
 
Bootstrap 3
Bootstrap 3Bootstrap 3
Bootstrap 3
 
Stole16
Stole16Stole16
Stole16
 

Recently uploaded

一比一原版UTS毕业证悉尼科技大学毕业证成绩单如何办理
一比一原版UTS毕业证悉尼科技大学毕业证成绩单如何办理一比一原版UTS毕业证悉尼科技大学毕业证成绩单如何办理
一比一原版UTS毕业证悉尼科技大学毕业证成绩单如何办理
aagad
 
Living-in-IT-era-Module-7-Imaging-and-Design-for-Social-Impact.pptx
Living-in-IT-era-Module-7-Imaging-and-Design-for-Social-Impact.pptxLiving-in-IT-era-Module-7-Imaging-and-Design-for-Social-Impact.pptx
Living-in-IT-era-Module-7-Imaging-and-Design-for-Social-Impact.pptx
TristanJasperRamos
 
Article writing on excessive use of internet.pptx
Article writing on excessive use of internet.pptxArticle writing on excessive use of internet.pptx
Article writing on excessive use of internet.pptx
abhinandnam9997
 

Recently uploaded (12)

Latest trends in computer networking.pptx
Latest trends in computer networking.pptxLatest trends in computer networking.pptx
Latest trends in computer networking.pptx
 
Multi-cluster Kubernetes Networking- Patterns, Projects and Guidelines
Multi-cluster Kubernetes Networking- Patterns, Projects and GuidelinesMulti-cluster Kubernetes Networking- Patterns, Projects and Guidelines
Multi-cluster Kubernetes Networking- Patterns, Projects and Guidelines
 
1.Wireless Communication System_Wireless communication is a broad term that i...
1.Wireless Communication System_Wireless communication is a broad term that i...1.Wireless Communication System_Wireless communication is a broad term that i...
1.Wireless Communication System_Wireless communication is a broad term that i...
 
一比一原版UTS毕业证悉尼科技大学毕业证成绩单如何办理
一比一原版UTS毕业证悉尼科技大学毕业证成绩单如何办理一比一原版UTS毕业证悉尼科技大学毕业证成绩单如何办理
一比一原版UTS毕业证悉尼科技大学毕业证成绩单如何办理
 
ER(Entity Relationship) Diagram for online shopping - TAE
ER(Entity Relationship) Diagram for online shopping - TAEER(Entity Relationship) Diagram for online shopping - TAE
ER(Entity Relationship) Diagram for online shopping - TAE
 
The+Prospects+of+E-Commerce+in+China.pptx
The+Prospects+of+E-Commerce+in+China.pptxThe+Prospects+of+E-Commerce+in+China.pptx
The+Prospects+of+E-Commerce+in+China.pptx
 
History+of+E-commerce+Development+in+China-www.cfye-commerce.shop
History+of+E-commerce+Development+in+China-www.cfye-commerce.shopHistory+of+E-commerce+Development+in+China-www.cfye-commerce.shop
History+of+E-commerce+Development+in+China-www.cfye-commerce.shop
 
How to Use Contact Form 7 Like a Pro.pptx
How to Use Contact Form 7 Like a Pro.pptxHow to Use Contact Form 7 Like a Pro.pptx
How to Use Contact Form 7 Like a Pro.pptx
 
The AI Powered Organization-Intro to AI-LAN.pdf
The AI Powered Organization-Intro to AI-LAN.pdfThe AI Powered Organization-Intro to AI-LAN.pdf
The AI Powered Organization-Intro to AI-LAN.pdf
 
Living-in-IT-era-Module-7-Imaging-and-Design-for-Social-Impact.pptx
Living-in-IT-era-Module-7-Imaging-and-Design-for-Social-Impact.pptxLiving-in-IT-era-Module-7-Imaging-and-Design-for-Social-Impact.pptx
Living-in-IT-era-Module-7-Imaging-and-Design-for-Social-Impact.pptx
 
Article writing on excessive use of internet.pptx
Article writing on excessive use of internet.pptxArticle writing on excessive use of internet.pptx
Article writing on excessive use of internet.pptx
 
BASIC C++ lecture NOTE C++ lecture 3.pptx
BASIC C++ lecture NOTE C++ lecture 3.pptxBASIC C++ lecture NOTE C++ lecture 3.pptx
BASIC C++ lecture NOTE C++ lecture 3.pptx
 

Accessible code-patterns

  • 1. ACCESSIBLE CODE PATTERNS francesco bedussi inspired by Inclusive design pattern by Heydon Pickering
  • 2. unfortunately, we have a habit of overengineering and overcomplicating things targeting a so-called average user is a disastrus interface design strategy, because average users do not exist Heydon Pickering
  • 4. ACCESSIBILITY, WHY? It involves a lot of people: Though estimates vary, most studies find that about one fi h (20%) of the population has some kind of disability Search engine spiders are severely "impaired", so an accessible site is also a search engine friendly site We have to. Governments (especially USA) are enforcing accessibility by legislation
  • 5. ACCESSIBILITY, FOR WHOM? Vision impairments Limited fine motor control Cognitive disabilities (rings a bell? :-P ) Hearing impairments Older people (ourselves tomorrow)
  • 6. CHECKLIST People who don't use a mouse should be able to use a site People who don't look at a screen should be able to use a site A site's content should be visually legible People should have control over automatic changes to the page
  • 8. INDEX document navigation (menu) button page paragraph list of products filter widget registration form
  • 10. DOCUMENT THE LANG ATTRIBUTE on html element, on any inner element :lang(en) pseudo-class
  • 11.
  • 12. ALLOW PINCH-TO-ZOOM DON'T DO <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
  • 13. FONT SIZES do don't html { font-size: 100%; } html { font-size: 16px; }
  • 14. responsive font-size html { font-size: calc(1em + 1vw); }
  • 15. Font loading prefer FOUT over FOIT load web fonts asynchronously
  • 16. use proper title element use the main element
  • 17. BONUS: PRINT ONLY THE MAIN ELEMENT @media print { body > *:not(main) { display: none; } }
  • 18. SKIP TO MAIN CONTENT for sighted keyboard users [href="#main"] { position: absolute; top: 0; right: 100%; /* moves off screen*/ } [href="#main"]:focus { right: auto; }
  • 20. NAVIGATION a menu should look like a menu HOME ABOUT PRODUCTS CONTACTS
  • 21.
  • 22. a menu is a nav containing an ul identify the current page link... ...but not with color alone
  • 23. A NAVIGATION EXAMPLE <header role="banner"> <a href="#main"> <img src="images/logo.svg" alt="My project home"> </a> <nav> <ul> <li><a href="#main">home</a></li> <li><a href="/about">about</a></li> <li><a href="/products">products</a></li> </ul> </nav> </header>
  • 24. TABLE OF CONTENTS if you hijack the link to implement smooth scroll don't forget to manage the focus <nav class="toc" aria-labelledby="contents-heading"> <h2 id="contents-heading">Contents</h2> <ul> <li><a href="#history">Our history</a></li> <li><a href="#services">The services we offer</a></li> <li><a href="#office">Visit our office</a></li> </ul> </nav>
  • 26. (MENU) BUTTON (hamburger) icon + label + button appearance min touch target size: 48x48px <nav aria-label="site"> <button aria-expanded="false"> <svg><use xlink:href="#navicon"></use></svg> menu </button> <ul hidden> <li><a href="#main">home</a></li> <li><a href="/about">about</a></li> <li><a href="/products">products</a></li> </ul> </nav>
  • 27.
  • 28. critical JS (vanilla, to be included at the end of the page) (function() { var button = document.querySelector('[aria-label="site"] button var menu = button.nextElementSibling; button.setAttribute('aria-expanded', 'false'); button.hidden = false; menu.hidden = true; button.addEventListener('click', function() { var expanded = this.getAtrtribute('aria-expanded') === 'tru this.setAttribute('aria-expanded', String(!expanded)); menu.hidden = expanded; }); })();
  • 29. PAGE
  • 30. PAGE HEADINGS describe nested sections one h1 per page never skip a level never use a heading for a subtitle
  • 31.
  • 32. VIDEO use captions: non-native speakers, for people watching video with audio turned off (e.g. public places), for deaf and hard of hearing use keyboard and screen reader accessible players (e.g. YouTube, it provides captions too) provide a transcript (linearized version of captions)
  • 33. VERTICAL FLOW Use paragraph line-height as basis for vertical spacing: e.g if the line-height is 1.5, then one unit of vertical whitespace should be 1.5rem: note the use of the main * + * { margin-top: 1.5rem; } owl selector
  • 34. .VISUALLYHIDDEN .visuallyHidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(1px, 1px, 1px, 1px); }
  • 35. TRICKS DEFENSIVE CODING FORCEFEED.JS allows you to feed the layout with random content of different length main :empty { display: none; }
  • 37. PARAGRAPH the ideal length of a line is around 60 characters main {max-width: 60rem;} no justification line height ~1.5 p { line-height: 1.5; /*unitless!*/} avoid extremely high or extremely low contrast keep the standard link style (blue, underlined) whenever possible, eventually improve it never ever just remove focus style, eventually replace it
  • 38.
  • 40. LIST OF PRODUCTS code products list as <ul> use self-governing grid .grid {display: flex; flex-wrap: wrap;} .grid li {flex-grow: 1; flex-shrink: 1; flex-basis: 10em}
  • 41.
  • 42. KEY INFORMATION group key pieces of information in a definition list: <dl> <dt>Size:</dt> <dd>90cm x 30xm</dd> <dt>Price:</dt> <dd>€35.95</dd> </dl>
  • 43. IMAGES provide alt text only if it adds meaning optimize & lazy load images
  • 44. CTA if the cta is a link do not style it as a button... ...but use some visual clue (e.g. color) common to links, buttons, ctas to indicate their interactivity if cta is a link style it using tag + class selector, e.g. a.call-to-action include the product name, eventually visually hidden, in the cta label buttons do not have an hand cursor
  • 45. AVOID LINK WRAPPING PRODUCT BLOCK it doesn't have a dedicated label produces unexpected behavior in some screen readers on touch device it can be pressed accidentally
  • 46. USE MICRODATA TO ENHANCE SERP <main id="main" itemscope itemtype="http://schema.org/Product"> <h1> <span itemprop="name">Naked man in garage forecourt</span <a href="/artist/kenny-mulbarton">by Kenny Mulbarton</a </h1> <img itemprop="image" src="images/naked-forecourt-man.jpg" <dl> <dt>Size: </dt> <dd>90cm &times; 30cm</dd> <dt>Price: </dt> <dd> <span itemprop="offers" itemscope itemtype="http://sche <meta itemprop="priceCurrency" content="EUR" /> €<span itemprop="price">35.95</span> </span> </dd>
  • 47. LOADING MORE RESULTS avoid infinite scroll prefer a "load more" button remember to manage focus and to communicate that the loading is in progress
  • 48. 1. click on "load more" 2. the button is disabled and its label changed in "loading" 3. a hidden live region announces "loading more products" 4. the request is handled 5. on success the content is rendered 6. the live region announces "products loaded" 7. focus is moved to the first of the new products 8. the "load more" button reverts to its original status
  • 50. A FILTER WIDGET leverage HTML behavior visually hide radio buttons and style labels based on radio buttons status use live regions to communicate that the content is being fetched do not remove the submit button
  • 51.
  • 53. A REGISTRATION FORM LOGIN/REGISTER TOOLBAR <h1>Welcome</h1> <div role="toolbar" aria-label="login or register"> <button aria-pressed="true">Login</button> <button aria-pressed="false">Register</button> </div> <div id="forms"> <div id="login"> <form> <!-- login form --> </form> </div> <div id="register"> <form> <!-- registration form --> </form>
  • 54.
  • 55. USE LABELS!!! placeholders are not labels, they are hints on how to fill in the field
  • 56. <fieldset> are pointless without <legend> use aria-required="true" and prefer it over required html attribute give the possibility to show password mark error message containers as aria- live="assertive" use aria-invalid="true" on field that do not pass the validation (it can be used as a CSS selector as well) provide a hint on why the field is invalid