Writing HTML with accessibility in mind
An introduction to web accessibility. Tips on how to improve your markup and provide users with more and betters ways to navigate and interact with your site.
If you don’t want to read the preface, jump right to the tips.
This article is also available in Russian, thanks to Workafrolic, Korean, thanks to Yongui, in Portuguese, thanks to EmanuelG, and in Spanish, thanks to “Ibidem Group”.
Personal development and change in perspective
When I made my first website my highest priority was to get content online. I didn’t care much about usability, accessibility, performance, UX or browser compatibility. Why would I? I made a robust table based layout and I offered a 800×600 and a 1024×768 version of my site. On top of that, I informed users that the website was optimized for Internet Explorer 5.

This was of course before I started to work professionally as a web designer and my perspective in what was important changed. Years later, instead of dictating the requirements for my websites, I started to optimize them for all major browsers. Beginning with Ethan Marcotte’s game changing article I started caring about devices as well. Making websites for all kinds or browsers and devices is great, but pretty much useless if the websites are too slow. So I learned everything about critical CSS, speed indices, font loading, CDNs and so on.
Getting started with accessibility (a11y)
Recently my perspective has changed again and I realized that making a fast, responsive website that works in older browsers isn’t enough if e.g. it isn’t navigable via keyboard. But accessibility isn’t just yet another item on our to-do list to cross off before we launch our website. Accessibility is the foundation of what we do as web designers and web developers and it’s our obligation to treat it as such.
I spent the last few months reading, listening and talking about web accessibility. It took me some time to get my head around a few things and I’m still at the beginning, but the more I learn the more I’m surprised how much I can do right now without having to learn anything completely new.
I’ve expanded my knowledge of HTML, CSS, and JavaScript, but the most important thing I’ve learned is that accessibility isn’t just a medical term that only applies to a certain percentage of people. Accessibility is something that concerns all of us, you and me, every day. What we create is useless if it isn’t accessible.
In this series of articles, I want to share some of my newly acquired knowledge with you. You shouldn’t treat the tips I’m going to give you as a check list but as a starting point. Incorporating these techniques into your workflow will get you started with accessibility and hopefully motivate you to learn and care more about your users.
Without further ado, here are my accessibility tips:
It’s important to define the natural language of your document
Telling the browser which language you are using in your document has many benefits. It’s good for SEO, it helps third-party translation tools and browsers to identify the right language and dictionary. Defining the correct language in an HTML page helps assistive technology to choose the correct voice profile or character set.(1) Adrian Roselli has gathered some more benefits of using the lang attribute on his website.
<html lang="en">
…
</html>Watch a demonstration of the lang attribute in use on YouTube.
If you switch language within a document you can use the lang attribute on specific tags.(2)
<p>There is a certain <i lang="fr" class="idiomatic">je ne sais quoi</i> in the air.</p>Make sure to always define the right language. Steve Faulkner made a video that illustrates what happens if you don’t use the lang attribute correctly. All language codes are listed in the IANA Language Subtag Registry.
You can hide content using the hidden attribute
If you want to hide content visually and from screen readers, use the hidden attribute.
Browser support for the hidden attribute is very good, except for IE 10 and lower. You can provide support for older browsers if you add this fallback to your CSS.
[hidden] {
display: none;
}Sometimes it’s better to add a blank alt attribute to an <img> element
If an image is used as content, apply the alt attribute to describe the images content and function succinctly. When you do that don't start with „Picture/Image/Graphic of…“, because the screen reader does that anyway.
If the image is purely decorative or doesn’t add valuable information, consider embedding it with CSS as a background image. If you have/want to add it in HTML, don’t remove the alt attribute, but leave it empty.(3)
<img src="decorative_image.jpg" alt="" />It’s important that you don’t omit the alt attribute.
Omitting this attribute altogether indicates that the image is a key part of the content, and no textual equivalent is available. Setting this attribute to an empty string (alt=””) indicates that this image is not a key part of the content and that non-visual browsers may omit it from rendering. https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img
There are some more tips on using the alt attribute on the The A11y Project page „Quick Tip: Using alt Text Properly “.
If you need a button, use the <button> element
In general, you should always favor native HTML elements, if there is one, over faking your own. For example, if you need a button, use the <button> element and not a <div>.
Buttons have many benefits/crucial features, for example:
- Focusable
- Clickable (with mouse and keys)
- Screen readers identify them as buttons
Rob Dodson did a really great job explaining the benefits of an actual <button> over a <div>. Watch the A11ycasts episode „Just use button“ for more details and examples.
If you are not sure whether to use a button or a link, read Marcy Suttons post „Links vs. Buttons in Modern Web Applications“.
Structuring your markup correctly with headings is important
By creating a sound outline using headings <h1> - <h6> you are helping users to better understand the structure of your page and relationships between individual sections. On top of that, it will help users with assistive technology navigate. Screen readers provide different ways of moving from one piece of content to another. For example using the NVDA screen reader users can jump from heading to heading with shortcuts (H and Shift + H).







