32 Tailwind CSS Tabs
17 / 32
Pure TailwindMIT licensed

Variable Font Weight Tabs in Tailwind CSS

Pure type-weight contrast: inactive labels are 200 hairline, the active one dials up to 900 black on Geist's variable axis while a violet rule draws in. The port fixes the original's layout jitter — bolding a word makes it wider and shoved its neighbours — by reserving each label's black-weight width with an invisible twin.

Live Demo
Plain CSSTailwind v4
Try it

Untitled UI Pro: 5,000+ React + Tailwind CSS v4 components · from $349 one-time

Untitled UI React · Affiliate link

Get Untitled UI Pro

The code

<section class="ttb-17 group/tabs grid min-h-svh w-full place-items-center bg-ttb17-bg px-5 py-14 font-ttb17-sans text-ttb17-paper" aria-label="Variable font weight tabs demo">
  <div class="grid w-full max-w-xl justify-items-start gap-7">
    <div role="radiogroup" aria-label="Project section" class="flex flex-wrap gap-x-8 gap-y-3">
      <label class="group/tab relative cursor-pointer pb-2.5 text-[28px] leading-none font-extralight tracking-[-0.02em] transition-[font-weight] duration-500 after:absolute after:inset-x-0 after:bottom-0 after:h-0.5 after:origin-left after:scale-x-0 after:bg-ttb17-acc after:transition-transform after:duration-500 after:ease-[cubic-bezier(0.65,0,0.35,1)] hover:font-normal has-checked:font-black has-checked:after:scale-x-100 has-focus-visible:outline-2 has-focus-visible:outline-offset-4 has-focus-visible:outline-ttb17-acc motion-reduce:transition-none motion-reduce:after:transition-none"><input class="sr-only" type="radio" name="ttb17" id="ttb17-r1" checked><span class="grid [&>*]:[grid-area:1/1]"><span>Overview</span><span aria-hidden="true" class="invisible font-black">Overview</span></span></label>
      <label class="group/tab relative cursor-pointer pb-2.5 text-[28px] leading-none font-extralight tracking-[-0.02em] transition-[font-weight] duration-500 after:absolute after:inset-x-0 after:bottom-0 after:h-0.5 after:origin-left after:scale-x-0 after:bg-ttb17-acc after:transition-transform after:duration-500 after:ease-[cubic-bezier(0.65,0,0.35,1)] hover:font-normal has-checked:font-black has-checked:after:scale-x-100 has-focus-visible:outline-2 has-focus-visible:outline-offset-4 has-focus-visible:outline-ttb17-acc motion-reduce:transition-none motion-reduce:after:transition-none"><input class="sr-only" type="radio" name="ttb17" id="ttb17-r2"><span class="grid [&>*]:[grid-area:1/1]"><span>Activity</span><span aria-hidden="true" class="invisible font-black">Activity</span></span></label>
      <label class="group/tab relative cursor-pointer pb-2.5 text-[28px] leading-none font-extralight tracking-[-0.02em] transition-[font-weight] duration-500 after:absolute after:inset-x-0 after:bottom-0 after:h-0.5 after:origin-left after:scale-x-0 after:bg-ttb17-acc after:transition-transform after:duration-500 after:ease-[cubic-bezier(0.65,0,0.35,1)] hover:font-normal has-checked:font-black has-checked:after:scale-x-100 has-focus-visible:outline-2 has-focus-visible:outline-offset-4 has-focus-visible:outline-ttb17-acc motion-reduce:transition-none motion-reduce:after:transition-none"><input class="sr-only" type="radio" name="ttb17" id="ttb17-r3"><span class="grid [&>*]:[grid-area:1/1]"><span>Settings</span><span aria-hidden="true" class="invisible font-black">Settings</span></span></label>
    </div>
    <div class="max-w-[42ch] font-ttb17-serif text-[16px] leading-relaxed text-ttb17-mut">
      <p class="hidden group-has-[#ttb17-r1:checked]/tabs:block">A summary of the project, its members and the decisions made so far.</p>
      <p class="hidden group-has-[#ttb17-r2:checked]/tabs:block">Edits, comments and team mentions over the last seven days.</p>
      <p class="hidden group-has-[#ttb17-r3:checked]/tabs:block">Permissions, integrations and billing controls.</p>
    </div>
    <p aria-hidden="true" class="rounded-full border border-white/10 px-3.5 py-2 font-ttb17-mono text-[11.5px] text-ttb17-mut">font-extralight → font-black · invisible twin = 0 CLS</p>
  </div>
</section>
@import "tailwindcss";

@theme {
  --color-ttb17-bg: #14141c;
  --color-ttb17-bg: oklch(0.195 0.016 284.8);
  --color-ttb17-paper: #ece6d4;
  --color-ttb17-paper: oklch(0.925 0.025 91.6);
  --color-ttb17-mut: #b0aa9b;
  --color-ttb17-mut: oklch(0.739 0.022 88.8);
  --color-ttb17-acc: #8b6dff;
  --color-ttb17-acc: oklch(0.638 0.208 288.5);
  --font-ttb17-sans: 'Geist', system-ui, sans-serif;
  --font-ttb17-serif: 'Newsreader', Georgia, serif;
  --font-ttb17-mono: 'Geist Mono', ui-monospace, monospace;
}
/* Root rule: the full-bleed contract, stated in CSS as well as in the markup's utilities, so the
   stage is sized before the browser build compiles. */

.ttb-17 {
  width: 100%;
  min-height: 100svh;
}

Setup — do this once per project

Skip this if your project already runs Tailwind v4.

1Load Tailwind
<script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script>

Compiles in the browser — perfect for a CodePen or a quick test, not for production.

2Add the stylesheetRequiredthe @theme block is what makes the custom utilities exist
@import "tailwindcss";

@theme {
  --color-ttb17-bg: #14141c;
  --color-ttb17-bg: oklch(0.195 0.016 284.8);
  --color-ttb17-paper: #ece6d4;
  --color-ttb17-paper: oklch(0.925 0.025 91.6);
  --color-ttb17-mut: #b0aa9b;
  --color-ttb17-mut: oklch(0.739 0.022 88.8);
  --color-ttb17-acc: #8b6dff;
  --color-ttb17-acc: oklch(0.638 0.208 288.5);
  --font-ttb17-sans: 'Geist', system-ui, sans-serif;
  --font-ttb17-serif: 'Newsreader', Georgia, serif;
  --font-ttb17-mono: 'Geist Mono', ui-monospace, monospace;
}
/* Root rule: the full-bleed contract, stated in CSS as well as in the markup's utilities, so the
   stage is sized before the browser build compiles. */

.ttb-17 {
  width: 100%;
  min-height: 100svh;
}
3Fonts used by this demooptional — skip if you have your own type stack
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Geist:wght@100..900&family=Newsreader:ital,opsz,wght@0,6..72,400..600;1,6..72,400..600&family=Geist+Mono:wght@400..600&display=swap">

What changed in the port

Which parts became utilities, which stayed CSS, and why.

  • font-weight plus font-variation-settings:"wght" collapsed to font-extralight / has-checked:font-black — with a real variable font loaded, the weight utility alone animates the axis.
  • The ::after rule became after:scale-x-0 has-checked:after:scale-x-100.
  • UI upgrade from the CSS original: bug fix — bolding the active label widened it and pushed every later tab sideways on each click; an invisible font-black twin in the same grid cell now reserves the final width (zero layout shift).
  • UI upgrade: the font is Geist with a true 100–900 axis (the original relied on whatever ui-sans-serif resolved to, usually not variable), plus a keyboard focus ring.
Paste this into ChatGPT, Claude, Cursor, or any coding assistant. The block below is pre-framed with everything the AI needs to integrate this demo into your project — markup, styles, scoping notes, and the source URL. Hit Copy and paste straight into your chat.
Here's a working CSS demo from CodeFronts. Use it as-is or adapt to your framework. All classes are scoped under a unique prefix so the code won't collide with your existing styles. MIT licensed.
Demo: Variable Font Weight Tabs in Tailwind CSS
Source: https://codefronts.com/navigation/tailwind-css-tabs/variable-font-weight-tabs-tailwind-css/

Pure type-weight contrast: inactive labels are 200 hairline, the active one dials up to 900 black on Geist's variable axis while a violet rule draws in. The port fixes the original's layout jitter — bolding a word makes it wider and shoved its neighbours — by reserving each label's black-weight width with an invisible twin.
## HTML
```html
<section class="ttb-17 group/tabs grid min-h-svh w-full place-items-center bg-ttb17-bg px-5 py-14 font-ttb17-sans text-ttb17-paper" aria-label="Variable font weight tabs demo">
  <div class="grid w-full max-w-xl justify-items-start gap-7">
    <div role="radiogroup" aria-label="Project section" class="flex flex-wrap gap-x-8 gap-y-3">
      <label class="group/tab relative cursor-pointer pb-2.5 text-[28px] leading-none font-extralight tracking-[-0.02em] transition-[font-weight] duration-500 after:absolute after:inset-x-0 after:bottom-0 after:h-0.5 after:origin-left after:scale-x-0 after:bg-ttb17-acc after:transition-transform after:duration-500 after:ease-[cubic-bezier(0.65,0,0.35,1)] hover:font-normal has-checked:font-black has-checked:after:scale-x-100 has-focus-visible:outline-2 has-focus-visible:outline-offset-4 has-focus-visible:outline-ttb17-acc motion-reduce:transition-none motion-reduce:after:transition-none"><input class="sr-only" type="radio" name="ttb17" id="ttb17-r1" checked><span class="grid [&>*]:[grid-area:1/1]"><span>Overview</span><span aria-hidden="true" class="invisible font-black">Overview</span></span></label>
      <label class="group/tab relative cursor-pointer pb-2.5 text-[28px] leading-none font-extralight tracking-[-0.02em] transition-[font-weight] duration-500 after:absolute after:inset-x-0 after:bottom-0 after:h-0.5 after:origin-left after:scale-x-0 after:bg-ttb17-acc after:transition-transform after:duration-500 after:ease-[cubic-bezier(0.65,0,0.35,1)] hover:font-normal has-checked:font-black has-checked:after:scale-x-100 has-focus-visible:outline-2 has-focus-visible:outline-offset-4 has-focus-visible:outline-ttb17-acc motion-reduce:transition-none motion-reduce:after:transition-none"><input class="sr-only" type="radio" name="ttb17" id="ttb17-r2"><span class="grid [&>*]:[grid-area:1/1]"><span>Activity</span><span aria-hidden="true" class="invisible font-black">Activity</span></span></label>
      <label class="group/tab relative cursor-pointer pb-2.5 text-[28px] leading-none font-extralight tracking-[-0.02em] transition-[font-weight] duration-500 after:absolute after:inset-x-0 after:bottom-0 after:h-0.5 after:origin-left after:scale-x-0 after:bg-ttb17-acc after:transition-transform after:duration-500 after:ease-[cubic-bezier(0.65,0,0.35,1)] hover:font-normal has-checked:font-black has-checked:after:scale-x-100 has-focus-visible:outline-2 has-focus-visible:outline-offset-4 has-focus-visible:outline-ttb17-acc motion-reduce:transition-none motion-reduce:after:transition-none"><input class="sr-only" type="radio" name="ttb17" id="ttb17-r3"><span class="grid [&>*]:[grid-area:1/1]"><span>Settings</span><span aria-hidden="true" class="invisible font-black">Settings</span></span></label>
    </div>
    <div class="max-w-[42ch] font-ttb17-serif text-[16px] leading-relaxed text-ttb17-mut">
      <p class="hidden group-has-[#ttb17-r1:checked]/tabs:block">A summary of the project, its members and the decisions made so far.</p>
      <p class="hidden group-has-[#ttb17-r2:checked]/tabs:block">Edits, comments and team mentions over the last seven days.</p>
      <p class="hidden group-has-[#ttb17-r3:checked]/tabs:block">Permissions, integrations and billing controls.</p>
    </div>
    <p aria-hidden="true" class="rounded-full border border-white/10 px-3.5 py-2 font-ttb17-mono text-[11.5px] text-ttb17-mut">font-extralight → font-black · invisible twin = 0 CLS</p>
  </div>
</section>
```
## CSS
```css
@import "tailwindcss";

@theme {
  --color-ttb17-bg: #14141c;
  --color-ttb17-bg: oklch(0.195 0.016 284.8);
  --color-ttb17-paper: #ece6d4;
  --color-ttb17-paper: oklch(0.925 0.025 91.6);
  --color-ttb17-mut: #b0aa9b;
  --color-ttb17-mut: oklch(0.739 0.022 88.8);
  --color-ttb17-acc: #8b6dff;
  --color-ttb17-acc: oklch(0.638 0.208 288.5);
  --font-ttb17-sans: 'Geist', system-ui, sans-serif;
  --font-ttb17-serif: 'Newsreader', Georgia, serif;
  --font-ttb17-mono: 'Geist Mono', ui-monospace, monospace;
}
/* Root rule: the full-bleed contract, stated in CSS as well as in the markup's utilities, so the
   stage is sized before the browser build compiles. */

.ttb-17 {
  width: 100%;
  min-height: 100svh;
}
```

How this works

Bold text is wider text. Animating 200 → 900 widens the word by ~15%, so every tab to its right slides on each click. The fix is to size the cell for the heaviest state up front:

<span class="grid [&>*]:[grid-area:1/1]">
  <span>Overview</span>
  <span aria-hidden="true" class="invisible font-black">Overview</span>
</span>

Both copies share one grid cell; the invisible black copy sets the width, the visible one animates freely inside it. Geist ships a true 100–900 wght axis, so the transition is a smooth dial rather than a snap.

Make it yours

  • Softer contrast: font-light → font-extrabold keeps inactive labels more legible.
  • Serif version: Fraunces also has a full weight axis.
  • Recolour the rule via --color-ttb17-acc.

Gotchas — read before shipping

  • A static (non-variable) font snaps between weights — still correct, just not animated.
  • Keep the invisible twin's text identical to the visible label or the cell sizes wrong.
  • 200-weight text needs a large size and high contrast; it's 26px on a near-black stage here.

Browser support

ChromeSafariFirefoxEdge
111+16.4+128+111+

Font-weight interpolation on variable fonts is universal in evergreen engines.

Techniques used in this demo

Utilitiesfirst-class utility or variant

Search CodeFronts

Loading…