Skip to content

shadcn.io is an independent project built on shadcn/ui

Horizontal Radio Group for Svelte

Option 1, Option 2 and Option 3 in a single row. Option 1 starts selected, and each label sits beside its radio.

UI library: Ark UI

Option 1, Option 2 and Option 3 sit on one line, each with a radio and a label. Option 1 starts selected.

Use a row for a short choice that should not take vertical space. Stack the options, or use a Select, when the labels get long. In Svelte, Ark UI does not wrap the row.

Preview

Preview width

Installation

MCP · Pro
Make your AI a shadcn expert
Your agent installs components, builds pages and restyles your app from one prompt, in Claude Code, Cursor or VS Code.
Part of Pro

Anatomy

Radio Group anatomy: root, label, item control, indicator, item, item text

Usage

<RadioGroup class="flex w-fit flex-row flex-wrap gap-4" defaultValue="option-1" orientation="horizontal"><RadioGroupItem value="option-1">Option 1</RadioGroupItem><RadioGroupItem value="option-2">Option 2</RadioGroupItem><RadioGroupItem value="option-3">Option 3</RadioGroupItem></RadioGroup>

FAQ

How are the options placed in a row?

RadioGroup takes flex flex-row flex-wrap gap-4, which replaces its default grid. defaultValue is option-1.

How do I start on a different option?

Change defaultValue to option-2 or option-3, matching that item's value.

Why does the label text select the radio?

The text is the item's label, so clicking it checks that item. The text is the child of RadioGroupItem, which renders it as the item's label.

What if the labels get too long for one row?

flex-wrap moves the options that do not fit onto the next line. For more than four options, or long labels, a vertical group reads faster.

How do I control the selected value?

This demo uses defaultValue, so the group stores the choice. Pass value, and onValueChange receives details.value.

Do the arrow keys still move across a horizontal group?

Yes. Tab moves focus to the checked item, and the arrow keys move to the next or previous item and check it, in the order of the row. orientation is horizontal on RadioGroup, which tells assistive tech the options run across.

API Reference

Radio Group

Sets defaultValue="option-1", orientation="horizontal", value="option-1", value="option-2" and value="option-3". The rest is on the Radio Group page.