タブ Tabs

関連するコンテンツをタブで切り替え表示する。情報の分類・整理に最適。

使用場面: 設定画面やプロフィールページなど複数セクションの切り替え 採用例: Chrome, Notion

ライブデモ

概要

このプロダクトの概要説明です。主要な特徴とメリットを簡潔にまとめています。

ソースコード

<div class="demo-tabs2">
  <div class="demo-tabs2-header" role="tablist" aria-label="タブナビゲーション">
    <button class="demo-tabs2-tab active" role="tab" aria-selected="true" aria-controls="demo-panel-overview" id="demo-tab-overview">概要</button>
    <button class="demo-tabs2-tab" role="tab" aria-selected="false" aria-controls="demo-panel-features" id="demo-tab-features">機能</button>
    <button class="demo-tabs2-tab" role="tab" aria-selected="false" aria-controls="demo-panel-reviews" id="demo-tab-reviews">レビュー</button>
    <div class="demo-tabs2-indicator"></div>
  </div>
  <div class="demo-tabs2-panel active" role="tabpanel" id="demo-panel-overview" aria-labelledby="demo-tab-overview">
    <h4 style="margin:0 0 8px;color:var(--ui-primary);">概要</h4>
    <p style="margin:0;font-size:13px;color:#555;line-height:1.6;">このプロダクトの概要説明です。主要な特徴とメリットを簡潔にまとめています。</p>
  </div>
  <div class="demo-tabs2-panel" role="tabpanel" id="demo-panel-features" aria-labelledby="demo-tab-features" hidden>
    <h4 style="margin:0 0 8px;color:var(--ui-primary);">機能一覧</h4>
    <ul style="margin:0;padding-left:20px;font-size:13px;color:#555;line-height:1.8;">
      <li>リアルタイム同期</li><li>オフライン対応</li><li>多言語サポート</li>
    </ul>
  </div>
  <div class="demo-tabs2-panel" role="tabpanel" id="demo-panel-reviews" aria-labelledby="demo-tab-reviews" hidden>
    <h4 style="margin:0 0 8px;color:var(--ui-primary);">レビュー</h4>
    <p style="margin:0;font-size:13px;color:#555;">★★★★☆ — 使いやすくて満足しています。</p>
  </div>
</div>
.demo-tabs2-header {
  display: flex; position: relative; gap: 0;
  border-bottom: 2px solid #e5e7eb;
}
.demo-tabs2-tab {
  padding: 10px 20px; border: none; background: transparent;
  cursor: pointer; font-size: 14px; font-weight: 600;
  color: #999; transition: color 0.2s; position: relative; z-index: 1;
}
.demo-tabs2-tab:hover { color: #555; }
.demo-tabs2-tab.active { color: var(--ui-primary); }
.demo-tabs2-indicator {
  position: absolute; bottom: -2px; height: 2px;
  background: var(--ui-primary); border-radius: 1px;
  transition: left 0.3s cubic-bezier(0.4,0,0.2,1), width 0.3s cubic-bezier(0.4,0,0.2,1);
}
.demo-tabs2-panel {
  display: none; padding: 20px 4px; animation: demoTabFade 0.3s ease;
}
.demo-tabs2-panel.active { display: block; }
@keyframes demoTabFade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
(function() {
  const header = document.querySelector('.demo-tabs2-header');
  const tabs = header.querySelectorAll('.demo-tabs2-tab');
  const indicator = header.querySelector('.demo-tabs2-indicator');
  const panels = document.querySelectorAll('.demo-tabs2-panel');
  function moveIndicator(tab) {
    indicator.style.left = tab.offsetLeft + 'px';
    indicator.style.width = tab.offsetWidth + 'px';
  }
  moveIndicator(header.querySelector('.demo-tabs2-tab.active'));
  tabs.forEach(tab => {
    tab.addEventListener('click', function() {
      tabs.forEach(t => { t.classList.remove('active'); t.setAttribute('aria-selected', 'false'); });
      panels.forEach(p => { p.classList.remove('active'); p.hidden = true; });
      this.classList.add('active');
      this.setAttribute('aria-selected', 'true');
      const panel = document.getElementById(this.getAttribute('aria-controls'));
      panel.classList.add('active');
      panel.hidden = false;
      moveIndicator(this);
    });
  });
  header.addEventListener('keydown', e => {
    const idx = Array.from(tabs).indexOf(document.activeElement);
    if (idx < 0) return;
    if (e.key === 'ArrowRight') { e.preventDefault(); tabs[(idx + 1) % tabs.length].focus(); tabs[(idx + 1) % tabs.length].click(); }
    if (e.key === 'ArrowLeft') { e.preventDefault(); tabs[(idx - 1 + tabs.length) % tabs.length].focus(); tabs[(idx - 1 + tabs.length) % tabs.length].click(); }
  });
})();

AIプロンプト

Basic
タブUIをHTML/CSSで作ってください。タブヘッダーをクリックすると対応するパネルが切り替わります。
Custom
以下の仕様でタブUIを実装してください。
- スライドするアンダーラインインジケーター
- タブ切り替え時のフェードアニメーション
- プライマリカラー: #2563eb
- アイコン + テキストのタブ
- 縦型タブ(サイドバー型)バリエーションも含む
- タブコンテンツのスクロール可能エリア
Advanced
アクセシビリティ対応のタブUIを実装してください。
- WAI-ARIA Tabs パターン完全準拠
- role="tablist", role="tab", role="tabpanel" を適切に設定
- aria-selected, aria-controls, aria-labelledby を設定
- 矢印キーでタブ移動(自動アクティベーションモード)
- Home/End キーで最初/最後のタブに移動
- prefers-reduced-motion対応
- 動的タブ追加/削除APIとクロースボタン
- URL ハッシュ同期