Accessibility Tutorial
Accessibility Tutorial
A Brief History
The principle that everyone should be able to use the web equally, regardless
of any disability, is as important today as it was twenty years ago. People
who have limited use of their arms, people who cannot hear or see well and
people who process information differently, should all be able to access and
use web sites and apps. Web technologies have many built in features for
accessibility, and we as web developers should know them so that we do not
exclude any of our users.
Milestones
1995: Dr. Cynthia
Dr. Cynthia Waddel published a web design accessibility standard for the City
of San Jose’s Office of Equality Assurance. One of the requirements in the
standard was that all images must have alternative text. This is one rule that
is still valid today. Another requirement was that all pages should support
text browsers. That is not something we aim for any longer, even though text
browsers still exist.
Even though her standard became an important starting point for other well
known standards and guidelines, she is better known for the accessibility
testing software Cynthia Says.
1996: Bobby
The accessibility testing software Bobby was released a couple of years
before Cynthia Says. Bobby worked much the same way many of the current
testing tools are working. HTML code was tested against a set of rules, and
the results was a list of issues. Instead of a browser extension, that did not
exist back then, you uploaded a local HTML file.
1997: Web Accessibility Initiative (WAI)
The Web Accessibility Initiative started as a W3C project in 1996. This
initiative is mostly known for the Web Content Accessibility Guidelines
(WCAG). They also provide a variety of strategies and resources for web
accessibility.
2001: Wave
Another accessibility testing tool. First released by Dr. Len Kasday and then
taken over by WebAIM in 2003. Still a popular tool by many developers and
accessibility experts.
Accessibility Diversity
Accessibility Semantic
Elements
Semantic elements = elements with a
meaning.
Provide the user a good way to navigate and interact with your site. Make
your HTML semantic. Semantics is about using the correct element in HTML.
There are approximately 110 elements in HTML 5.
Two of them have no meaning – <div> and <span>. They tell us nothing
about the content. They have no built in accessibility features, so we should
always check to see if any other elements are better suited. Example of
semantic elements: <form>, <table> and <article>. They clearly define
the content.
Look online
● A heading
● A paragraph
● A button
● A link
● An image
● <h2>
● <p>
● <button>
● <a>
● <img>
Is this correct? Even though Sign up to drive looks like a button, Uber has
used a <a> instead of a <button>. This is the code, a bit simplified:
<h2>Get in the driver's seat and get paid</h2>
The <button> element should be used for any interaction that performs an action on
the current page. The <a> element should be used for any interaction that navigates
to another view.
Now that you have learned the basics of semantics, let us check which
semantic elements we have in our HTML toolbox. Next up, landmarks.
Accessibility Landmarks
Why
With landmarks, blind users using a screen reader have the ability to jump to
sections of a web page.
What
In HTML there are some semantic elements that can be used to define
different parts of a web page:
● <header>
● <nav>
● <main>
● <aside>
● <section>
● <footer>
One way to visualize landmarks is to use the tool Accessibility Insights. One
of the features is that it highlights the landmarks, as we can see in the
following screenshot.
Try it yourself. Download the browser extension Accessibility Insights and
turn on the landmark visualization. Is your favorite site using landmarks?
Roles
But wait, it shows banner, contentinfo and navigation. This is a bit
confusing. The reason is that each landmark element has a corresponding
role. We have not talked about roles in this course so far. We will get back to
this, but as a simplified explanation:
A <header> has a built in role of banner. This means that both <header>,
<header role="banner"> and <div role="banner"> are more or less
equivalent. For most cases, <header> will be sufficient.
The same is true for <nav>, which has role="navigation" built in. <main>
is easier, it has role="main". And then we have <footer> with its
role="contentinfo". Let us leave the roles for now.
In the footer of The White House, we have three <nav>s, each with an aria-
label, like aria-label="social navigation". This means that a screen
reader user can skip directly to the social navigation. A helping hand. Some
will say that to use the wording "navigation" as a part of the label of a <nav>
is redundant. There is no right and wrong, but aria-label="social" should
be fine.
What
The <button> element should be used for any
interaction that performs an action on the current page.
The <a> element should be used for any interaction that
navigates to another view.
How
In the introduction, we saw that the visual design does not dictate which
HTML element we should use. A link that looks like a button, but behaves like
a link, is an <a>.
Both the "button" Sign up to drive and the link underneath is coded as an
<a>. So when should we use a <button>, then?
Let us take a closer look at the website of Uber. The first section of the
header has five elements – a logo, a dropdown menu and three links. One of
them is coded as a <button>.
Clicking Company opens a drop down menu. This is an interaction that
performs an action on the current page. Using <button> here is the correct
thing to do. The underlying links, About us, Our offerings and so on, are
correctly coded with <a> elements.
The arrow indicates that this is a button with a dropdown menu, that changes
direction when opened. This is a nice extra visual cue.
One benefit with this, is that semantic HTML gives context to screen readers,
which read the contents of a page out loud. You will learn more about screen
readers in module 7 about assistive technologies.
Both a link and a button are accessible for people relying on keyboard-only
navigation; it can be clickable with both mouse and keys, and it can be
tabbed between using the tab key on the keyboard.
Now you know when to use a <button> and when to use an <a>. What else
should you keep in mind?
Proper links
Links take users from one page to another, or sometimes to another part of
the page. For a link to be accessible, remember to:
The link About us from the Uber example is coded like this, a bit simplified:
What
There are two cases where we can't use a good HTML element with built-in
accessibility features, even though we want to:
How
How do we make sure that custom components have a role, a name and a
value?
Role
In our last section, Button and Links, we learned that a dropdown menu
button should be coded as a <button>. What if our framework does not allow
us to do that? If it forces us to use an <a> instead? If the navigation
component in the library we are using, is built with <a>s? Then we need to
add a role.
Name
The custom control needs a name. In our example, the name is the content of
the element, Company. As long as we have written our element like <div
role="button">Company</div>, we have a good name. This is also known
as the accessible name. The accessible name for our <div> is Company.
Good.
That was too easy. In the following login form, we have several components –
a logo, a heading, a label, a dropdown, an input and a button.
We are taking a closer look at the label, dropdown and the input. Visually
there is no clear distinction between the dropdown and the input. The
dropdown is coded with a <select>, which is a correct element for this case.
However, it has no name:
<select name="countryCode">…</select>
It has a name attribute. This is not the same as an accessible name. This is
confusing. The article What is an accessible name? explains this further. The
name attribute is for computers. In a <form>, it is used as a reference when
the data is submitted. This name countryCode will not help any users. It will
not be picked up by assistive technologies.
To give this <select> an accessible name, we must use the attribute aria-
label. Normally, we would have connected a visual label to the <select>
component. In this case, there is only one visual label for both the
components.
Value
Some components have a value or a state. An accordion is open or closed.
This information has to be accessible.
Good. It has the role of a button. It also has a name, the content of the div.
To give this button a value, we need to tell assistive technologies that it is
closed. This is done with aria-expanded="false":
What
We measure contrast between text or graphics against the background color.
This is called contrast ratio. A white text on a white background has a
contrast ratio of 1. This is impossible to perceive. Black text on a white
background has a contrast ratio of 21.
How
One way to measure the color contrast is to use a tool like Contrast Ratio.
This accepts multiple color inputs, like RGB, HSL and hex. It even supports
transparency, like RGBA.
ADVERTISEMENT
Example from Foodora
Foodora uses the color Royal Red as their main profile color. The color has
the hex code #D60265. On white, the color contrast is 5.17. This is good for
decorations, icons, logo and buttons. If Foodora had used this color for bigger
chunks of text, the readability would have been poor.
Text on images
To measure contrast on text on top of a background image, we need to find
the brightest or darkest part of the image. If the text is bright, look for the
brightest part and vice versa.
In this example from Wolt, we have white text on a bright background image.
Using a color picker on a light green section gives us the hex value #a1ad95.
This is a contrast ratio of 2.35. Not sufficient. One possible improvement is to
add a color overlay on that part of the picture with text. The overlay can be
solid or have a degree of opacity.
Different states
Any interactive component has different states – hover, focus, active,
unvisited, visited and deactivated. Remember to ensure that the states also
have good contrast. Working with states, we have to think about two
scenarios:
What
Do not use color as the only visual indicator of a meaning.
Wikipedia is one example where color alone is used for styling links. In the
grayscale version of the site, it is not possible to see what is plain text and
what is a link.
How
Underlined links
Add underline to links. Or, do not remove them. Keep in mind that they can
reduce readability.
Color as status
Add text and/or icons to communicate meaning, in addition to color.
Tools
Note: The following tools gives a rating for the contrast assuming that you are using it
as text color.
The tool Contrast Ratio uses color to communicate if a color contrast is good
or not. Red means bad contrast. In this example you might say that the
number is another indicator. That is a valid argument. However, you are then
assuming that the user understands the metric contrast ratio and knows
about the guidelines.
The tool Coolors Color Contrast Checker uses three methods to tell us
whether or not a color combination is good:
● The red color tells us that the contrast is bad.
● The text Very poor tells us that the contrast is b… very poor.
● 1 of 5 stars tells us that this is really bad.
●
What
Some images are meaningful and some are decorative. This is an important
distinction in terms of accessibility. Every image must be coded as
meaningful or decorative.
How
You will learn how to separate meaningful from decorative images.
Decorative images
If an image is not important for a user to understand the functionality or the
content of a web page or app, it is considered decorative. Can you remove it
with no impact? Then it is a decorative image.
<img src="Ha50044a3568449409f3396e5b36be8c3h.png_80x80q80.jpg"
alt="">
Assistive technologies, like a screen reader will then ignore the image.
Without the empty alt attribute, a screen reader may read the file name.
This will make no sense, and will confuse the user.
Background images
Another method for decorative images is to add them using the CSS
background-image property. This is common when we create hero images.
Font icons
At the bottom of the mobile version of Alibaba, we have five links that are
combinations of icons and text – Home, Feeds, Messenger, Cart and My
Alibaba. Since the site is still readable if we remove the icons, they are
decorative. The icons are created with font icons. No <img> element and no
background image. Add role="img" and aria-hidden="true":
With this code, we add some semantics to the <i> with the image role. User
agents now understand that this is an image. Screen readers also understand
that they should ignore the image.
Meaningful images
Most of our images are meaningful. In this example from Alibaba, we have six
images:
● Logo
● Search icon
● Coffee
● Jacket
● 1 year badge
● Gold badge
The only decorative image here is the search icon. This is decorative because
of the text Search Products. If the icon for open search had been stand-alone,
it would have been a meaningful image.
As with decorative images, we have several methods for coding meaning
images.
In this example from Alibaba, the logo is there for two reasons. First of all, to
tell the users which site they are on. Second, to provide the users a link back
to the front page.
Inaccessible:
<img src="TB1hVGkvVP7gK0jSZFjXXc5aXXa-365-49.svg">
Better:
Best:
● Add role="img"
● Add a descriptive aria-label or aria-labelledby attribute.
<div role="img" aria-label="Private house, modern
architecture. Minimalistic with a big garage.">
Now you know how to code decorative and meaningful images. Next you will
learn what to write as descriptive text for meaningful images.
What
The value of the alt attribute should describe the image, or even better the
intention of the image.
How
You will learn how to add descriptive text for non-interactive images, stand-
alone icons and logos.
Non-interactive images
Imagine you were to explain a web page over a phone call with a friend, what
would you say about an image? This is a good technique for writing
descriptive image texts.
Editorial images
In this screenshot from an article on Medium, there is an image of Google
cofounder Sergey Brin, jumping out of a helicopter. An descriptive text for
this image would be something like:
Product pictures
The first product image shows a bag of coffee. When zoomed in, there are a
lot of interesting details in the image, like the brand name, the weight and
the sustainability badge on the back.
"Dr. Nam whole bean coffee. Medium roast. 500 grams. UTZ certified"
The second product image shows a jacket. Try to make a brief description like
this:
"Kicker Sports men's jacket. Full zipper. Gray arms. Black and white pattern
in front. Two pockets with buttons on the sides."
Background images
Background images are often not meaningful. They can be used to set a
mood. Sometimes they tell something more than just a mood. Let us try to
add a text alternative for what the image is trying to tell us.
This example from Caledon Build has a background image of a house. Not an
ordinary house, but a modern house that this company built. The text
Building the next level does not tell the user specific what kind of houses
they build. A description of this image should be something like:
Private house, modern architecture with straight lines. Minimalistic with a big
garage
Stand-alone icons
Describe the function of the icon, not the presentation.
Articles on Medium have four stand-alone icons below the main heading.
Instead of describing the presentation of the icon, like "Twitter logo", we
should write what the icon does:
● "Share on Twitter"
● "Share on LinkedIn"
● "Share on Facebook"
● "Bookmark on Medium"
Badges
The previous example has an icon showing a small star. The icon is not
interactive, it does not do anything. It means something. It signifies partner
stories, readable only by subscribed members. A text description like "Black
star" would make no sense. Instead, write the meaning:
"Partner story"
The coffee product has two badges. For these we must add a text of what
they represent. The first has the text 1 YR. In this case, this means that the
supplier has been a paid supplier member for one year. The second badge is
an illustration of two yellow blocks. This icon is for gold suppliers that have a
premium membership. These badges should have alternative texts like this:
"Gold supplier"
Logos
Describe the intention of the logo.
In this screenshot from an article on Medium, we have two logos. First, the
main logo from Medium. Second, the logo of this channel, Business Insider.
To add "Medium" and "Business Insider" would not be sufficient as descriptive
text. The user might not know if the logo is linked to the web site of Business
Insider or to the Medium channel for Business Insider. In this case it is the
latter, and we can write these descriptions:
● "Medium home"
● "Business Insider on Medium"
What
Links hardly needs an introduction. They are the heart of the web. A link has
many states. Here are five of the most common states. In CSS terms, these
are pseudo-classes:
● Unvisited
● Visited
● Hover
● Active
● Focus
How
To make sure that all link states are accessible, we must remember these
three tips. We will use an example from the front page of ICRC, the
International Committee of the Red Cross.
1. Underline
Links are underlined by default. Removing the underline from a link in body
text is a bad idea most of the time. We learned this in the section about color
alone. This is most important for unvisited and visited links.
In the example from ICRC, there is one link in the body text – rules of war.
Without underline. Let us remove the text-decoration: none; from the
stylesheet:
Now the link rules of war is in a focused state. The text has an orange outline
without any offset. This focus state has two problems. First, the orange
outline has low contrast compared to the white background. Second, the lack
of offset makes the text hard to read. Let us use the red color that is already
in the color palette of the site, and let us add some offset.
Much better! A focused link that is accessible for people that are using a
keyboard to navigate and/or has reduced vision.
3. Hover
A clear hover state is helpful for everyone, especially people with motor
impairments.
In the footer of ICRC you can see a collection of quick links. They have a very
subtle hover state, changing the color from light grey to white. This effect can
be improved.
In this example we have added one effect for the hover state, bold text. It is
now clearer what action the user is about to do.
Accessibility Link Text
Why
People with visual disabilities may zoom the page so that they see a small
portion of the screen. There are many types of visual disabilities. One eye
condition is Glaucoma, one of the leading causes of blindness for people over
the age of 60. Some compare glaucoma to looking through a straw.
What
An accessible link text is a text that makes sense without any context. A link
text should explain clearly what information the reader will get by clicking on
that link.
How
Some examples of good and bad link text.
Good
● Find out more about the HTML language
● Read more about how to eat healthy
● Buy tickets to Mars here
Bad
● Click here
● Read more
● Buy tickets to Mars here
Another reason is that Google Search prefers descriptive links.
● Donate
● Read more
● Visit the eshop
As you can see from this list, the second link does not make any sense
without the context. It takes the user to the page Humanitarian Law and
Policy. An improved link text will be Law and policy. Or Read more about
humanitarian law and policy. Or somewhere in the middle.
Accessibility Headings
Introduction
In our introduction to semantic elements, you learned to use the heading
elements.
The headings must be clear, both visually and use clear wording. The heading
structure of a page forms the outline of the page. You might think of this like
the skeleton of the page.
News papers use a lot of headings. The front page of The Straits Times has
over 80 headings.
In the next module you will learn about assistive technologies and screen
readers. As a teaser, you should watch Rob Dodson from Google demonstrate
the importance of headings when using a screen reader. The first five
minutes of the video explains the use of headings in a screen reader.
How
Let us check a good and a bad example of heading levels.
Solutions
Let us solve each problem, point by point.
No main heading
1. Use the logo as the main heading. The way The Straits Times did it.
2. Use Trump Acquitted as the main heading.
3. Use Trump Acquitted together with 7 Republicans Break With Former
President in Vote on 2nd Impeachment as the main heading. Even
though the two headings are distinct visually, they can be considered
one heading from a semantic point of view. They both describe the
content that follows.
4. Add a hidden heading Front page.
There is no right and wrong here. As the front page of a newspaper, it makes
sense to use the logo as the main heading. Remember to have an alternative
text for the image.
Confusing h2s
Sometimes it makes sense to add content just for screen readers. This is such
a case. A common practice is to use a CSS class .sr-only, where sr means
screen reader:
<h2 class="sr-only>Briefings</h2>
.sr-only {
position: absolute;
left: -10000px;
top: auto;
width: 1px;
height: 1px;
overflow: hidden;
Then it makes sense to change the level of the briefings from h2 to h3. But
are they really headings? Do they present the following content? Let's say no.
If we agree on that, we can change the three links to a list.
Both the prominent heading Trump Acquitted and the following heading 7
Republicans … points to the same article. Therefore, they can be a part of the
same heading. Again, there is no right or wrong here. We can change this to
a h2 or we can add a hidden heading for this <section>:
<h2 class="sr-only">Headlines</h2>
The heading Headlines works well together with Briefings in the document
outline.
Repeating information
In this page, you have read many headings. Check the document outline. Is it
good?
● People with hand tremors cannot grip a mouse. They use the keyboard
to navigate.
● People with mobility disabilities use their voice to control the computer
or mobile device.
● People with mobility disabilities use eye tracking to move the screen
cursor.
● People with mobility disabilities use switch devices to operate the
computer or mobile device.
● People who are blind use screen readers, braille displays or speech
recognition software.
● People with low vision use screen magnification.
The term assistive technologies is a broad term for all these tools. As
developers, we do not need to code for a particular technology. We use
standards methods to make sure that our solution is accessible for all.
In this module, you will learn the basics of keyboard and screen reader
navigation.
What
You learned a bit about visual focus when we talked about link states. Let us
dig deeper. Visual focus is sometimes called keyboard focus or tab focus. It is
a visual indicator on a interactive component that has keyboard focus. The
effect is often a border or outline.
How
You will learn not to remove the focus, and two options for styling the focus.
Do not remove or hide the focus
This is the most important takeaway from this module. Whatever you do, do
not remove the focus. This CSS line is ruining the accessibility for a lot of
people:
outline: 0;
Another common method for hiding the focus that the parent element is to
small to show it, in combination with:
overflow: hidden;
Most browsers use the outline property to show the visual focus of an
interactive element. We have two options. Leave it or customize it. Removing
it is not an option.
In this example from Airbnb, the destination Ålesund is the focused element.
However, it is not possible to tell. The reason is that the parent <div> has
overflow: hidden;
Removing the overflow: hidden; showing the default focus styling. The
browser Chrome in mobile mode is using an orange outline. You might think
that keyboard focus is not important on mobile devices. That is a
misconception. People use keyboards and other assistive technologies on
mobile devices as well.
● The default styling may not align with the color palette of the site.
● The default styling is similar to the color palette of the site.
● The default styling is not visible enough in all browsers.
The travel site Momondo has a vivid color palette. They can pick a color from
their palette to use as the visual focus.
This is a modified version of the Momondo website, showing the link Trips in
focus with a pink and white outline. The pink color is from their palette, the
same as the search button.
As a side note, the search button has insufficient color contrast when used
with white text. The contrast ratio is only 3.33. However, used as a visual
focus against a dark purple background the contrast is better with a ratio of
5.47.
CSS Outline
To better make custom visual focus, you need to know about the different
CSS outline properties. Head over to W3Schools to learn about the outline
style, color, width and offset. Now you are better prepared to make keyboard
accessible interfaces.
What
The most common skip link is the first interactive element on a page. It takes
the user to the main content, past the global elements like the logo, search
and navigation. It is almost always hidden until it receives focus.
How
Try it yourself
HTML
The HTML of a skip link is the easy part.
Let's assume that you have used a <header> and a <main> in your site, as
you learned in Landmarks. The skip link is a global element, so you should
include it in the <header>. You also need to have an ID on the <main>, so
that you are able to link to it with an anchor.
<header>
</header>
<main id="main">
CSS
As you might noticed in the HTML, the link had the class skip, so that we are
able to hide it.
.skip {
position: absolute;
left: -10000px;
top: auto;
width: 1px;
height: 1px;
overflow: hidden;
This code moves the link way outside of the browser. If you are not familiar
with absolute positioning, read about the CSS position property. The 1px size
and the overflow: hidden; are for special cases where user has
deactivated absolute positioning.
When the link is focused, it has to be visible. This is also done with CSS:
.skip:focus {
position: static;
width: auto;
height: auto;
This method is very helpful and important for users that rely on keyboard and
similar input. If you have a complex site, you might want to add more skip
links, not only to the main content. We will cover that later.
Accessibility Screen Readers
Why
Screen readers are necessary for blind people, important for partially-sighted
users and helpful for people with reading disorders.
What
It is hard to teach about web accessibility without talking about screen
readers. Screen readers has become for web accessibility what wheel chairs
is for accessibility. Even though it is a myth that accessibility is just for blind
or partially-sighted users, screen reader support is a mandatory topic.
If you have done everything you have learned in this course, your site should
probably work well in screen readers. That does not necessarily mean that all
blind users are able to use it.
As the name implies, a screen reader is a tool that reads your screen.
Necessary for blind people, important for partially-sighted users and helpful
for people with reading disorders.
Mobile
For mobile devices, Apple has the biggest share of screen reader users. The
screen reader VoiceOver is built in on iOS. The second most popular is
TalkBack for Android, also built in on all Android devices.
Making sure your site works well with these two is a good starting point.
Before we proceed, read these articles:
How
You will to set the language, and we will test two websites – Toyota and
Hyundai.
Language
For the screen reader to speak the correct language, it needs to know what
language your content is. This is done with the lang attribute in the <html>
element. The following example specifies English as the language:
<!DOCTYPE html>
<html lang="en">
1. Check the source code of the english Wikipedia article about Dyslexia.
2. Click the language Bahasa Indonesia.
3. Check the source code again.
The lang attribute changed from lang="en" to lang="id". Good for screen
readers and good for search engines.
Language of parts
Sometimes parts of your content is in another language. To make screen
readers change their language in the middle of the page, we use the same
lang attribute. Check the source code of the link to Bahasa Indonesia on the
english page about Dyslexia:
Now the screen reader understands that the words "Bahasa Indonesia"
should be read in the language Bahasa Indonesia, not English. It also
understand that the target page is in Bahasa Indonesian because of the
hreflang attribute.
Toyota
After hearing the logo, you probably got lost. Three buttons without
accessible names. As you learned in the page Role, Name and Value, all
elements must have an accessible name.
These small changes would improve the Toyota site, not fix it. Using
components like modals and menus requires other considerations as well.
This course will not go into details about custom components. If you want to
learn more about patterns like these, please visit WAI-ARIA Authoring
Practices 1.1 to read about menu button, modal and carousel.
Hyundai
Now you have learned the basics of a screen reader. Feel free to explore
other accessibility options built in your mobile device. Try to operate your
phone with your face, using switch controls.
Forms come in a variety of ways. From simple search forms to order forms
and complex multistep forms.
Accessibility Labels
Why
Labels are critical for blind users, user with low vision, users with mobility
disabilities and users with memory loss. Missing labels will make a form
inaccessible for many users.
What
Visual labels are text near a form control that describe what information
belongs in a given form field or a group of fields. Each label must be
programmatically associated with the form control or group of controls.
Labels are not necessarily the <label> element.
How
You will learn how to use <label>, aria-label and <legend>.
The <label>
The <label> tag defines a label for several elements, like <input>,
<select> and <textarea>.
In this example from Vodafone, we have one <select> and one <input
type="email">, each with a describing <label>:
The <label> element is useful for screen-reader users, because the screen-
reader will read out loud the label when the user focus on the input element.
The <label> element also help users who have difficulty clicking on very
small regions (such as radio buttons or checkboxes) - because when the user
clicks the text within the <label> element, it toggles the radio button or
checkbox.
The for attribute of the <label> tag should be equal to the id attribute of
the <input> element to bind them together.
Required fields
Form labels often contain a "*" or the word "required" to indicate that the
field is required. Both of these methods are fine. However, it is recommended
to add the required and aria-required="true" to the form control if you
use an asterisk (*):
The aria-label
Fields without visual labels still needs a label. If you can not use a <label>,
one option is to use a aria-label.
This search field has a placeholder, but no label. A placeholder is not a valid
accessible name. You can not rely on it as a substitute. An easy solution here
is to add aria-label="Enter search term":
The <legend>
Groups of form controls, like checkboxes and radio buttons often require a
higher level of "label" in addition to the <label>. This high level "label" is
made with <fieldset> and <legend>.
This registration form has three form controls to provide the date of birth.
Visually it makes sense that both day, month and year is related to "Your
date of birth". This relation is not obvious for a screen reader user. We can
not use <label> here. The labels are Day, Month and Year. The solution is to
add a <fieldset> and a <legend>:
<fieldset>
<label for="dobDay">Day</label>
<select id="dobDay">…</select>
<label for="dobMonth">Month</label>
<select id="dobMonth">…</select>
<label for="dobYear">Year</label>
</fieldset>
❮ Previous
Next ❯
Even this simple search field is a form.
The most important element to make sure your form is accessible is a label.
Not necessarily a <label>. What is the difference, you might wonder?
Continue to learn about labels.
Accessibility Autocomplete
Why
The autocomplete attribute makes a form easier and more efficient for all
users, especially users that are attention deficit, have cognitive impairments,
reduced mobility, low vision or blind users.
What
Have you ever experienced coming to a web form, and your browser autofill
the fields in magical way? That is either because the browser was smart, or
that the form author had used the autocomplete attribute in correct way.
This is convenient for everybody. This is very helpful for user with motor
impairments or cognitive disabilities. Filling a form can be hard, and the
autocomplete attribute is often a helping hand.
How
Autocomplete can be used on <input>, <textarea>, <select> and <form>
elements. The attribute has many possible values, like:
The complete list of values: Input Purposes for User Interface Components.
A label and a placeholder is a hint for some browsers, but not a bulletproof
solution. The best way is to add the magical autocomplete attribute:
Exceptions
No rules without exceptions. The above code example will make the form
easy, efficient, error free and accessible. If the form was asking for another
email, not "your" email, it would make no sense to add the autocomplete
attribute. When the data is probably not saved in the browser, it shouldn’t
have attribute.
Not all forms are error free. How do you code accessible error messages.
Read on!
Accessibility Errors
Why
Everyone make mistakes. When we do, we need to understand why we have
failed, to be able to correct ourselves. An accessible form needs error
messages that is perceivable and understandable for people who is color
blind, who is blind or low vision, and people with limited cognitive abilities.
What
An accessible error message is
● written in text. Color and icon can be used, but not alone.
● close to the element that has failed.
● informative, helping the user.
● associated to the failed element in the code.
In addition, is is helpful to move the focus to the form control that has failed.
In this registration form, the user has typed a number instead of characters.
How
You will learn five techniques for creating accessible error messages.
Written in text
The error message is written in text, in addition to a warning icon and red
border. Three different indicators makes this error situation clear to the user.
Only an icon and a red border would not have been sufficient for all users to
understand.
Close together
Design elements near each other are perceived as related, while elements
spaced apart are perceived as belonging to separate groups.
Design elements near each other are perceived as
related, while elements spaced apart are perceived as
belonging to separate groups.
In this example the errors are close to the failing fields. In combination with a
big margin between the fields, it is easy to understand where the error
messages belongs.
Informative
The more informative, the better.
In our first example the error "Your first name must have at least two letters
and no unusual characters" is informative. It is written in a human language.
It can be improved, written even more precise:
The more precise, the better. This means that the system needs more error
messages for different situations. Be pragmatic when deciding how many
different error messages and situations you will create. Ask the users if they
understand what is wrong. If not, write the error more precise.
The error has the role alert. This is good. It would make a screen reader read
out the content, even though it is not in focus.
The error message is not assosiated with the field. This can be done using the
aria-describedby attribute. The value is the ID of the error message.
Move focus
This is more important for server-side validations, compared to client-side
validation. When the user submits a form, the focus moves to the first invalid
field.
In this example, all three fields have been invalid. The focus was moved to
the first field, First name. The error is removed when the user starts typing.
Users with low vision zoom in on content to be able to perceive it. Users with
good vision zoom in on content to increase the readability of the content.
There are three main ways of zooming:
1. Screen magnifier
2. Text zoom
3. Page zoom
You will learn about text and page zoom. As a developer, there is not that
much to think about when it comes to screen magnifier.
First, you will learn how to let users change the text size without zooming the
entire interface.
What
Users must be able to change the text size without zooming the entire
interface.
This is done in the settings of the operating system or the browser. There are
many ways of doing this. In the Chrome browser on desktop, you can set the
font size in settings under Appearance and Customize fonts.
How
Let us open the website for LG in India in the Chrome browser on a desktop
or laptop computer.
This is what the section Most popular looks like with default browser settings.
Browser settings
Now, in your Chrome browser, set the font size to 40 pixels. That is 2.5 times
the default size. For low vision users, this is not much.
.model-name {
font-size: 18px;
line-height: 22px;
height: 66px;
overflow: hidden;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;
}
Relative units
To solve this, let us try rem instead of px. 18 px is 1.125 rem if the base size
is 16 px.
.model-name {
font-size: 1.125rem;
line-height: 22px;
height: 66px;
overflow: hidden;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;
}
There are several reasons for this. First of all, the line-height is set in
pixels. As with font size, we should avoid absolute units when setting line
height. line-height can be set with a number without a unit, instead of a
length. In this case, we can use line-height: 1.2; instead of line-
height: 22px;
The container of the product title has height: 66px; – not a good idea when
you want to support text zoom. Let us try to remove that absolute height.
The last problem is that this product title has -webkit-line-clamp: 3; that
limit the text to three lines. Important information is lost.
.model-name {
font-size: 1.125rem;
line-height: 1.2;
overflow: hidden;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-box-orient: vertical;
Result
This course will not cover all techniques for supporting text resizing. The
main takeaways are that you should test the sites you code, and strive to use
relative units.
What
The big brother of text zoom is page zoom. Zoom everything! The principles
are easy to understand:
Page zoom often triggers mobile view on responsive sites, which is good.
How
You will now learn five techniques to support page zoom.
Hidden icons
In this example from Samsung India, the page is zoomed 400 %. The content
is scaling properly. No horizontal scrollbar. However, the chat button occupies
a big part of the browser window. It is not easy to access the buttons for
search, cart or menu. And the quality of the button graphic is low. In addition,
there is a huge ad for an app.
Improvements:
● Add a minimize button for the chat button. Use the minimized version
as the default.
● Use vector graphics like SVG instead of raster graphics like PNG.
● Show mobile ads only for mobile devices.
No clutter
In this example from Philips, the entire viewport is available for main content.
The main navigation is opened, and there is no clutter. The text and graphics
are scaled well.
Fixed width
In this example from Dell, we can only see a small part of the header. The
site does not scale when zoomed. The result is a large horizontal scroll that
makes it hard to navigate the page in two dimensions.
In addition, the cookie consent button is fixed, not possible to remove even
though the consent is given. The logo and the icons are low resolution PNGs
that does not scale well. Viewport is not set.
Improvements:
Hidden tabs
In this example from Sony, the tabs with product information is not accessible
in a desktop browser with page zoom. Even if the user scrolls, the scrolling is
happening outside of the browser window. All the specifications, features,
reviews and support are inaccessible. The problem is that the entire section
is "sticky":
<section class="sticky-nav">
.sticky-nav {
position: fixed;
z-index: 1035;
top: 0;
This section is 159 pixels high in a mobile view. When zoomed four times, the
fixed section occupies 636 pixels of the desktop view. With a browser height
of 720 pixels, minus the top part of the browser, leaves not much room for
the main content.
Fixed content is not necessarily inaccessible. The takeaway is that you should
always test your site with page zoom in common browser sizes.
In a mobile view, the content beneath the tabs is accessible.
The sticky navigation from Huawei is not too high, so there are enough space
for the main content.
In this example from Xiaomi, the zoomed text is pixelated because it is part
of the image. Parts of the text is also outside the browser window, so that the
user has to scroll to read the entire product title. Displaying text with pure
HTML and CSS has many benefits, in addition to be accessible: responsive,
translatable and searchable.
15 HTML tags for accessibility
1. ARIA labels
The first rule of ARIA use is “If you can use a native HTML
example:
<button aria-label="Close">X</button>
For example:
an element.
<fieldset>
<legend>Contact preferences</legend>
</fieldset>
3.<label>
should use the for attribute to link the label with the
example:
<label for="name">Name:</label>
example:
roles. You can find a list of all the roles and their
descriptions at MDN.
6. <h1> to <h6>
only one <h1> tag per page and use lower-level headings
<h1>HTML Accessibility</h1>
<h2>Semantic HTML</h2>
<p>Semantic HTML means using correct HTML elements for their correct
example:
<tr>
<th scope="col">Category</th>
<th scope="col">January</th>
<th scope="col">February</th>
...
</tr>
<tr>
<th scope="row">Books</th>
...
</tr>
8. lang attribute
<html lang="en">
10. <caption>
</table>
</figure>
12. <abbr>
“HTML”, “CSS”, “Mr.”, “Dr.”, etc. You can use the global
For example:
</p>
This will display “WHO” as an abbreviation with a dotted
13. <button>
screen readers.
Here is an example of a native button with an accessible
text label:
<button>Submit</button>
<div role="button"
tabindex="0"
aria-label="Close"
onclick="closeWindow()"
onkeydown="handleKey(event)">
</div>
<script>
function closeWindow() {
function handleKey(event) {
closeWindow();
</script>
14. <nav>
confusion.
mind:
<nav aria-labelledby="main-nav">
<ul>
<li><a href="home.html">Home</a></li>
<li><a href="about.html">About</a></li>
<li><a href="contact.html">Contact</a></li>
</ul>
</nav>
the media.
and context.
● The <track> tag is used to provide additional
WebVTT format.
</video>
accessibility
HTML plays such a critical role in the structure of the web that it must be
universally accessible to users with disabilities. Following accessibility
standards and guidelines, including those outlined in the Web Content
Accessibility Guidelines
(opens in a new tab)
(WCAG), ensures developers create accessible HTML code that
accommodates diverse users.
Below, we’ll review HTML accessibility best practices for creating accessible
code and examine a list of HTML tags that improve accessibility and the user
experience.
More simply, semantic elements convey the intended meaning of the content
they enclose. For example, <button> and <form> are examples of semantic
HTML.
Along with using semantic HTML elements, use ARIA roles as well. ARIA roles,
states, and properties further accessibility for dynamic content, such as
custom widgets or interactive elements, by providing additional context for
users.
, only changing native semantics if you have to. For example, if a developer
wants to build a heading that’s a tab, the World Wide Web Consortium
Ensure your headings are organized hierarchically (e.g., H1, H2, H3). Avoid
skipping headings levels, as this can create confusion for screen reader
users. Additionally, ensure your headings accurately describe the content
that follows.
The lang attribute indicates the language on a page. Using it helps screen
readers and other assistive technologies correctly pronounce words,
understand and interpret abbreviations, and present content in the right
language for users. It’s a simple but effective way of ensuring content is both
accessible and inclusive to a range of users.
Ensure that all links (<a> elements) on your content are descriptive. They
should provide clear information about the destination or purpose of a
hyperlink before a user clicks on it. Avoid generic or vague link text like ‘click
here’ or ‘read more’ as they don’t convey meaningful information to screen
reader users or those navigating via keyboard.
● <nav>: The <nav> HTML tag identifies a set of navigation links and
identify and skip over repetitive content and get the information
● <main>: This tag defines the main content area of a web page or
text or alt text) to be added to each one. Alt text ensures users with
Ethically speaking, accessible HTML code improves the user experience for all
visitors, boosting satisfaction and retention rates. It expands your potential
customer base by accommodating individuals with disabilities, representing a
huge portion of the global population. Plus, accessible websites typically rank
higher in SEO rankings, allowing more people to find your business.
Here’s the bottom line: increasing the accessibility of your HTML shows your
commitment to inclusivity and the experience of your users and mitigates
legal risk. This results in more positive business outcomes and fosters a more
inclusive digital environment for all users.
AudioEye then goes a step further, relying on our team of human experts to
test your content for more complex accessibility errors and provide
recommendations for improvement. With these insights, you can create a
detailed remediation plan to fix accessibility errors and get closer to a more
accessible, WCAG-compliant website.
Developers can also test the accessibility of page content with AudioEye’s
Developer Tools. The online environment provides a secure place in which
developers can test inline code or individual components for accessibility
issues early in the web development process. Doing so lets you avoid
accessibility issues that could negatively impact your users.