DEV Community

Cover image for Semantic HTML
Estherngaire
Estherngaire

Posted on

Semantic HTML

Introduction

Semantic HTML is a way of writing code that helps computers and people understand the meaning and the structure of a web page, making it easier for search engines and assistive technologies to understand. Semantic HTML helps improve accessibility, better SEO, enhance user experience, improve code readability, improve performance etc. It uses special HTML tags that give the meaning of the content and help computers and people understand what each section of the page is for. In this article we’ll dive deeper at how semantic HTML helps improve SEO and accessibility, it’s comparison to non-semantic, benefits of using semantic and how to implement it effectively.

What is Semantic HTML

Semantic HTML means HTML that carries meaning tags that describe their purpose to the browser and to developers, such as <header>,<main>,<section>,<article> and <Footer>.Historically ,websites relied on <div> and <span>. Unlike <div> and <span> these tags give structure and provide context for browsers, search engines and assistive machines. Example;

Non-Semantic

My website

Welcome to my website

@ 2025 My website




GitHub logo Estherngaire / Semantic-HTML

Semantic html gives structure and provide context for browsers, search engines and assistive machines.The code is shorter, clearer and tells the search engine that the content is the page headers.

Home

Semantic is clearer

Semantic shows a clear structure of the page you are in




In the Semantic version, the code is shorter, clearer and tells the search engine that the content is the page headers whereas Non-Semantic doesn’t provide clear meaning to the structure making it difficult for screen readers and search engines to understand.<div> and <span>don't give any meaning. Semantic HTML has multiple benefits like;

*Improved accessibility
*Better Search engine Optimization
*Easier Maintenance and updates
*Improve code readability

Technical SEO benefits of Semantic HTML

One of the most effective benefit of using semantic HTML is it improves SEO. These Search engines analyze the page structure using tags like <header>, <nav> ,<article> and <section> making it clear which part of the page is important.An example of a html structure;

<html>
<head>
<title>Semantic<<title>
>/head>
<body>
<header>
<nav>
<a href="link">Home</a>
</nav>
</header>
<main>
<h1>Semantic is clearer </h1>
</main>

</body>
</html>
Each tag gives a meaning to each section the code;
<header> Defines the sections of a document
<nav> a set of navigation links
<main> Explains the main content of a document
<section>a self contained set of information, contacts, or any other secondary information
<aside> Defines content that is related to the main content
<footer> provides additional information about a website

This structure helps improve indexing and visibility. In measurable SEO, semantic HTML contributes to improved rankings, Rich snippet and performance gains.

Accessibility and Semantic HTML

Accessibility is ensuring all users, including the once with disability, can have access to a website freely. This is achievable with Semantic HTML because it creates landmarks and structure that assistive technologies can understand.Here are ways that Semantic HTML contributes:

• Provides automatic Accessible Rich Internet Application roles (ARIA).ARIA provides additional information about elements such as property,role and state;Example of ARIA attributes:

aria-label:Provides a text description
aria-labelledby:References the id of an element that provides text description.
aria-describedby:the id that provides additional information.
role:Defines the role of an item,such as button or navigation region
aria-live:indicates that an element will be updated

This reduces the need for adding role attributes manually, minimizing redundancy and error

• Creates landmarks for screen readers to announce sections: Elements like <header>,<nav>, <main>, and <footer> act as landmarks. Screen readers can easily read through these without listening to every element.

• Heading hierarchy; proper heading order <h1> to <h6> helps assistive technologies help users go through headings like a table of content.

• Enhanced user experience:With the help of tags,screen readers provide accurate and helpful feedback,improving overall user experience

• Improved Navigation:Screen readers can provide shortcuts to navigate between elements.

WCAG

Web Content Accessibility Guidelines are like rulebooks that ensure people with disability can also use a website.Its organized into four principals.(POUR)

  1. Perceivable:Information must be presented in ways users understand like providing alternative text for images,using proper headings <h1>-<h6>
  2. Operable:Users must be able to operate navigation
  3. Understandable:writing clear instruction and avoiding complex languages helps users understand easily.
  4. Robust:Content should work in all devices and assistive technologies.like testing the code on multiple browsers,Ensuring ARIA are used correctly and using valid semantic html so screen readers would interpret easily

Testing Methodologies
Testing methodologies is basically testing the code to ensure that its accessible to all users.
A. Automated testing:Using tools like google light house,Wave and axe Devtools to identify any errors
b. User-centered Evaluations:Involving users with disabilities to test to provide their feedback
c. Manual testing: Human review to identify the complex issue that a tool might have missed.

Real-world Implementation Scenarios

  1. When writing an article or blog post,<article>,<section> and <aside> are used to separate post,advertisement or related content.
  2. Cooperate sites rely on <header>,<nav>and <footer> to create consistent layout across pages while making navigations accessible to screen readers.

Best practices and common Pitfalls

Best practices

  1. One <main> per page ;helps search engines and assistive technologies focus on the main content
  2. Follow a proper heading hierachy<h1> for main title <h2>,<h3>,...
  3. Using Semantic elements where possible; For clean and readable code
  4. Use <article> for shareable content like blog posts
  5. Provide alternative text for images with <img alt="..">

Common Pitfalls

  1. Multiple <main> elements. This makes it hard for assistive technologies to focus on the core content
  2. Overusing <div> element instead of using semantic tags.
  3. Skipping heading levels. Follow the way they are. Don’t jump from <h1> to <h6>
  4. Redundant ARIA roles. <nav role=”navigation”> is unnecessary - <nav> already provides this role
  5. Wrong placement of tags example <title> inside of <header>

Technical testing and validation
They are ways that check html codes to make sure they follow valid HTML rules.Think of it like proofreading and spell-checking for errors.Examples;
A. Validators:tool used is W3C validator.It checks if your html follows the rules
b. Accessibility tools: tools used are Light house,Wave,axe.This tools show how people and assistive technologies are experiencing the page
c. Browser Devtools like chrome/firefox,brave to see if there is errors or something missing

Conclusion
Semantic HTML is a game changer for web development, with it offering improved accessibility, easier maintenance and better SEO. With the help of semantic HTML elements, one can create a website that’s readable, user friendly and structured. And as the web continues to grow, so will the importance of Semantic HTML making it an essential skill for any developer looking to create a website that’s accessible and functional.

Top comments (0)