DEV Community

Cover image for HTML Semantic Elements(A to Z)
Ridoy Hasan
Ridoy Hasan

Posted on

HTML Semantic Elements(A to Z)

HTML Semantic Elements: A Comprehensive Guide

HTML semantic elements clearly describe their meaning in a way that both the browser and the developer can understand. They enhance the readability and accessibility of web pages. This guide explores various semantic elements, their purposes, and practical code examples.

What Are Semantic Elements?

Semantic elements are HTML elements that convey meaning about the content they contain. Unlike non-semantic elements like <div> and <span>, semantic elements provide a clear structure to the web page.

Common HTML Semantic Elements

  1. <header>: Defines a header for a document or a section.
  2. <nav>: Defines a container for navigation links.
  3. <article>: Represents a self-contained piece of content.
  4. <section>: Defines a section in a document.
  5. <aside>: Defines content aside from the content it is placed in.
  6. <footer>: Defines a footer for a document or a section.
  7. <main>: Specifies the main content of a document.
  8. <figure>: Specifies self-contained content, like illustrations or diagrams.
  9. <figcaption>: Provides a caption for a <figure> element.
  10. <time>: Represents a specific time or date.

Example: Using Semantic Elements

Let's create a simple webpage using semantic elements to demonstrate their usage.

HTML Code:

<!DOCTYPE html>
<html>
<head>
    <title>Semantic HTML Example</title>
</head>
<body>
    <header>
        <h1>Welcome to My Website</h1>
        <nav>
            <ul>
                <li><a href="#home">Home</a></li>
                <li><a href="#about">About</a></li>
                <li><a href="#contact">Contact</a></li>
            </ul>
        </nav>
    </header>

    <main>
        <section id="home">
            <h2>Home</h2>
            <p>This is the home section of the webpage.</p>
        </section>

        <section id="about">
            <h2>About</h2>
            <article>
                <h3>About Us</h3>
                <p>We are a company that values excellence and innovation.</p>
            </article>
        </section>

        <section id="contact">
            <h2>Contact</h2>
            <aside>
                <h3>Contact Information</h3>
                <p>Email: info@example.com</p>
                <p>Phone: 123-456-7890</p>
            </aside>
        </section>
    </main>

    <footer>
        <p>&copy; 2024 My Website. All rights reserved.</p>
    </footer>
</body>
</html>
Enter fullscreen mode Exit fullscreen mode

Output:

Welcome to My Website

  • Home
  • About
  • Contact

Home
This is the home section of the webpage.

About
About Us
We are a company that values excellence and innovation.

Contact
Contact Information
Email: info@example.com
Phone: 123-456-7890

Β© 2024 My Website. All rights reserved.

In this example, we use semantic elements like <header>, <nav>, <main>, <section>, <article>, <aside>, and <footer> to structure the webpage. These elements improve the readability of the HTML code and help search engines and assistive technologies understand the content better.

Benefits of Using Semantic Elements

  • Improved Readability: Semantic elements make the HTML code more readable and understandable for developers.
  • Better SEO: Search engines can better understand and index the content, improving search engine rankings.
  • Enhanced Accessibility: Assistive technologies can better interpret the content, improving the user experience for people with disabilities.
  • Consistent Structure: Provides a consistent and standardized way to structure web pages.

Conclusion

Understanding and using HTML semantic elements is essential for creating well-structured, accessible, and SEO-friendly web pages. By incorporating these elements into your projects, you can improve the readability and functionality of your web content.

FOLLOW ME ON LINKEDIN -

https://www.linkedin.com/in/ridoy-hasan7

Top comments (2)

Collapse
 
jonrandy profile image
Jon Randy πŸŽ–οΈ

Common HTML Semantic Elements

Many obvious ones missing from your list... paragraphs, lists, etc.

Collapse
 
ridoy_hasan profile image
Ridoy Hasan

thanks @jonrandy .
Actually I have discussed about them in other articles