Skip to content

Underlined tabs in HTML and CSS

Understated tabs with an underlined active tab, to organize the information on a product page.

Here is an excerpt of this component's code in HTML and CSS. The full code is free for members, ready to copy into your project.

This component also comes in

Open in a new tab

The code in HTML and CSS

index.html
<!doctype html>
<html lang="fr">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Onglets soulignés</title>
    <link rel="stylesheet" href="style.css" />
  </head>
  <body>
    <main class="demo">
      <div class="utabs" data-tabs>
        <div class="utabs__list" role="tablist" aria-label="Informations sur le produit" hidden>
style.css
:root {
  --ut-text: #0b1b3a;
  --ut-muted: #46577a;
  --ut-line: #d6e0f5;
  --ut-active: #1d4ed8;
  --ut-ring: #1d4ed8;
  --demo-bg: #f8faff;
  --demo-text: #0b1b3a;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
tabs.js
document.querySelectorAll("[data-tabs]").forEach((root) => {
  const list = root.querySelector('[role="tablist"]');
  const tabs = [...list.querySelectorAll('[role="tab"]')];
  const panels = tabs.map((tab) => document.getElementById(tab.getAttribute("aria-controls")));
  const vertical = list.getAttribute("aria-orientation") === "vertical";

  function select(index, focus) {
    tabs.forEach((tab, position) => {
      const selected = position === index;
      tab.setAttribute("aria-selected", String(selected));
      tab.tabIndex = selected ? 0 : -1;
      panels[position].hidden = !selected;

Free component: copy it freely, including for commercial projects.

Tabs components in HTML and CSS
  • Accessible tabs on large screens that turn into an accordion on phones, with the right ARIA roles in each mode.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • Indicative prices sorted by trade in tabs, with the unit of each service, a VAT-inclusive / excl. switch and a free-quote notice.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • Two tabs to show different opening hours by season, in a compact card.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • A dark code block with one tab per package manager, for technical documentation.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component