32 Tailwind CSS Tabs
21 / 32
Pure TailwindMIT licensed

Bracket Selection Tabs in Tailwind CSS

A pair of crimson brackets frames the active word and slides between choices. The original positioned two spans from measured offsets; the port puts both brackets inside one span the width of a column and moves that span — the brackets stay pinned to the cell edges and travel together.

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-21 group/tabs grid min-h-svh w-full place-items-center bg-ttb21-bg px-5 py-14 font-ttb21-serif text-ttb21-paper" aria-label="Bracket selection tabs demo">
  <div class="grid w-full max-w-md justify-items-center gap-8">
    <div role="radiogroup" aria-label="Marker" class="relative grid w-full grid-cols-3 [--i:0] has-[#ttb21-r2:checked]:[--i:1] has-[#ttb21-r3:checked]:[--i:2]">
      <label class="flex min-h-14 cursor-pointer items-center justify-center text-[26px] text-ttb21-mut transition-colors hover:text-ttb21-paper has-checked:text-ttb21-paper has-focus-visible:outline-1 has-focus-visible:-outline-offset-8 has-focus-visible:outline-dashed has-focus-visible:outline-ttb21-paper"><input class="sr-only" type="radio" name="ttb21" id="ttb21-r1" checked>One</label>
      <label class="flex min-h-14 cursor-pointer items-center justify-center text-[26px] text-ttb21-mut transition-colors hover:text-ttb21-paper has-checked:text-ttb21-paper has-focus-visible:outline-1 has-focus-visible:-outline-offset-8 has-focus-visible:outline-dashed has-focus-visible:outline-ttb21-paper"><input class="sr-only" type="radio" name="ttb21" id="ttb21-r2">Two</label>
      <label class="flex min-h-14 cursor-pointer items-center justify-center text-[26px] text-ttb21-mut transition-colors hover:text-ttb21-paper has-checked:text-ttb21-paper has-focus-visible:outline-1 has-focus-visible:-outline-offset-8 has-focus-visible:outline-dashed has-focus-visible:outline-ttb21-paper"><input class="sr-only" type="radio" name="ttb21" id="ttb21-r3">Three</label>
      <span aria-hidden="true" class="pointer-events-none absolute inset-y-0 left-0 flex w-1/3 translate-x-[calc(var(--i)*100%)] items-center justify-between px-1 text-[44px] leading-none font-light text-ttb21-crimson transition-transform duration-500 ease-[cubic-bezier(0.65,0,0.35,1)] motion-reduce:transition-none"><span>[</span><span>]</span></span>
    </div>
    <div class="min-h-6 text-center text-[17px] text-ttb21-soft italic">
      <p class="hidden transition-opacity duration-300 group-has-[#ttb21-r1:checked]/tabs:block starting:opacity-0">The first marker — a beginning.</p>
      <p class="hidden transition-opacity duration-300 group-has-[#ttb21-r2:checked]/tabs:block starting:opacity-0">The second marker — a turn.</p>
      <p class="hidden transition-opacity duration-300 group-has-[#ttb21-r3:checked]/tabs:block starting:opacity-0">The third marker — a close.</p>
    </div>
    <p aria-hidden="true" class="rounded-full border border-white/10 px-3.5 py-2 font-ttb21-mono text-[11.5px] text-ttb21-mut">one frame w-1/3 · justify-between brackets · translate by --i</p>
  </div>
</section>
@import "tailwindcss";

@theme {
  --color-ttb21-bg: #25222e;
  --color-ttb21-bg: oklch(0.261 0.023 296.3);
  --color-ttb21-paper: #ece6d4;
  --color-ttb21-paper: oklch(0.925 0.025 91.6);
  --color-ttb21-soft: #cfc9b8;
  --color-ttb21-soft: oklch(0.836 0.024 90.8);
  --color-ttb21-mut: #a9a395;
  --color-ttb21-mut: oklch(0.717 0.021 87.5);
  --color-ttb21-crimson: #f04a5f;
  --color-ttb21-crimson: oklch(0.649 0.201 17.8);
  --font-ttb21-serif: 'Instrument Serif', Georgia, serif;
  --font-ttb21-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-21 {
  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-ttb21-bg: #25222e;
  --color-ttb21-bg: oklch(0.261 0.023 296.3);
  --color-ttb21-paper: #ece6d4;
  --color-ttb21-paper: oklch(0.925 0.025 91.6);
  --color-ttb21-soft: #cfc9b8;
  --color-ttb21-soft: oklch(0.836 0.024 90.8);
  --color-ttb21-mut: #a9a395;
  --color-ttb21-mut: oklch(0.717 0.021 87.5);
  --color-ttb21-crimson: #f04a5f;
  --color-ttb21-crimson: oklch(0.649 0.201 17.8);
  --font-ttb21-serif: 'Instrument Serif', Georgia, serif;
  --font-ttb21-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-21 {
  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=Instrument+Serif:ital@0;1&family=JetBrains+Mono:wght@400;500&display=swap">

What changed in the port

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

  • Two independently positioned bracket spans (offsetLeft − 20, offsetLeft + offsetWidth + 4) became one column-wide frame with justify-between, moved by translate-x-[calc(var(--i)*100%)].
  • The brackets now animate transform rather than left, so the slide stays on the compositor.
  • UI upgrade from the CSS original: the brackets started stacked at left:0 until JavaScript ran (a visible first-paint glitch); they're correct on first paint now.
  • UI upgrade: crimson brightened to 4.6:1 on the stage (was 3.3:1), resting words raised from 50% to a 6.5:1 token, and panels fade in with starting:.
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: Bracket Selection Tabs in Tailwind CSS
Source: https://codefronts.com/navigation/tailwind-css-tabs/bracket-selection-tabs-tailwind-css/

A pair of crimson brackets frames the active word and slides between choices. The original positioned two spans from measured offsets; the port puts both brackets inside one span the width of a column and moves that span — the brackets stay pinned to the cell edges and travel together.
## HTML
```html
<section class="ttb-21 group/tabs grid min-h-svh w-full place-items-center bg-ttb21-bg px-5 py-14 font-ttb21-serif text-ttb21-paper" aria-label="Bracket selection tabs demo">
  <div class="grid w-full max-w-md justify-items-center gap-8">
    <div role="radiogroup" aria-label="Marker" class="relative grid w-full grid-cols-3 [--i:0] has-[#ttb21-r2:checked]:[--i:1] has-[#ttb21-r3:checked]:[--i:2]">
      <label class="flex min-h-14 cursor-pointer items-center justify-center text-[26px] text-ttb21-mut transition-colors hover:text-ttb21-paper has-checked:text-ttb21-paper has-focus-visible:outline-1 has-focus-visible:-outline-offset-8 has-focus-visible:outline-dashed has-focus-visible:outline-ttb21-paper"><input class="sr-only" type="radio" name="ttb21" id="ttb21-r1" checked>One</label>
      <label class="flex min-h-14 cursor-pointer items-center justify-center text-[26px] text-ttb21-mut transition-colors hover:text-ttb21-paper has-checked:text-ttb21-paper has-focus-visible:outline-1 has-focus-visible:-outline-offset-8 has-focus-visible:outline-dashed has-focus-visible:outline-ttb21-paper"><input class="sr-only" type="radio" name="ttb21" id="ttb21-r2">Two</label>
      <label class="flex min-h-14 cursor-pointer items-center justify-center text-[26px] text-ttb21-mut transition-colors hover:text-ttb21-paper has-checked:text-ttb21-paper has-focus-visible:outline-1 has-focus-visible:-outline-offset-8 has-focus-visible:outline-dashed has-focus-visible:outline-ttb21-paper"><input class="sr-only" type="radio" name="ttb21" id="ttb21-r3">Three</label>
      <span aria-hidden="true" class="pointer-events-none absolute inset-y-0 left-0 flex w-1/3 translate-x-[calc(var(--i)*100%)] items-center justify-between px-1 text-[44px] leading-none font-light text-ttb21-crimson transition-transform duration-500 ease-[cubic-bezier(0.65,0,0.35,1)] motion-reduce:transition-none"><span>[</span><span>]</span></span>
    </div>
    <div class="min-h-6 text-center text-[17px] text-ttb21-soft italic">
      <p class="hidden transition-opacity duration-300 group-has-[#ttb21-r1:checked]/tabs:block starting:opacity-0">The first marker — a beginning.</p>
      <p class="hidden transition-opacity duration-300 group-has-[#ttb21-r2:checked]/tabs:block starting:opacity-0">The second marker — a turn.</p>
      <p class="hidden transition-opacity duration-300 group-has-[#ttb21-r3:checked]/tabs:block starting:opacity-0">The third marker — a close.</p>
    </div>
    <p aria-hidden="true" class="rounded-full border border-white/10 px-3.5 py-2 font-ttb21-mono text-[11.5px] text-ttb21-mut">one frame w-1/3 · justify-between brackets · translate by --i</p>
  </div>
</section>
```
## CSS
```css
@import "tailwindcss";

@theme {
  --color-ttb21-bg: #25222e;
  --color-ttb21-bg: oklch(0.261 0.023 296.3);
  --color-ttb21-paper: #ece6d4;
  --color-ttb21-paper: oklch(0.925 0.025 91.6);
  --color-ttb21-soft: #cfc9b8;
  --color-ttb21-soft: oklch(0.836 0.024 90.8);
  --color-ttb21-mut: #a9a395;
  --color-ttb21-mut: oklch(0.717 0.021 87.5);
  --color-ttb21-crimson: #f04a5f;
  --color-ttb21-crimson: oklch(0.649 0.201 17.8);
  --font-ttb21-serif: 'Instrument Serif', Georgia, serif;
  --font-ttb21-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-21 {
  width: 100%;
  min-height: 100svh;
}
```

How this works

Move the frame, not the marks. Both brackets live in one absolutely positioned span exactly one column wide:

<span class="absolute inset-y-0 left-0 flex w-1/3 justify-between
  translate-x-[calc(var(--i)*100%)] transition-transform">
  <span>[</span><span>]</span>
</span>

That replaces two independent left offsets with one transform and can never desynchronise.

Make it yours

  • Code flavour: braces { } or chevrons ⟨ ⟩.
  • Bold brackets: font-bold on the marks reads as editor UI.
  • Four choices: grid-cols-4 and w-1/4.

Gotchas — read before shipping

  • The brackets are decorative (aria-hidden); selection is announced by the radio.
  • Equal columns are required; long and short words share the same cell width.
  • Short words in wide cells leave air inside the brackets; tighten with px-4 on the frame if needed.

Browser support

ChromeSafariFirefoxEdge
111+16.4+128+111+

:has() drives the index.

Techniques used in this demo

Utilitiesfirst-class utility or variant

Theme tokensset in @theme, used by a utility

Search CodeFronts

Loading…