What is aria-hidden Attribute in HTML: Simple Explanation
aria-hidden attribute in HTML tells assistive technologies like screen readers whether to ignore an element. When set to true, the element and its children are hidden from screen readers, improving accessibility by controlling what content is announced.How It Works
The aria-hidden attribute acts like a 'do not disturb' sign for screen readers. Imagine a room where some conversations are private and should not be overheard. Setting aria-hidden="true" on an element tells screen readers to skip that element and everything inside it, so users relying on these tools won't hear about it.
This attribute does not hide the element visually on the page; it only affects what assistive technologies announce. This helps developers control the reading order and avoid confusion by hiding decorative or redundant content from screen readers.
Example
This example shows a visible message that is hidden from screen readers using aria-hidden.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>aria-hidden Example</title> </head> <body> <h1>Welcome to Our Website</h1> <p aria-hidden="true">This text is visible but hidden from screen readers.</p> <p>This text is visible and read by screen readers.</p> </body> </html>
When to Use
Use aria-hidden="true" when you want to hide content from screen readers but keep it visible on the page. This is helpful for:
- Decorative icons or images that do not add meaning.
- Duplicate content that might confuse screen reader users.
- Elements used only for visual effects or layout.
Do not use it to hide important information or interactive elements, as this can make your site inaccessible.
Key Points
- aria-hidden controls screen reader visibility, not visual display.
- Setting it to
truehides the element and its children from assistive tech. - Helps improve accessibility by reducing noise for screen reader users.
- Should not be used to hide important or interactive content.