HTML:HTML Semantic Elements: <header>, <main>, <article>, and <footer>
HTML•Semantic HTML5

HTML Semantic Elements: <header>, <main>, <article>, and <footer>

Semantic tags communicate the meaning and purpose of layout sections to browsers and assistive technologies.

Syntax

<header><nav></nav></header> <main><article></article></main> <footer></footer>

Parameters & Values

Key components and acceptable values for this structure:

ParameterTypeDescription
<main>Semantic TagContains dominant unique content of document (only one per page).
<nav>Semantic TagDeclares major navigation link blocks.

Ready-to-Run Code Example

Executable in Compilra

Run this complete, working example directly without installing HTML locally:

<!DOCTYPE html>
<html>
<head>
  <style>
    body { font-family: sans-serif; margin: 0; display: flex; flex-direction: column; min-height: 100vh; }
    header, footer { background: #0f172a; color: white; padding: 15px 20px; }
    main { flex: 1; padding: 20px; max-width: 600px; margin: auto; }
    article { background: white; border: 1px solid #e2e8f0; border-radius: 8px; padding: 15px; margin-bottom: 15px; }
  </style>
</head>
<body>
  <header>
    <strong>Compilra Platform</strong>
  </header>
  <main>
    <article>
      <h2>Zero-Setup Cloud Execution</h2>
      <p>Compile and run C++, Python, and Rust code in isolated containers with instant output.</p>
    </article>
  </main>
  <footer>
    &copy; 2026 Compilra Technologies. All rights reserved.
  </footer>
</body>
</html>
Expected Output:
[Semantic Full-Height Page Layout: Dark Header, Centered Content Article, and Dark Sticky Footer]

How It Works: Step-by-Step

  • Lines 12-14: <header> defines top brand banner.
  • Lines 15-20: <main> and <article> encapsulate core document article.
  • Lines 21-23: <footer> renders bottom copyright compliance bar.

Key Concepts

  • Replace meaningless <div> soup with semantic tags for accessibility.
  • There must be only one <main> element per document.

Common Mistake: Using generic <div> for all layout containers instead of semantic tags

Overusing <div> strips accessibility landmarks from screen readers.

❌ Incorrect
<div id="header">...</div> <div id="footer">...</div>
✅ Correct
<header>...</header> <footer>...</footer>

Related HTML Tutorials & Compiler

Run and test HTML on Compilra

Execute this code snippet with pre-supplied standard input (stdin) in Compilra’s cloud compiler.

HTML Online Compiler