Lesson 1 of 12 · 11 min · HTML and CSS

Semantic HTML: structuring a page

Covers: Current HTML Living Standard. Updated 13 Nov 2026. Part of the Frontend Developer roadmap.

What you will learn

  • The structure of an HTML document
  • Landmark elements: header, nav, main, section, article, aside, footer
  • Headings, paragraphs, lists, links and images
  • Why choosing the right element matters
  • Avoid "div soup" and common markup mistakes

In simple words

HTML is the skeleton of a web page. It does not say how things look (that is CSS); it says what things are: this is a heading, this is a list, this is the navigation, this is the main article. Using the right tag for each part is called semantic HTML. It lets browsers, search engines and screen readers understand the page, the way chapter titles and page numbers help a reader navigate a book.

Words to know

  • Element: a piece of a page made of an opening tag, content and a closing tag, such as <p>Hello</p>.
  • Attribute: extra information inside a tag, such as href in a link.
  • Semantics: the meaning an element carries, beyond how it looks.
  • Landmark: a major region of a page, such as the navigation or main content.

A minimal document

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Interview practice | Myskillgrid</title>
  <meta name="description" content="Practise interview questions for your target job.">
  <link rel="stylesheet" href="styles.css">
</head>
<body>
  <h1>Hello, world</h1>
  <p>This is a paragraph.</p>
</body>
</html>
  • <!DOCTYPE html> switches the browser into standards mode.
  • lang="en" tells browsers and screen readers the page language (use hi, te, ta for pages in those languages; it chooses pronunciation and hyphenation).
  • charset="utf-8" makes Indian scripts, the rupee sign and emoji display correctly.
  • The viewport meta tag is required for pages to work on phones (the responsive lesson explains why).
  • <title> shows in the tab, bookmarks and search results; make it unique per page.
  • Content goes in <body>; metadata, styles and scripts go in <head>.

Landmarks: the structure of a page

<body>
  <a class="skip-link" href="#main">Skip to main content</a>

  <header>
    <a href="/" aria-label="Home"><img src="logo.svg" alt="Myskillgrid" width="140" height="32"></a>
    <nav aria-label="Main">
      <ul>
        <li><a href="/roadmaps/">Roadmaps</a></li>
        <li><a href="/learn/" aria-current="page">Learn</a></li>
        <li><a href="/pricing/">Pricing</a></li>
      </ul>
    </nav>
  </header>

  <main id="main">
    <article>
      <h1>How to prepare for a Java interview</h1>
      <p>Published <time datetime="2025-10-31">31 October 2025</time></p>

      <section>
        <h2>Core Java</h2>
        <p>...</p>
      </section>

      <section>
        <h2>Spring Boot</h2>
        <p>...</p>
      </section>
    </article>

    <aside>
      <h2>Related articles</h2>
      <ul>...</ul>
    </aside>
  </main>

  <footer>
    <p>&copy; 2025 Example Company</p>
  </footer>
</body>
Element Meaning
<header> introductory content for the page or a section (logo, title, navigation)
<nav> a major block of navigation links
<main> the primary content, one per page
<article> a self-contained piece that makes sense on its own (a post, a product card, a comment)
<section> a thematic group of content, normally with a heading
<aside> related but secondary content (a sidebar, a pull quote)
<footer> closing content for the page or a section (copyright, links)
<figure> / <figcaption> an image, chart or code sample with a caption

Screen reader users can jump between these landmarks, so a page built from them is far easier to navigate than a page of identical <div>s.

Headings

Headings form an outline of the page: <h1> is the main title (usually one per page), <h2> the main sections, <h3> the subsections, down to <h6>.

  • Do not skip levels (an <h2> followed directly by an <h4>).
  • Choose a heading level for structure, not for size; change the look with CSS.
  • Screen reader users and search engines both use headings to navigate and understand the page.

Images

<img src="/images/roadmap.png" alt="A roadmap showing SQL, Python and Power BI as steps for a data analyst"
     width="800" height="450" loading="lazy">
  • alt text describes the image's purpose for people who cannot see it: informative images get a short description; decorative images get an empty alt="" so screen readers skip them. Never omit alt.
  • Set width and height so the browser reserves space and the layout does not jump while the image loads (performance lessons).
  • loading="lazy" delays offscreen images. Do not lazy-load the main image at the top of the page.
  • <picture> and srcset serve different image files for different screens (responsive lesson).
  • For charts, give a text summary nearby, not only the picture.

Why semantics matter

  • Accessibility: assistive technology uses the element types to announce "navigation", "main", "heading level 2", "button" and to let users jump around. A <div onclick> pretending to be a button has none of that (and no keyboard support).
  • Search engines: headings, lists and landmarks help them understand and summarise a page; structured data (JSON-LD) adds more.
  • Built-in behaviour: <button>, <a href>, <input>, <details> and <dialog> come with keyboard handling, focus, and states for free.
  • Maintainability: <nav> and <footer> tell the next developer what a block is. Well-structured HTML needs less CSS and JavaScript.
  • Reader modes, translation and printing work better.

"Div soup" is a page made only of <div> and <span> with classes like .top-bar and .box: it looks fine but means nothing to a machine. Use <div> and <span> only when no semantic element fits (a wrapper for layout or styling).

Other useful elements

  • <details> and <summary>: a disclosure widget (FAQ) with no JavaScript.
  • <dialog>: a modal or non-modal dialog with built-in focus handling.
  • <time datetime="...">, <address>, <blockquote>, <cite>, <mark>, <kbd>, <small>.
  • <button type="button"> versus type="submit" (the forms lesson).
  • <video> and <audio> with controls, captions via <track>.
  • Entities: &amp;, &lt;, &gt;, &quot;, &copy;, &nbsp;.

Validating your HTML

Run the page through the W3C Nu HTML Checker (validator.w3.org) or your editor's linter. Typical errors: unclosed tags, duplicate id values (ids must be unique), block elements inside inline ones, missing alt, invalid nesting (a <div> inside a <p>, a <button> inside an <a>). Valid markup is the foundation for predictable CSS and JavaScript.

Common mistakes

  • Using headings for size or skipping heading levels.
  • Clickable <div>s instead of <button> or <a href>.
  • Missing or useless alt text ("image", the file name).
  • Tables for layout.
  • Several <main> elements or duplicate ids.
  • Link text such as "click here".
  • Forgetting the viewport and lang.

Try it yourself

  1. Build a page for a fictional course with header, nav, main, an article with two sections, an aside and a footer.
  2. Check the heading outline: is there one h1 and no skipped levels?
  3. Add an informative image with alt text and a decorative one with alt="".
  4. Replace a <div class="btn"> with a real <button> and a real link, and note what you get for free.
  5. Validate the page with the W3C checker and fix every error.

Check yourself

What does "semantic HTML" mean?

Choosing elements for what the content is (heading, navigation, list, button), not just how it looks, so browsers, search engines and assistive technology can understand the page.

When should an image have alt=""?

When it is purely decorative, so screen readers skip it; informative images need a descriptive alt.

What is the difference between <section> and <article>?

An <article> is self-contained and makes sense on its own; a <section> is a thematic group within a page, normally introduced by a heading.

Why is a <button> better than a <div> that you click?

A <button> is focusable, activated by Enter and Space, announced correctly by screen readers and has form behaviour built in; a <div> needs all of that added by hand.

Interview questions

Why is semantic HTML important?

It improves accessibility, SEO, maintainability and built-in behaviour: assistive technology uses elements and landmarks for navigation, search engines understand structure, and elements such as button and dialog provide keyboard support for free.

What is the difference between <div> and <span>?

Both have no meaning. <div> is a block-level container; <span> is an inline container for part of a line of text.

What are <strong> and <em> for, compared with <b> and <i>?

<strong> and <em> express importance and emphasis; <b> and <i> are presentational. Use CSS for pure styling.

Summary

  • A page has a doctype, lang, charset, viewport and title; content lives in landmarks (header, nav, main, article, aside, footer).
  • Headings form the outline; links go somewhere, buttons do something; every informative image needs alt.
  • Semantic elements give accessibility, SEO and behaviour for free; avoid div soup.
  • Validate your markup.

Going deeper

See how much of this you can explain

A free mock interview asks you new questions on HTML, CSS and how the web works for Frontend Developer and scores every answer, with what to fix.