How to take care of your website accessibility: Best Practises
In this article, we’ll explore what web accessibility means, tools that make things more accessible, the advantages of adding accessibility features, and some ideas to make your website more accessible.
In today’s digital era, ensuring website accessibility is not just a legal requirement or a good practice but it’s a fundamental aspect of ensuring a positive user experience for a diverse audience. The websites we create should be usable by everyone, no matter what kind of computer or software they use, the language they speak, where they are, or their abilities. When we design websites with this in mind, they become easy for everyone to use, including people with different abilities like hearing, movement, sight, and thinking, which leads to building an Inclusive Web environment.
This article outlines essential best practices for taking care of your website’s accessibility and we’ll explore key elements of web accessibility, from understanding the basics to implementing best practices in HTML, CSS, JavaScript, and more.
So, What is Accessibility?
Think of accessibility as an equalizer, offering everyone equal opportunities, irrespective of their abilities or circumstances. Often it’s associated with disabilities like Visual, Hearing, Mobility, and Cognitive Impairments but it also benefits users with mobile devices or those facing network connections.
Building Accessible Sites: Benefits for All
Building accessible sites not only aligns with ethical standards but also brings about practical benefits. Semantic HTML is just crucial for accessibility, and improves SEO and site findability, as we’ll see later.
Accessibility as a Law
Understand the legal landscape surrounding web accessibility, emphasizing that it’s not just a good practice but a legal requirement in some countries. Get acquainted with the Web Content Accessibility Guidelines (WCAG) HERE and learn about specific legislations governing web accessibility in different regions.
You just need to focus on key areas relevant to your project from the complex world accessibility guidelines. Familiarize yourself with WCAG, understand how your country’s laws may impact web accessibility, and acknowledge the importance of making accessibility a priority in your web development practices.
So How HTML serves as an excellent foundation for accessibility, let’s see the key to building inclusive and user-friendly web experiences.
HTML and Accessibility
HTML as you know (But you don’t know what you know) is the concept of writing markup language that has a meaning used to build the structure of your website, stands as the cornerstone, providing the foundation for creating inclusive and user-friendly digital experiences, you will learn to use thoughtful markup and semantic elements that significantly enhance the usability of your website:
- Semantic HTML:
Before: Everything’s div
<div class="header">
<h1>Welcome to Our Website</h1>
<div id="navigation">
<a href="somelink"></a>
<a href="someotherlink"></a>
</div>
</div>
<div class="main-content">This is the main content of the page.</div>
After:
<header>
<h1>Welcome to Our Website</h1>
<nav>
<ul>
<li><a href="somelinkhere"></a></li>
<li><a href="somelinkhere"></a></li>
<li><a href="somelinkhere"></a></li>
</ul>
</nav>
</header>
<main>This is the main content of the page.</main>
You notice the difference, HTML tags can speak what they’re doing rather than divs, providing a seamless look to the programmer without getting lost with divs, By using semantic elements appropriately, web developers can ensure that the content is not only visually structured but also semantically meaningful, aiding users who rely on assistive technologies like screen readers.
Other Useful Semantic Elements:
<article>, <aside>, <details>, <figure>, <footer>, <header>, <main>, <nav>, <section>, <summary>, <time>, <form>...
2. Multimedia and Alternative Text Mastery:
Before
<div class="image">
<img src="flower.jpg" alt="A beautiful flower" />
</div>
After
<figure>
<img src="flower.jpg" alt="A beautiful flower" />
<figcaption>A beautiful flower</figcaption>
</figure>
Add descriptive alternative text to images (<img>
), and use <figure>
and <figcaption>
for multimedia content.
3. ARIA Roles and Attributes in Action
- Stands for Accessible Rich Internet Applications
- ARIA is a set of attributes that can be added to HTML elements to enhance their accessibility for users of assistive technologies
- ARIA roles define the overall purpose or category of an element.
- ARIA attributes provide additional information about an element’s state, properties, or behavior.
- When used appropriately, ARIA contributes to a more inclusive and accessible user experience for individuals using assistive technologies.
Here’s a basic illustration:
Suppose you have a custom navigation menu built with <div>
elements, and you want to convey to screen readers that these <div>
elements serve specific roles, like "navigation" and "menu item." ARIA roles and attributes come into play to provide this additional information.
Before ARIA:
<div id="navigation">
<div>Home</div>
<div>About Us</div>
<div>Contact</div>
</div>
After ARIA:
<div role="navigation" id="navigation">
<div role="menuitem">Home</div>
<div role="menuitem">About Us</div>
<div role="menuitem">Contact</div>
</div>
The role="navigation"
attribute is added to the parent <div>
to explicitly define it as a navigation region. This helps assistive technologies understand the purpose of this container. Also, Each menu item <div>
is assigned role="menuitem"
. This attribute informs screen readers that these <div>
elements represent items within a menu, aiding users in comprehending the structure
Other different kinds of ARIA attributes can be used, and you can find them here.
As we conclude this exploration of HTML and accessibility, you should have a solid foundation for integrating accessibility considerations into your HTML markup, so you should consider using proper document structure in conjunction with ARIA Roles for optimal results.
Finally, I wanna elaborate on the workflow of accessibility in HTML as the picture illustrates:
As The browser constructs the DOM(Document Object Model) that represents the structure of the web page as a tree of objects after parsing HTML documents, it also generates the Accessibility Tree in parallel.
The Accessibility Tree is a hierarchical structure that mirrors the DOM but only retrieves the information relevant to accessibility that will be exposed to assistive technologies.
What Information Does the Accessibility Tree expose?
- The text content of elements.
- Hierarchical relationships between elements.
- Roles (e.g., button, link, heading) and states (e.g., expanded, checked) of elements.
- Keyboard interactions supported by elements
and How Assistive Technologies Interact with the Accessibility Tree?
Of course, using the Accessibility API, They retrieve information from the tree to provide an alternative presentation of the content to users with disabilities.
I think you start drawing the picture of your crucial role as a developer to ensure that the accessibility Tree reflects the content and semantics of the web page.
CSS and JavaScript accessibility
While HTML lays the foundation for an accessible website, CSS and JavaScript play pivotal roles in enhancing the overall user experience.
CSS for Accessibility:
- Cascading Style Sheets (CSS) are essential for styling and layout purposes, but they also contribute significantly to web accessibility. Here are some key considerations:
- Contrast and Color: Ensure sufficient color contrast between text and background to cater to users with visual impairments. A good practice is to use a color contrast tool to validate your design choices. Additionally, avoid relying solely on color to convey information.
- Responsive Design: Implement responsive design principles to ensure your website is accessible on various devices and screen sizes. This benefits users with different abilities and those using assistive technologies.
- Font and Text: Use relative units for font sizes, such as percentages or ems, to allow users to adjust text size according to their preferences. Avoid using fixed units like pixels, as they may hinder readability.
- Focus Styles: Ensure that interactive elements, such as links and form controls, have clear and visible focus styles. This is crucial for users who navigate websites using keyboards or other input devices.
- Hidden Content: Be cautious when hiding content using CSS. If content is visually hidden but still present in the DOM, ensure that it is accessible to screen readers and other assistive technologies.
JavaScript for Accessibility:
- JavaScript adds interactivity and dynamic behavior to websites, but it’s essential to implement it in a way that enhances accessibility. Consider the following practices:
- Keyboard Navigation: Ensure that all interactive elements on your site can be accessed and activated using a keyboard. Users who cannot use a mouse rely on keyboard navigation, so it’s crucial to test and optimize this aspect.
- Progressive Enhancement: Implement a progressive enhancement approach, where your website functions without JavaScript but offers an enhanced experience for users with JavaScript-enabled. This ensures accessibility for a broader range of users.
- Aria-labelledby and Aria-describedby: Leverage ARIA attributes like aria-labelledby and aria-describedby to associate dynamic content with proper labels. This helps screen readers provide meaningful information to users, especially in the case of dynamically updated sections.
- Avoid Excessive Animation: While animations can enhance user experience, avoid excessive or rapid movements that may cause discomfort or disorientation, particularly for users with cognitive or neurological conditions.
- Error Handling: Implement clear and accessible error messages for form validation or other user inputs. Ensure that users with screen readers receive adequate feedback when errors occur.
- Testing and Compatibility: Regularly test your website’s JavaScript functionality with accessibility tools and screen readers to identify and address any potential issues. Consider browser compatibility to ensure a consistent experience across different platforms.
In conclusion, combining HTML, CSS, and JavaScript with accessibility in mind creates a more inclusive and user-friendly web environment. As a web developer, embracing these best practices will not only enhance your website’s accessibility but also contribute to a positive user experience for all visitors.
Top Resource:
Others: