32 Tailwind CSS Tabs
27 / 32
Pure TailwindMIT licensed

Animated SVG Underline Tabs in Tailwind CSS

Italic slab-serif tabs on cream vellum; the active word gets an emerald swash that draws itself beneath the letters like a calligrapher's flourish. The port normalises the path with pathLength="1", so the draw is exact for any curve, and sets the labels in Zilla Slab italic.

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-27 group/tabs grid min-h-svh w-full place-items-center bg-ttb27-bg px-5 py-14 font-ttb27-slab text-ttb27-ink" aria-label="Animated SVG underline tabs demo">
  <div class="grid w-full max-w-xl justify-items-start gap-7">
    <div role="radiogroup" aria-label="Section" class="flex flex-wrap items-end gap-x-9 gap-y-4">
      <label class="group/tab relative min-h-11 cursor-pointer pb-2 text-[24px] font-bold text-ttb27-mut italic transition-colors hover:text-ttb27-ink has-checked:text-ttb27-ink has-focus-visible:outline-2 has-focus-visible:outline-offset-6 has-focus-visible:outline-ttb27-ink"><input class="sr-only" type="radio" name="ttb27" id="ttb27-r1" checked>Manifesto<svg aria-hidden="true" class="absolute -bottom-2 left-0 h-3.5 w-full overflow-visible" viewBox="0 0 100 14" preserveAspectRatio="none"><path pathLength="1" d="M2 9 Q 22 2 44 7 T 86 6 q 8-1 10 3" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" class="transition-[stroke-dashoffset] duration-700 ease-[cubic-bezier(0.65,0,0.35,1)] [stroke-dasharray:1] [stroke-dashoffset:1] group-has-checked/tab:[stroke-dashoffset:0] motion-reduce:transition-none"/></svg></label>
      <label class="group/tab relative min-h-11 cursor-pointer pb-2 text-[24px] font-bold text-ttb27-mut italic transition-colors hover:text-ttb27-ink has-checked:text-ttb27-ink has-focus-visible:outline-2 has-focus-visible:outline-offset-6 has-focus-visible:outline-ttb27-ink"><input class="sr-only" type="radio" name="ttb27" id="ttb27-r2">Colophon<svg aria-hidden="true" class="absolute -bottom-2 left-0 h-3.5 w-full overflow-visible" viewBox="0 0 100 14" preserveAspectRatio="none"><path pathLength="1" d="M2 9 Q 22 2 44 7 T 86 6 q 8-1 10 3" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" class="transition-[stroke-dashoffset] duration-700 ease-[cubic-bezier(0.65,0,0.35,1)] [stroke-dasharray:1] [stroke-dashoffset:1] group-has-checked/tab:[stroke-dashoffset:0] motion-reduce:transition-none"/></svg></label>
      <label class="group/tab relative min-h-11 cursor-pointer pb-2 text-[24px] font-bold text-ttb27-mut italic transition-colors hover:text-ttb27-ink has-checked:text-ttb27-ink has-focus-visible:outline-2 has-focus-visible:outline-offset-6 has-focus-visible:outline-ttb27-ink"><input class="sr-only" type="radio" name="ttb27" id="ttb27-r3">Errata<svg aria-hidden="true" class="absolute -bottom-2 left-0 h-3.5 w-full overflow-visible" viewBox="0 0 100 14" preserveAspectRatio="none"><path pathLength="1" d="M2 9 Q 22 2 44 7 T 86 6 q 8-1 10 3" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" class="transition-[stroke-dashoffset] duration-700 ease-[cubic-bezier(0.65,0,0.35,1)] [stroke-dasharray:1] [stroke-dashoffset:1] group-has-checked/tab:[stroke-dashoffset:0] motion-reduce:transition-none"/></svg></label>
    </div>
    <div class="max-w-[40ch] pt-2 font-ttb27-serif text-[17px] leading-relaxed text-ttb27-ash italic">
      <p class="hidden group-has-[#ttb27-r1:checked]/tabs:block">The founding statement of intent, set in full measure.</p>
      <p class="hidden group-has-[#ttb27-r2:checked]/tabs:block">The closing inscription: type, paper and press notes.</p>
      <p class="hidden group-has-[#ttb27-r3:checked]/tabs:block">Corrections issued after the first printing.</p>
    </div>
    <p aria-hidden="true" class="rounded-full border border-ttb27-ink/15 bg-white/50 px-3.5 py-2 font-ttb27-mono text-[11.5px] text-ttb27-ash">pathLength="1" · [stroke-dashoffset:1] → 0</p>
  </div>
</section>
@import "tailwindcss";

@theme {
  --color-ttb27-bg: #fbf2d4;
  --color-ttb27-bg: oklch(0.960 0.040 93.2);
  --color-ttb27-ink: #0f4f3d;
  --color-ttb27-ink: oklch(0.383 0.070 169.3);
  --color-ttb27-mut: #4a7a6c;
  --color-ttb27-mut: oklch(0.541 0.057 173.6);
  --color-ttb27-ash: #3a3a42;
  --color-ttb27-ash: oklch(0.352 0.014 285.7);
  --font-ttb27-slab: 'Zilla Slab', Rockwell, serif;
  --font-ttb27-serif: 'Newsreader', Georgia, serif;
  --font-ttb27-mono: 'JetBrains 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-27 {
  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-ttb27-bg: #fbf2d4;
  --color-ttb27-bg: oklch(0.960 0.040 93.2);
  --color-ttb27-ink: #0f4f3d;
  --color-ttb27-ink: oklch(0.383 0.070 169.3);
  --color-ttb27-mut: #4a7a6c;
  --color-ttb27-mut: oklch(0.541 0.057 173.6);
  --color-ttb27-ash: #3a3a42;
  --color-ttb27-ash: oklch(0.352 0.014 285.7);
  --font-ttb27-slab: 'Zilla Slab', Rockwell, serif;
  --font-ttb27-serif: 'Newsreader', Georgia, serif;
  --font-ttb27-mono: 'JetBrains 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-27 {
  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=Zilla+Slab:ital,wght@0,500;1,500;1,700&family=Newsreader:ital,opsz,wght@1,6..72,400..600&family=JetBrains+Mono:wght@400;500&display=swap">

What changed in the port

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

  • stroke-dasharray:100; stroke-dashoffset:100 became pathLength="1" with [stroke-dasharray:1] [stroke-dashoffset:1] — exact for any curve.
  • The inline stroke="#0f4f3d" became stroke="currentColor", so the swash follows the label's colour token.
  • UI upgrade from the CSS original: labels are Zilla Slab italic — a real slab serif, matching the demo's name — at 24px, and the swash ends in a small Spencerian hook.
  • UI upgrade: inactive labels moved from 55% emerald (≈4.0:1) to a 4.9:1 token, and a focus ring was added.
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: Animated SVG Underline Tabs in Tailwind CSS
Source: https://codefronts.com/navigation/tailwind-css-tabs/animated-svg-underline-tabs-tailwind-css/

Italic slab-serif tabs on cream vellum; the active word gets an emerald swash that draws itself beneath the letters like a calligrapher's flourish. The port normalises the path with pathLength="1", so the draw is exact for any curve, and sets the labels in Zilla Slab italic.
## HTML
```html
<section class="ttb-27 group/tabs grid min-h-svh w-full place-items-center bg-ttb27-bg px-5 py-14 font-ttb27-slab text-ttb27-ink" aria-label="Animated SVG underline tabs demo">
  <div class="grid w-full max-w-xl justify-items-start gap-7">
    <div role="radiogroup" aria-label="Section" class="flex flex-wrap items-end gap-x-9 gap-y-4">
      <label class="group/tab relative min-h-11 cursor-pointer pb-2 text-[24px] font-bold text-ttb27-mut italic transition-colors hover:text-ttb27-ink has-checked:text-ttb27-ink has-focus-visible:outline-2 has-focus-visible:outline-offset-6 has-focus-visible:outline-ttb27-ink"><input class="sr-only" type="radio" name="ttb27" id="ttb27-r1" checked>Manifesto<svg aria-hidden="true" class="absolute -bottom-2 left-0 h-3.5 w-full overflow-visible" viewBox="0 0 100 14" preserveAspectRatio="none"><path pathLength="1" d="M2 9 Q 22 2 44 7 T 86 6 q 8-1 10 3" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" class="transition-[stroke-dashoffset] duration-700 ease-[cubic-bezier(0.65,0,0.35,1)] [stroke-dasharray:1] [stroke-dashoffset:1] group-has-checked/tab:[stroke-dashoffset:0] motion-reduce:transition-none"/></svg></label>
      <label class="group/tab relative min-h-11 cursor-pointer pb-2 text-[24px] font-bold text-ttb27-mut italic transition-colors hover:text-ttb27-ink has-checked:text-ttb27-ink has-focus-visible:outline-2 has-focus-visible:outline-offset-6 has-focus-visible:outline-ttb27-ink"><input class="sr-only" type="radio" name="ttb27" id="ttb27-r2">Colophon<svg aria-hidden="true" class="absolute -bottom-2 left-0 h-3.5 w-full overflow-visible" viewBox="0 0 100 14" preserveAspectRatio="none"><path pathLength="1" d="M2 9 Q 22 2 44 7 T 86 6 q 8-1 10 3" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" class="transition-[stroke-dashoffset] duration-700 ease-[cubic-bezier(0.65,0,0.35,1)] [stroke-dasharray:1] [stroke-dashoffset:1] group-has-checked/tab:[stroke-dashoffset:0] motion-reduce:transition-none"/></svg></label>
      <label class="group/tab relative min-h-11 cursor-pointer pb-2 text-[24px] font-bold text-ttb27-mut italic transition-colors hover:text-ttb27-ink has-checked:text-ttb27-ink has-focus-visible:outline-2 has-focus-visible:outline-offset-6 has-focus-visible:outline-ttb27-ink"><input class="sr-only" type="radio" name="ttb27" id="ttb27-r3">Errata<svg aria-hidden="true" class="absolute -bottom-2 left-0 h-3.5 w-full overflow-visible" viewBox="0 0 100 14" preserveAspectRatio="none"><path pathLength="1" d="M2 9 Q 22 2 44 7 T 86 6 q 8-1 10 3" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" class="transition-[stroke-dashoffset] duration-700 ease-[cubic-bezier(0.65,0,0.35,1)] [stroke-dasharray:1] [stroke-dashoffset:1] group-has-checked/tab:[stroke-dashoffset:0] motion-reduce:transition-none"/></svg></label>
    </div>
    <div class="max-w-[40ch] pt-2 font-ttb27-serif text-[17px] leading-relaxed text-ttb27-ash italic">
      <p class="hidden group-has-[#ttb27-r1:checked]/tabs:block">The founding statement of intent, set in full measure.</p>
      <p class="hidden group-has-[#ttb27-r2:checked]/tabs:block">The closing inscription: type, paper and press notes.</p>
      <p class="hidden group-has-[#ttb27-r3:checked]/tabs:block">Corrections issued after the first printing.</p>
    </div>
    <p aria-hidden="true" class="rounded-full border border-ttb27-ink/15 bg-white/50 px-3.5 py-2 font-ttb27-mono text-[11.5px] text-ttb27-ash">pathLength="1" · [stroke-dashoffset:1] → 0</p>
  </div>
</section>
```
## CSS
```css
@import "tailwindcss";

@theme {
  --color-ttb27-bg: #fbf2d4;
  --color-ttb27-bg: oklch(0.960 0.040 93.2);
  --color-ttb27-ink: #0f4f3d;
  --color-ttb27-ink: oklch(0.383 0.070 169.3);
  --color-ttb27-mut: #4a7a6c;
  --color-ttb27-mut: oklch(0.541 0.057 173.6);
  --color-ttb27-ash: #3a3a42;
  --color-ttb27-ash: oklch(0.352 0.014 285.7);
  --font-ttb27-slab: 'Zilla Slab', Rockwell, serif;
  --font-ttb27-serif: 'Newsreader', Georgia, serif;
  --font-ttb27-mono: 'JetBrains 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-27 {
  width: 100%;
  min-height: 100svh;
}
```

How this works

Normalise the path. The original used stroke-dasharray:100, a guess at the curve's length; redraw the swash and the animation would stop short. With pathLength="1" the browser rescales the path to length 1:

<path pathLength="1" d="M2 9 Q 22 2 44 7 T 86 6 q 8-1 10 3"
  class="[stroke-dasharray:1] [stroke-dashoffset:1]
    transition-[stroke-dashoffset] duration-700
    group-has-checked/tab:[stroke-dashoffset:0]"/>

The dash is exactly one path long, the gap exactly one path long, and sliding the offset from 1 to 0 draws the whole stroke for any shape.

Make it yours

  • Redraw d freely — pathLength keeps the draw correct.
  • Oxblood ink: --color-ttb27-ink: #5c1a2b.
  • Draw on hover too: add group-hover/tab:[stroke-dashoffset:0.6].

Gotchas — read before shipping

  • preserveAspectRatio="none" stretches the stroke width with the word; keep it modest.
  • The SVG is decorative (aria-hidden).
  • Undrawing (on deselect) uses the same duration; shorten it with a separate rule if you want a snappier exit.

Browser support

ChromeSafariFirefoxEdge
111+16.4+128+111+

pathLength is universal in SVG 2 engines.

Techniques used in this demo

Utilitiesfirst-class utility or variant

Search CodeFronts

Loading…