HTML:HTML 表形式データマトリクス:テーブルセマンティクスを用いた構造化レイアウト
HTML•ループ

HTML 表形式データマトリクス:テーブルセマンティクスを用いた構造化レイアウト

Web 上で表形式のデータマトリクスや多次元の運用指標を提示する際、セマンティックな HTML テーブル構造は優れたアクセシビリティ、スクリーンリーダーによるセルナビゲーション、正確な列揃えを実現します。scope 属性やゼブラストライプを備えた構造化 <thead>・<tbody>・<tfoot> ブロックにより、レイアウトシフトのない高密度なレコード表を描画できます。

構文

<table class="data-matrix"> <thead><tr><th scope="col">Node ID</th><th scope="col">Status</th></tr></thead> <tbody><tr><td>cluster-01</td><td>HEALTHY</td></tr></tbody> <tfoot><tr><td colspan="2">Cluster Status: All OK</td></tr></tfoot> </table>

パラメータと値

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

パラメータ型説明
<table>Root Element表形式データマトリクスの構造的境界を定義します。
<thead>, <tbody>, <tfoot>Semantic Sectionsマトリクスのヘッダー、反復データ行セット、集計フッター行を分離します。
<th scope="col|row">Header Cell見出しセルが列と行のどちらを分類しているかを支援技術へ明示します。
<td colspan|rowspan>Data Cell最小単位のレコードデータを保持し、集計時には複数の列や行にまたがります。

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

Compilra で実行可能

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

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Cloud Fleet Telemetry Matrix</title>
  <style>
    body { font-family: system-ui, -apple-system, sans-serif; background: #0b0f19; color: #f8fafc; padding: 24px; }
    .table-container { overflow-x: auto; max-width: 720px; border-radius: 12px; border: 1px solid #334155; }
    table { width: 100%; border-collapse: collapse; text-align: left; font-size: 14px; }
    thead tr { background: #1e293b; color: #38bdf8; border-bottom: 2px solid #475569; }
    th, td { padding: 12px 16px; }
    th { font-weight: 700; text-transform: uppercase; font-size: 12px; letter-spacing: 0.05em; }
    tbody tr { border-bottom: 1px solid #1e293b; transition: background 0.15s; }
    tbody tr:nth-child(even) { background: #0f172a; }
    tbody tr:hover { background: #1e293b; }
    .status-badge { display: inline-block; padding: 2px 8px; border-radius: 9999px; font-size: 11px; font-weight: 700; }
    .status-online { background: #064e3b; color: #34d399; }
    .status-warn { background: #78350f; color: #fcd34d; }
    .mono { font-family: ui-monospace, SFMono-Regular, monospace; }
    tfoot { background: #1e293b; font-weight: 700; color: #94a3b8; border-top: 2px solid #475569; }
  </style>
</head>
<body>
  <h2>Cloud Fleet Compute Matrix</h2>
  <div class="table-container">
    <table>
      <thead>
        <tr>
          <th scope="col">Instance ID</th>
          <th scope="col">Region</th>
          <th scope="col">vCPU / RAM</th>
          <th scope="col">P99 Latency</th>
          <th scope="col">Health</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td class="mono">srv-us-east-01</td>
          <td>US East (N. Virginia)</td>
          <td>64 cores / 256 GB</td>
          <td class="mono">14.2 ms</td>
          <td><span class="status-badge status-online">HEALTHY</span></td>
        </tr>
        <tr>
          <td class="mono">srv-eu-west-02</td>
          <td>EU West (Frankfurt)</td>
          <td>32 cores / 128 GB</td>
          <td class="mono">28.7 ms</td>
          <td><span class="status-badge status-online">HEALTHY</span></td>
        </tr>
        <tr>
          <td class="mono">srv-ap-south-01</td>
          <td>AP South (Mumbai)</td>
          <td>16 cores / 64 GB</td>
          <td class="mono">88.4 ms</td>
          <td><span class="status-badge status-warn">DEGRADED</span></td>
        </tr>
      </tbody>
      <tfoot>
        <tr>
          <td colspan="2">Active Cluster Total: 3 Nodes</td>
          <td colspan="3" style="text-align: right;">Capacity: 112 vCPUs | 448 GB RAM</td>
        </tr>
      </tfoot>
    </table>
  </div>
</body>
</html>
期待される出力:
[Rendered Telemetry Matrix Table: Dark styled tabular rows with zebra striping, scoped column headers, latency metrics, and summary tfoot capacity counters]

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

  • 20-30 行目: scope="col" 属性を持つアクセシブルな列見出しを含む <thead> ブロックを定義します。
  • 31-54 行目: 対になった <tr> と <td> セルで構成された <tbody> の反復データ行を定義します。
  • 55-60 行目: colspan="2" と colspan="3" を用いてクラスター指標を集計する <tfoot> 集計行を定義します。
  • 9-15 行目: 表の視認性を高めるため CSS の border-collapse: collapse と nth-child(even) のゼブラストライプを適用します。

重要ポイント

  • HTML テーブルは構造化された表形式データマトリクス専用とし、汎用ページレイアウトのグリッドには使用すべきではありません。
  • scope="col" および scope="row" 属性は、スクリーンリーダーに不可欠なナビゲーションの目印を提供します。
  • テーブルを <thead>・<tbody>・<tfoot> に分割すると、印刷時のヘッダー繰り返しや明確なスタイル分離が可能になります。
  • colspan 属性により、フッター内の単一集計セルを複数の表列にまたがらせることができます。

よくある間違い: 複数行データマトリクスにセマンティックなテーブル要素ではなく <div> の羅列を使う

非セマンティックな <div> 要素でグリッドを描画すると、スクリーンリーダーのテーブル読み上げやキーボードでのセル移動が機能しなくなります。

❌ 誤り
<!-- Div soup without semantic table landmarks -->
<div class="row"><div class="col">Node</div><div class="col">Status</div></div>
✅ 正しい例
<!-- Semantic table matrix with headers and data cells -->
<table>
  <thead><tr><th scope="col">Node</th><th scope="col">Status</th></tr></thead>
  <tbody><tr><td>Node 1</td><td>Active</td></tr></tbody>
</table>

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

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

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