artCode

Web Accessibility: Best Practices with HTML5 and ARIA

Web accessibility is essential to ensure that all users, including those with disabilities, can navigate, understand and interact with web content.

Tags

  • HTML
  • CSS

Published

Reading Time

6 min
Cover image for Web Accessibility: Best Practices with HTML5 and ARIA

HTML5 and ARIA (Accessible Rich Internet Applications) provide technical specifications to help developers create more accessible sites.

Using HTML5 semantic elements

HTML5 has introduced semantic elements that clearly define the structure of a web page, improving accessibility for screen readers and assistive devices.

Structure Elements such as: header, footer, nav, section and article, are used to mark the various parts of the page. This facilitates content navigation for screen reader users.

HTML
<header> <!-- Site header --> </header> <nav> <!-- Main navigation --> </nav> <main> <article> <!-- Main content --> </article> </main> <footer> <!-- Page footer --> </footer>

Furthermore, HTML5 enriches form accessibility through specific elements and attributes, such as with the for attribute, input types (email, tel, date) and attributes like placeholder and required.

Explicit Labels: Every input field should have an associated label, improving usability for users with assistive devices.

HTML
<label for="name">Name:</label> <input type="text" id="name" name="name" required>

ARIA to enhance accessibility

ARIA introduces attributes that can be added to HTML markup to provide additional information about roles, states and properties of elements, particularly useful in dynamic components.

ARIA Roles and Properties: use ARIA roles to define the role of elements (e.g. button, dialog) and properties like aria-labelledby and aria-hidden to improve accessibility.

HTML
<div id="modalDialog" role="dialog" aria-labelledby="dialogTitle" aria-modal="true"> <h2 id="dialogTitle">Dialog Title</h2> <p>Dialog content...</p> </div>

The example defines a dialog that uses the aria-labelledby attribute to associate the title, located in an h2 element, with the dialog itself. Through the aria-modal="true" attribute, we focus attention by defining the modal and making it accessible to the end user.

Let's always remember to verify that the site is fully accessible via keyboard.

Focus Order: Control the focus order with tabindex during keyboard navigation.

The focus order determined by the tabindex attribute establishes the sequence in which elements of a web page receive focus when the user navigates via keyboard, particularly using the Tab key. The value of tabindex can directly influence the accessibility and usability of a website.

HTML
<a href="https://theartcode.dev" tabindex="1">View example</a> <button tabindex="2">Click</button>
Web Accessibility: Best Practices with HTML5 and ARIA | artCode