Skip to content

Install command tabs in HTML and CSS

A dark code block with one tab per package manager, for technical documentation.

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 de commandes d'installation</title>
    <link rel="stylesheet" href="style.css" />
  </head>
  <body>
    <main class="demo">
      <div class="ctabs" data-tabs>
        <div class="ctabs__list" role="tablist" aria-label="Gestionnaire de paquets" hidden>
style.css
:root {
  --ct-bg: #11141b;
  --ct-bar: #1a1e28;
  --ct-text: #e8ebf2;
  --ct-muted: #9aa3b5;
  --ct-active: #e8ebf2;
  --ct-accent: #7dd3fc;
  --ct-prompt: #7d8597;
  --ct-ring: #7dd3fc;
  --demo-bg: #eef0f4;
  --demo-text: #11141b;
}
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
  • Understated tabs with an underlined active tab, to organize the information on a product page.

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

    • Tailwind
    • React
    • CSS
    • WordPress
    Component