DEV Community

Jake Espinosa
Jake Espinosa

Posted on

1

ARIA Landmark Roles: Why You Need To Use Them

When sighted people view a webpage, they can usually discern the structure at a glance. The header, main content area, footer, sidebar, etc stand out. However, the visually impaired don't have the same luxury. To even the playing field and make the web more accessible for all, we must use ARIA landmark labels in our HTML markup.

What Are Landmarks and Landmark Roles?

Landmarks are discrete components of webpages that form the overall structure, with headers, navbars, and footers as some examples. As mentioned, sighted users can typically identify these landmarks quickly, while visually impaired users cannot. To fix this, the HTML spec introduced ARIA landmark roles.

Landmark roles are implicit and explicit labels (not ARIA labels, though) for screen readers to understand the page structure. Elements such as <header> and <main> have implicit landmark roles, and elements such as <div> do not and require explicitly adding landmark roles. These landmark roles enable screen readers to present a website's general map to users and allow skip links.

However, not every div or non-semantic element needs a landmark role. It does not require a landmark role if you use a div for styling purposes and not as a button, navbar, or something else a sighted person could see. Be careful not to over-apply landmark roles and diminish their value to the user.

Landmark roles are so easy to use that there is no excuse not to. Add a role="<someRole>" attribute into your markup to increase accessibility and the user experience for your visually-impaired users.

Best Practices

  • Use when you are using a non-semantic element like a div for page structure and not styling
  • Asses your markup with an accessibility scanner like Lighthouse (built into ChromeDevTools)
  • Use standard names for landmark roles

Takeaway

As web developers, we must constantly strive to improve accessibility in any way we can. Use ARIA landmark roles to improve the accessibility and navigability of your website. Some semantic HTML elements have landmark roles built in, and some must have ARIA landmark roles explicitly added as attributes. By adding these roles, you will increase your website's accessibility and do your part to make the web more accessible to all.

AWS Q Developer image

Your AI Code Assistant

Generate and update README files, create data-flow diagrams, and keep your project fully documented. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Instrument, monitor, fix: a hands-on debugging session

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

Tune in to the full event

DEV is partnering to bring live events to the community. Join us or dismiss this billboard if you're not interested. ❤️