Pill Radio Group

Segmented radio pills using peer-checked.

Tailwind CSS
<div class="inline-flex rounded-xl border border-slate-200 p-1 gap-1">
  <label class="cursor-pointer">
    <input type="radio" name="size" class="peer sr-only" checked />
    <span class="block px-4 py-1.5 rounded-lg text-sm font-semibold text-slate-500 dark:text-slate-400 peer-checked:bg-slate-900 peer-checked:text-white transition-colors">S</span>
  </label>
  <label class="cursor-pointer">
    <input type="radio" name="size" class="peer sr-only" />
    <span class="block px-4 py-1.5 rounded-lg text-sm font-semibold text-slate-500 dark:text-slate-400 peer-checked:bg-slate-900 peer-checked:text-white transition-colors">M</span>
  </label>
  <label class="cursor-pointer">
    <input type="radio" name="size" class="peer sr-only" />
    <span class="block px-4 py-1.5 rounded-lg text-sm font-semibold text-slate-500 dark:text-slate-400 peer-checked:bg-slate-900 peer-checked:text-white transition-colors">L</span>
  </label>
</div>

Free to use in personal and commercial projects. No attribution required.

Variants

Same component, different looks. Preview each one live and copy the code you like.

Indigo active

Brand color active state instead of black for colorful interfaces.

Tailwind CSS

Billing period

Billing period switcher, the classic use case for segmented controls.

Tailwind CSS

Four sizes

Four option layout for size pickers in clothing and product pages.

Tailwind CSS

About this pill radio group

Pill radios are the segmented choice: S/M/L sizes, monthly/yearly billing, list/grid view. They look like tabs but behave like radios: one selection, mutually exclusive. This one uses native radio inputs with peer-checked for the selected state.

The pattern is three labels each containing a hidden radio and a styled span. The checked radio's sibling span gets the dark background. Native radios mean keyboard navigation and form submission work for free.

Use pill radios for 2-4 mutually exclusive options with short labels. More options deserve a dropdown. The labels must be short; 'Extra Large' breaks the pill aesthetic.

Some choices are too important for a dropdown, which hides the options, but too small for their own screen: billing period, size, view mode. Nobody should have to open a menu just to see two or three options. Pill radios lay every choice bare in one glanceable strip, turning open-scan-select into a single tap. The options do the persuading; the control just gets out of the way.

Each option is a label wrapping an sr-only radio input and a styled span, with all inputs sharing one name (size). The checked input's sibling span takes peer-checked:bg-slate-900 peer-checked:text-white. Because the inputs are native radios, mutual exclusivity, arrow-key navigation, and form submission work with no JavaScript at all; the pills are pure costume.

For two options, widen the pills (px-6) so the strip feels balanced rather than sparse. Add small icons before the labels for view toggles like list/grid, where the glyph explains faster than words. Swap the selected background to the brand color, but keep unselected labels muted so the current choice reads instantly.

The mistake is letting the pills overflow on small screens until labels truncate into Monthl... The pattern exists to expose every option, and truncation hides the very thing it is for. Give the strip overflow-x-auto with no wrapping, or let it wrap to two rows on narrow viewports. Option labels must always render in full, or the control fails its single job.

Where to use it

  • ✓ Size selectors
  • ✓ View toggles
  • ✓ Billing periods
  • ✓ Filter options

Customization tips

For binary choices, two pills suffice. Add icons inside pills for view toggles (list/grid). The dark selected state can use your brand color instead of slate-900.

Design notes

When to use

Use it for two to four mutually exclusive options with short labels: size selectors like S M L, monthly versus yearly billing, or list versus grid views. Native radio inputs make keyboard navigation and form submission work with no extra code. It looks like tabs but behaves like a proper choice.

What to avoid

Do not use it for more than four options; a long pill row overflows and a dropdown serves better. Do not use long labels like Extra Large, which break the compact pill aesthetic.

Accessibility

Native radios give screen readers the selected state for free. Wrap the group in a fieldset with a legend so the question being answered is announced, not just the options.

Frequently asked questions

Pill radios vs tabs, what is the difference?

Pill radios are form inputs (mutually exclusive selection submitted with a form). Tabs switch content panels. They look similar but serve different purposes.

How do pill radios work without JavaScript?

Native radio inputs with the same name are mutually exclusive by default. The peer-checked: variant styles the selected pill. No script needed.

How many options can pill radios have?

Two to four. More options make pills cramped; use a dropdown or listbox instead.

How do I style a radio button as a pill with CSS?

Hide the native input visually with opacity and absolute positioning, style the label as a pill, and use input:checked + span to recolor the selected pill. This element shows the pattern: the checked pill gets the brand background while the input stays in the DOM for keyboard and screen reader support.

Why can I select multiple pill radios at once?

The inputs are missing a shared name attribute. Radios only behave as a single-choice group when every input in the set has the same name. Give them all name='plan' or similar, and the browser enforces one selection automatically with full keyboard arrow-key support.

How do I make the selected pill slide like an iOS segmented control?

Add one absolutely positioned highlight element behind the pills and move it with a :has() selector that reads which input is checked, translating the highlight to the active segment. The simpler approach is styling each checked pill directly, which this element does and which works in every browser without :has() support.

Customize it with our tools