{
  "id": "sliding-underline-tabs",
  "name": "Sliding Underline Tabs",
  "category": "navigation",
  "tags": [
    "tabs",
    "animated",
    "indicator",
    "radio",
    "has"
  ],
  "description": "Equal-width tabs with one underline that slides to the selected tab, driven by :has() and a custom property.",
  "url": "https://copy-css.com/snippets/sliding-underline-tabs",
  "markdown": "https://copy-css.com/snippets/sliding-underline-tabs.md",
  "html": "<div class=\"slide-tabs\">\n  <div class=\"slide-tabs-list\" role=\"radiogroup\" aria-label=\"Period\">\n    <label><input type=\"radio\" name=\"slide-tabs\" checked>Day</label>\n    <label><input type=\"radio\" name=\"slide-tabs\">Week</label>\n    <label><input type=\"radio\" name=\"slide-tabs\">Month</label>\n  </div>\n  <div class=\"slide-tabs-panels\">\n    <p>1,284 visits today</p>\n    <p>8,930 visits this week</p>\n    <p>36,512 visits this month</p>\n  </div>\n</div>",
  "css": ".slide-tabs {\n  width: 250px;\n  font: 14px/1.5 system-ui, sans-serif;\n}\n\n.slide-tabs-list {\n  --i: 0;\n  position: relative;\n  display: grid;\n  grid-auto-columns: 1fr;\n  grid-auto-flow: column;\n  border-bottom: 1px solid #e5e7eb;\n}\n\n/* One indicator, moved by --i */\n.slide-tabs-list::after {\n  content: \"\";\n  position: absolute;\n  bottom: -1px;\n  left: 0;\n  width: calc(100% / 3);\n  height: 2px;\n  border-radius: 2px;\n  background: #0284c7;\n  transform: translateX(calc(var(--i) * 100%));\n  transition: transform 0.3s cubic-bezier(0.3, 0.7, 0.4, 1);\n}\n\n.slide-tabs-list:has(label:nth-child(2) input:checked) {\n  --i: 1;\n}\n\n.slide-tabs-list:has(label:nth-child(3) input:checked) {\n  --i: 2;\n}\n\n.slide-tabs-list label {\n  padding: 10px 0;\n  color: #6b7280;\n  font-weight: 600;\n  text-align: center;\n  cursor: pointer;\n  transition: color 0.2s ease;\n}\n\n.slide-tabs-list input {\n  position: absolute;\n  opacity: 0;\n  pointer-events: none;\n}\n\n.slide-tabs-list label:has(input:checked) {\n  color: #0284c7;\n}\n\n.slide-tabs-list label:has(input:focus-visible) {\n  border-radius: 6px;\n  outline: 2px solid #0284c7;\n  outline-offset: -2px;\n}\n\n.slide-tabs-panels p {\n  display: none;\n  margin: 0;\n  padding: 14px 2px;\n  color: #111827;\n  font-size: 18px;\n  font-weight: 700;\n}\n\n.slide-tabs:has(label:nth-child(1) input:checked) .slide-tabs-panels > :nth-child(1),\n.slide-tabs:has(label:nth-child(2) input:checked) .slide-tabs-panels > :nth-child(2),\n.slide-tabs:has(label:nth-child(3) input:checked) .slide-tabs-panels > :nth-child(3) {\n  display: block;\n}\n\n@media (prefers-reduced-motion: reduce) {\n  .slide-tabs-list::after { transition: none; }\n}",
  "features": [
    "transitions",
    "transforms",
    "CSS Grid",
    "the :has() selector",
    "the :checked state (no JavaScript)",
    "keyboard focus styles",
    "custom properties",
    "reduced-motion support"
  ],
  "customProperties": [
    {
      "name": "--i",
      "value": "0"
    }
  ]
}
