DEV Community

Cover image for Understand web Accessibility: semantic HTML (part 8)
Abdermaiza
Abdermaiza

Posted on

Understand web Accessibility: semantic HTML (part 8)

With over 100 HTML elements, you can create your own markup in infinite ways, but which one will be the best?...

HTML semantics provide accessibility information about page structure and an element's role, name, and state, helping to convey the nature and purpose of content on web pages.
By using HTML elements instead of a div soup without any semantic value, you are helping users and Google's robots to understand your web content...
If a developer used a <div> instead of a <header>, the implicit role would be absent, unless provided with extra code. That means the HTML won't be as useful to the machines that interpret it.

Structuring content

You can first try to always use semantic landmarks like header, main, aside, footer and nav elements.
Then, you should also use the good HTML element for each purpose:

  • a p will be the direct parent of paragraph of text, not a div

  • if you need a link or an anchor, use an a element, not a button

  • if you need an action (like opening a modal, closing a burger menu, expanding some content, playing a media, validate a form), use a <button> element

  • for a title or a subtitle, prefer the h1 to h6 elements and respect the order

  • if you have a list of items, use an ul & li combo...

Naming things as they are

Just by this way, using semantic HTML, you can for instance tell to screen reader users that an component is a button, or a link or a list of items. A div alone will not provide any information about your content...
Elements like <div>s and <span>s are meaningless, inert. You can use them for layout and styling, but not to replace semantic HTML5, as it will require a lot of JavaScript to mimic the real HTML5 element.

Always choose an existing HTML5 element first!

Sources:

AWS Q Developer image

Your AI Code Assistant

Automate your code reviews. Catch bugs before your coworkers. Fix security issues in your code. 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. ❤️