Open In App

What are these attributes `aria-labelledby` and `aria-hidden` ?

The term, ARIA with attributes such as aria-labelledby and aria-hidden stands for Accessible Rich Internet Applications. These are the set of standards and guidelines that makes web applications more accessible to people with disabilities. This is used in the interactive content in an HTML document such as error messages, progress bars, progressive hints, etc.

There are multiple ARIA attributes which are as follows



aria-hidden: The ARIA attribute aria-hidden is used to indicate assistive technologies like screen-readers which dictates the content on the document to people with disabilities that the content with this attribute can actually be skipped. The screen-reader will skip the element content without dictating them.

What type of content should have an aria-hidden attribute? 
Content that does not hold significant meaning can be skipped. Examples of such content includes the following. 
 



Difference between aria-hidden and HTML’s native hidden attributes:

Example:




<!DOCTYPE html>
<html>
 
<body>
    <h2>Welcome To GFG</h2>
     
    <p aria-hidden="true">
        This content will be
        skipped by Screen-Readers
    </p>
 
</body>
 
</html>

Output: 
 

The “p” element contents are non-interactive content, so these are hidden from the screen readers. 
 

 

Key things to know about aria-hidden are as follows. 
 

 

 

aria-labelledby: The aria-labelledby attribute is used to relate labels and the element containing labelling text. The value for the aria-labelledby is usually the ID of an element containing the labelling text. It can have more than one element id in its value part. 
This is very similar to an input element containing a for attribute to link labels.

 

Example:

 




<!DOCTYPE html>
<html>
 
<body>
    <h2>Welcome To GFG</h2>
    <div id="myBillingId">Billing</div>
 
    <div>
        <div id="myFirstName">First Name</div>
        <input type="text"
            aria-labelledby="myFirstName" />
    </div>
 
    <div>
        <div id="myContactNumber">
            Contact Number
        </div>
         
        <input type="text" aria-labelledby
            ="myFirstName myContactNumber" />
    </div>
</body>
 
</html>

When to use HTML specification attribute and ARIA attribute?

ARIA specifications are for contents that are intended for people with disabilities as well. It might be meaningful to use HTML specification attribute in some cases and ARIA specification in some cases and this has to be dealt with respect to the target audience.


Article Tags :