Web Accessibility
What is Web Accessibility?
Web accessibility means building pages that everyone can use, including people who:
- use a screen reader because they are blind or have low vision
- use only a keyboard instead of a mouse
- have trouble telling some colors apart
- need larger text or more contrast
So, always write HTML code with accessibility in mind!
Provide the user a good way to navigate and interact with your site.
Use Semantic HTML
Most web content can be made accessible just by making sure the HTML elements are used for the correct purpose at all times.
Semantic HTML means using the correct HTML elements for their correct purpose
as much as possible. So, if you need a button on your web page, use the <button> element,
and not a <div> element.
Semantic HTML gives context to screen readers, which read the contents of a page out loud.
With the button example in mind:
- buttons have suitable styling by default
- buttons have built-in keyboard accessibility
- a screen reader identifies it as a button
- buttons are focusable and clickable
Use Well-structured Text Content
One of the best accessibility aids a screen reader user can have, is a good text structure with headings, paragraphs, lists, etc.
A good semantic page can look something like the following:
Example
<h1>My Heading</h1>
<p>The first section of text.</p>
<p>Some more text.</p>
<ul>
<li>A list</li>
<li>A list</li>
<li>A
list</li>
</ul>
<h2>My subheading</h2>
<p>Some
more text.</p>
<h2>My 2nd subheading</h2>
<p>Some
more text.</p>
- A screen reader reads each header out as the user goes through the content, notifying what a heading is, what is a paragraph, etc.
- A screen reader stops after each element, letting the user go at whatever pace is comfortable
- Many screen readers allows the user to jump to the next/previous heading
- Many screen readers can bring up a list of all headings, allowing the user to use it as a table of contents to find specific content
Headings are Important
Headings are defined with the <h1> to <h6> tags:
Example
<h1>Heading 1</h1>
<h2>Heading 2</h2>
<h3>Heading 3</h3>
<h4>Heading 4</h4>
<h5>Heading 5</h5>
<h6>Heading 6</h6>
Try it Yourself »
Search engines use the headings to index the structure and content of your web pages. Users skim your pages by its headings. It is important to use headings to show the document structure and the relationships between different sections.
Screen readers also use headings as a navigational
tool. <h1> should be used for the main heading, followed by <h2> headings, then the less important
<h3>, and so on.
Note: Use HTML headings for headings only. Don't use headings to make text BIG or bold.
Use Clear Language
Always use a clear language, that is easy to understand.
Also try to avoid language and characters that cannot be read out clearly by a screen reader. For example:
- Avoid dashes. Instead of writing 1-3, write 1 to 3
- Avoid abbreviations. Instead of writing Feb, write February
- Avoid slang words
Use Language Code
A language code is a 2-letter abbreviation that specifies the language of a web page. The language code is meant to assist search engines and browsers.
Always include the lang
attribute inside the <html> tag, to declare the
language of your web page.
The following example specifies that the language of this web page is in English:
<!DOCTYPE html>
<html lang="en">
<body>
...
</body>
</html>
Use Text Alternatives
Always use the alt attribute to provide an alternate text for an image, if the user for
some reason cannot view it (because of slow connection, an error in the
src
attribute, or if the user uses a screen reader).
The value of the alt attribute should always
contain a good description of the image:
Example
<img src="img_chania.jpg" alt="A narrow city street with flowers in Chania">
Try it Yourself »
If a browser cannot display the image, it will display the value of the alt
attribute:
Example
<img src="wrongname.gif" alt="A narrow city street with flowers in Chania">
Try it Yourself »
Use Good Link Texts
A link text should explain clearly what information the reader will get by clicking on that link.
Examples of good and bad links: