HTML ARIA Attributes for Accessibility

HTML ARIA Attributes

The HTML ARIA attributes help users with disabilities use websites. These attributes describe roles and states for tools.

Understand the ARIA Attributes and Their Roles in HTML

ARIA means Accessible Rich Internet Applications. These values do not change the layout. They only help with assistive tools.

A role tells assistive tech what a part of the page does. It gives meaning to a div or span. You can also add it to any custom element.

Here is an example:

<div role="button">Click here</div>

The user hears this as a button, not just a block. You can use role to describe parts like button or navigation.

The aria-label Attribute:

Use this to add a name to an element. Screen readers read this label instead of the text inside.

<button aria-label="Close menu">X</button>

It hides the “X” and speaks “Close menu” to the user.

The aria-labelledby Attribute:

This points to another element that already holds a label.

<h2 id="heading">Settings</h2>
<section aria-labelledby="heading">...</section>

The section uses the heading text and connects both parts with the ID.

The aria-describedby Attribute:

This points to an element that gives extra info.

<input aria-describedby="hint">
<p id="hint">Use 8 characters or more.</p>

The input gets help text. The tool of “text-to-speech” speaks it after the field name.

The aria-hidden Attribute:

This tells the digital screen narration tool to skip the element.

<span aria-hidden="true"></span>

The star icon looks normal but is silent to assistive tools. You use this to remove noise.

The aria-expanded Attribute:

You use this for menus or other parts that open and close.

<button aria-expanded="false">Menu</button>

Change this with a script when the menu opens. Tools track if it is open or closed.

The aria-checked, aria-selected, aria-disabled Attributes:

Use these for elements that act like inputs or tabs.

<div role="checkbox" aria-checked="false" tabindex="0">Subscribe</div>

Update the value with a script when the user clicks.

<li role="option" aria-selected="true">Option A</li>
<button aria-disabled="true">Pay Now</button>

They work like native elements but without full control. You need scripts to manage them.

Examples

Toggle Section with aria-expanded:

<button aria-expanded="false" aria-controls="section" id="toggle">Show</button>
<div id="section" hidden>Some content here.</div>

<script>
  let btn = document.getElementById("toggle");
  let box = document.getElementById("section");

  btn.addEventListener("click", function () {
    let open = btn.getAttribute("aria-expanded") === "true";
    btn.setAttribute("aria-expanded", !open);
    box.hidden = open;
  });
</script>

The button shows or hides the box. The aria-expanded value updates. This helps tools follow what changes on the screen.

Custom Checkbox with aria-checked:

<div role="checkbox" aria-checked="false" tabindex="0" id="box">Accept Terms</div>

<script>
  let box = document.getElementById("box");

  box.addEventListener("click", function () {
    let checked = box.getAttribute("aria-checked") === "true";
    box.setAttribute("aria-checked", !checked);
  });
</script>

This div works as a checkbox, and the aria-checked attribute stores its state. A script handles the control.

Dialog Box with aria-labelledby and Role:

<div role="dialog" aria-labelledby="dlg-title" aria-hidden="true" id="dialog">
  <h2 id="dlg-title">Login Required</h2>
  <p>Please enter your password to continue.</p>
</div>

This box has a role and label. Also, the aria-labelledby points to the title. So, the tool reads it as a full dialog.

Disabled Button with aria-disabled:

<button aria-disabled="true" onclick="alert('No')">Submit</button>

This button looks active but tells the screen reader that it is not usable. You should add visual hints with CSS too.

Wrapping Up

In this article, you learned what ARIA attributes do and how they help tools understand your page. You also saw how roles and states work with scripts and styles.

Here is a quick recap:

  • ARIA helps build better tools for users who cannot use a mouse or screen.
  • Use roles to name parts. Use labels to explain things.
  • Use states when parts open, change, or update.
  • Use scripts to update values. This keeps your page usable for all.

FAQs

What are <ARIA attributes in HTML> and how do they improve accessibility?

ARIA (Accessible Rich Internet Applications) attributes provide extra information to assistive technologies like screen readers. They help users with disabilities interact with dynamic web content by describing roles, states, and properties. Example:
<button aria-label="Close"></button>
This tells screen readers the purpose of the button, even if it has no visible text.

How do you use <aria-hidden> in HTML and when should it be used?

The aria-hidden attribute is used to hide elements from assistive technologies. Example:
<div aria-hidden="true">Decorative content</div>
Use it for non-essential elements like icons or animations to avoid distracting screen readers.

What is the difference between <aria-label> and <aria-labelledby>?

aria-label provides a custom label directly, while aria-labelledby references an existing element's ID to label another element. Example using aria-label:
<input type="text" aria-label="Username">
Example using aria-labelledby:

<label id="nameLabel">Full Name</label>
<input type="text" aria-labelledby="nameLabel">

Similar Reads

HTML Class Attribute: Use in CSS and JavaScript

The HTML class attribute helps group elements. It helps you update the page style without changing the structure of HTML.…

HTML style Tag: Inline CSS

The style tag in HTML defines CSS inside a web page. Click to see how it works with syntax and…

HTML meter Tag: Measurements with Examples

Purpose and use cases: The HTML meter tag shows a scalar value within a known range. You can use it…

HTML Nav Tag: How to Create Navigation Menus

The nav tag defines a navigation block in HTML. It holds main links to other parts of your site. Search…

HTML Section Tag: How It Works with Examples

The HTML section tag groups parts of a web page that share one theme. It gives clear meaning to content.…

HTML Footer Tag for Document Footers

The <footer> tag defines a footer section in HTML. It creates a clear endpoint for a page or section. Browsers…

HTML Label Tag: How It Works with Examples

Forms need instructions so users know what to enter. You use the HTML label tag to give names to input…

The Button Tag in HTML: How it Works with Examples

The HTML button tag creates interactive controls on a web page. You can use this element to trigger actions or…

HTML Link Attributes Guide for Beginners

HTML link attributes tell the browser how a link works. They set where the link goes, how it opens, and…

HTML Input Tag: How It Works, Types & Examples

The HTML input tag lets you add fields for user data in forms. You use this tag to collect text,…

Previous Article

HTML Global Attributes Overview

Next Article

HTML Data Attributes with Examples

Write a Comment

Leave a Comment

Your email address will not be published. Required fields are marked *


Subscribe to Get Updates

Get the latest updates on Coding, Database, and Algorithms straight to your inbox.
No spam. Unsubscribe anytime.