Semantic HTML helps browsers and people understand the structure and meaning of a webpage. It makes websites easier to use, find, and maintain.
Why semantic HTML matters
<header> ... </header> <nav> ... </nav> <main> ... </main> <section> ... </section> <article> ... </article> <footer> ... </footer>
Semantic tags describe the role of the content inside them, like <header> for page header or <nav> for navigation links.
Using semantic tags helps assistive technologies and search engines understand your page better.
<header> tag holds the main heading of the page.<header> <h1>My Website</h1> </header>
<nav> tag groups navigation links.<nav> <ul> <li><a href="#home">Home</a></li> <li><a href="#about">About</a></li> </ul> </nav>
<main> tag holds the main content, and <article> is for a self-contained piece of content.<main> <article> <h2>Article Title</h2> <p>Article content goes here.</p> </article> </main>
<footer> tag contains footer information like copyright.<footer> <p>Ā© 2024 My Website</p> </footer>
This webpage uses semantic tags to organize content clearly. It includes a header, navigation, main content with sections and articles, and a footer. The aria-label on the nav helps screen readers understand the navigation purpose.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Semantic HTML Example</title> </head> <body> <header> <h1>Welcome to My Site</h1> </header> <nav aria-label="Main navigation"> <ul> <li><a href="#home">Home</a></li> <li><a href="#services">Services</a></li> <li><a href="#contact">Contact</a></li> </ul> </nav> <main> <section> <h2>About Us</h2> <p>We provide helpful web development tutorials.</p> </section> <article> <h2>Latest Article</h2> <p>Learn why semantic HTML matters for everyone.</p> </article> </main> <footer> <p>Ā© 2024 My Site</p> </footer> </body> </html>
Always use semantic tags instead of generic <div> when possible.
Semantic HTML improves accessibility for people using screen readers.
Search engines use semantic tags to better rank and display your pages.
Semantic HTML gives meaning to your webpage structure.
It helps users, search engines, and developers understand your content.
Use semantic tags like <header>, <nav>, <main>, <section>, <article>, and <footer>.