HTML:HTML セマンティック要素:<header>・<main>・<article>・<footer>
HTML•セマンティック HTML5

HTML セマンティック要素:<header>・<main>・<article>・<footer>

セマンティックタグはレイアウト領域の意味と目的をブラウザや支援技術へ明確に伝えます。

構文

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

パラメータと値

この構文の主な構成要素と指定可能な値:

パラメータ型説明
<main>Semantic Tag文書の主要な固有コンテンツを含みます(1 ページに 1 つのみ)。
<nav>Semantic Tag主要なナビゲーションリンクのブロックを宣言します。

そのまま実行できるコード例

Compilra で実行可能

HTML をローカルにインストールせずに、この動作する完全なコード例を直接実行できます:

<!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>
期待される出力:
[Semantic Full-Height Page Layout: Dark Header, Centered Content Article, and Dark Sticky Footer]

動作のしくみ: ステップ解説

  • 12-14 行目: <header> が上部のブランドバナーを定義します。
  • 15-20 行目: <main> と <article> が文書の中核となる記事を包みます。
  • 21-23 行目: <footer> が下部の著作権表示バーを描画します。

重要ポイント

  • アクセシビリティ向上のため意味のない <div> の多用をセマンティックタグへ置き換えましょう。
  • 1 つの文書につき <main> 要素は 1 つだけ配置する必要があります。

よくある間違い: セマンティックタグを使わずすべてのレイアウトコンテナに汎用 <div> を使う

<div> を乱用するとスクリーンリーダーからアクセシビリティのランドマーク情報が失われます。

❌ 誤り
<div id="header">...</div> <div id="footer">...</div>
✅ 正しい例
<header>...</header> <footer>...</footer>

関連するHTMLチュートリアルとコンパイラ

Compilra で HTML を実行・テストする

Compilraのクラウドコンパイラ上で事前設定した標準入力 (stdin) を使ってこのコードを実行できます。