Semantic HTML5: Exploring its concept and benefits in web development.

Introduction

If you are unfamiliar with the new semantic tags in HTML5, this guide will help you catch up. Web development has always evolved to meet the needs of a competitive market that quickly adopts new technologies. Although the HTML specification is relatively slow, HTML5 has introduced numerous new semantic tags that improve SEO and accessibility.

When I first started building websites, I used <div> and <span> tags to structure the HTML code. However, I recently discovered semantic tags designed to provide a more meaningful and intuitive structure to websites.

Initially, I was a bit confused about these tags and their purpose. However, as a Techster fellow at Tech4Dev, I had the opportunity to create websites using HTML with my fellow cohorts.

Our facilitator, Ayodele, taught us about using semantic HTML tags, which proved valuable as it helped me develop more readable and meaningful web pages. I was surprised at how useful these tags can be and realized I had missed out on their benefits for so long.

As a front-end developer, it's essential to understand that semantic HTML tags are crucial for building accessible and search engine-friendly websites. Semantic HTML provides meaningful structures for your web pages, making it easier for machines and developers to understand your code.

In this article, I will share what I learned about these helpful elements so that you can also benefit from them. We will examine the concept of semantic HTML and how to use these elements effectively in web development projects.

HTML5

What is semantic HTML?

Semantic HTML refers to using HTML tags that communicate meaning beyond visual presentation. Instead of relying solely on generic divs and spans, semantic elements accurately describe the role and purpose of the content they contain.

For example, when you use a semantic element like the <header> tag to wrap a heading section of your page or a <nav> tag to represent a navigation of the links section, it provides more context for the content within those elements.

The main advantage of semantic HTML to your pages is that it can help search engines and developers understand better the intent of that content and provide a more meaningful user experience.

additionally, it gives information that helps define the relative importance and roles of the different parts of your web page, unlike non-semantic HTML, which uses tags that don’t directly convey meaning.

Benefits of using semantic HTML tags

Semantic HTML tags offer several benefits when used to structure a webpage.

  1. Improved Accessibility: Semantic HTML tags provide meaning to the content of a webpage and make it easier for assistive technologies like screen readers to present and interpret the information to users with disabilities.

  2. Search Engine Optimization (SEO): when you use semantic HTML tags, you are providing a clear signal to search engines about the meaning and relevance of different sections of your content. It helps to enhance your website's ranking and visibility in search engine results.

  3. Readability and Maintainability: It promotes clean and well-organized code. when you use tags that accurately define the content, it becomes easier for developers to understand and maintain the codebase. It also creates a logical structure to identify and modify specific parts of the document.

  4. Future Compatibility: HTML constantly evolves, and new elements and attributes are introduced over time. semantic tags ensure your code is forward-compatible and aligns with the latest HTML standards. The risk of your code becoming outdated is reduced.

  5. Consistency and Styling: most times, semantic HTML tags have default styles that are associated with them. This helps to maintain a consistent appearance across different devices and browsers. semantic markup also makes it easier for developers to apply CSS styles to specific elements because the purpose and structure of the contents are clearly defined.

  6. Team Collaboration and Communication: It promotes better communication between developers, content creators, and designers. If everyone on the team understands the meaning and structure of the different document parts, it will be easier to collaborate and maintain a cohesive vision for the website.

Semantic vs non-semantic HTML Elements

image from https://suyashpradhan.hashnode.dev/semantic-html

Examples of Semantic HTML Tags

  1. <header>

    it is a tag used to introduce the content of a page or a container for a group of introductory content.

    </header>

  2. <nav>

    this tag is used to create a section on a webpage that contains links to navigate to different parts of the website.

    </nav>

  3. <main>

    It is used to define the primary or main content of a document. It is an important HTML tag that helps in structuring the web page and differentiating the main content from other sub-sections.

    </main>

  4. <article>

    This tag represents a self-contained composition in a document, such as a blog post or news article.

    </article>

  5. <section>

    It defines a distinct section of a document. It is often used to group related content.

    </section>

  6. <aside>

    represents content tangentially related to the main content, such as sidebars or pull quotes.

    </aside>

  7. <footer>

    This section typically appears at the end of a document and contains important information such as contact details and copyright information.

    </footer>

  8. <figure> It represents self-contained content, such as images or diagrams, and their respective captions.

    </figure>

  9. <figcaption>

    an HTML tag that provides a caption or description for a <figure> element.

    </figcaption>

  10. <time>

    It is an HTML tag representing a specific date and time.

    </time>

The following code contains some semantic HTML tags to explain this context better.

<header>
      <h1>A Webpage</h1>
</header>
   <section>
      <article>
        <figure>
            <img src="#">
            <figcaption></figcaption>
        </figure>
      </article>
   </section>
<footer></footer>

Examples of Non-Semantic HTML tags:

Unlike semantic HTML tags, non-semantic tags don't have any meaning, and they do not provide any information about the content they contain. It's essential to understand that while non-semantic tags serve distinct purposes, they can be used with various attributes to mark up semantics common to a group. Here is a list of some non-semantic elements.

  1. <div>: this HTML tag is a generic container for grouping elements or applying CSS styles.

  2. <span>: a generic inline commonly used for applying CSS styles or manipulating text within a larger context.

  3. <p>: represents a paragraph of text.

  4. <strong>: indicates a strong emphasis on text.

  5. <em>: indicates emphasis on text.

  6. <br>: inserts a line break.

  7. <img>: embeds an image in a document.

  8. <a>: creates a hyperlink to another webpage or resource.

  9. <input>: represents an input control element, such as a text box or checkbox.

  10. <button>: represents a clickable button.

    <div id="header"></div>
    <div class="section">
        <div class="article">
            <div class="figure">
                <img>
                <div class="figcaption"></div>
            </div>
        </div>
    </div>
    <div id="footer"></div>
    

Take a look at the two blocks of code above. What did you notice? Firstly, you will notice that the first block of code that uses semantic HTML tags is much easier to read than the second one.

This is just a little example because, as a programmer, you will often come across many lines of code. That is where semantic HTML tags come in handy. So, it is always advisable to use semantic HTML tags to make your code more readable and your job much easier.

2
Subscribe to my newsletter

Read articles from Peace Chinaza Nwosu directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Peace Chinaza Nwosu
Peace Chinaza Nwosu

Hi there! I’m Peace from Lagos Nigeria. I am a front-end developer and technical writer.