
# Radio



> Radio component allows users to choose a single option from a predefined set of options. To allow multiple choices, use the Checkbox component instead.

## Examples

### Default

```tsx
import { Fieldset, Radio } from "@kesko/components";

export default () => (
  <Fieldset label="Delivery method">
    <Radio label="Home delivery" name="delivery" value="home" defaultChecked />
    <Radio label="Pickup from store" name="delivery" value="pickup" />
    <Radio label="Parcel locker" name="delivery" value="locker" />
  </Fieldset>
);

```

```html
<fieldset class="k-fieldset">
  <legend class="k-fieldset-legend">Delivery method</legend>
  <k-radio>
    <input type="radio" id="home" name="delivery" value="home" checked />
    <label for="home">Home delivery</label>
  </k-radio>
  <k-radio>
    <input type="radio" id="pickup" name="delivery" value="pickup" />
    <label for="pickup">Pickup from store</label>
  </k-radio>
  <k-radio>
    <input type="radio" id="locker" name="delivery" value="locker" />
    <label for="locker">Parcel locker</label>
  </k-radio>
</fieldset>
```

### Assistive text

```tsx
import { Fieldset, Radio } from "@kesko/components";

export default () => (
  <Fieldset label="Delivery method">
    <Radio label="Home delivery" name="delivery" value="home" description="9,90 € · Tomorrow between 8 and 21" />
    <Radio label="Pickup from store" name="delivery" value="pickup" description="Free · Ready in 2 hours" defaultChecked />
    <Radio label="Parcel locker" name="delivery" value="locker" description="4,90 € · In 1 to 3 days" />
  </Fieldset>
);

```

```html
<fieldset class="k-fieldset" aria-describedby="delivery-description">
  <legend class="k-fieldset-legend">Delivery method</legend>
  <k-radio>
    <input type="radio" id="home" name="delivery" value="home" aria-describedby="home-description" />
    <label for="home">Home delivery</label>
    <p class="k-field-description" id="home-description">9,90 € · Tomorrow between 8 and 21</p>
  </k-radio>
  <k-radio>
    <input type="radio" id="pickup" name="delivery" value="pickup" aria-describedby="pickup-description" checked />
    <label for="pickup">Pickup from store</label>
    <p class="k-field-description" id="pickup-description">Free · Ready in 2 hours</p>
  </k-radio>
  <k-radio>
    <input type="radio" id="locker" name="delivery" value="locker" aria-describedby="locker-description" />
    <label for="locker">Parcel locker</label>
    <p class="k-field-description" id="locker-description">4,90 € · In 1 to 3 days</p>
  </k-radio>
</fieldset>
```

### Custom style

```tsx
import { Fieldset, Radio } from "@kesko/components";

const secondary = {
  "--k-radio-fill": "var(--k-color-theme-secondary)",
  "--k-radio-fill-hover": "var(--k-color-theme-secondary-hover)",
};

export default () => (
  <Fieldset label="Receipt" style={secondary}>
    <Radio label="Email" name="receipt" value="email" defaultChecked />
    <Radio label="Paper" name="receipt" value="paper" />
  </Fieldset>
);

```

```html
<fieldset
  class="k-fieldset"
  style="
    --k-radio-fill: var(--k-color-theme-secondary);
    --k-radio-fill-hover: var(--k-color-theme-secondary-hover);"
>
  <legend class="k-fieldset-legend">Receipt</legend>
  <k-radio>
    <input type="radio" id="email" name="receipt" value="email" checked />
    <label for="email">Email</label>
  </k-radio>
  <k-radio>
    <input type="radio" id="paper" name="receipt" value="paper" />
    <label for="paper">Paper</label>
  </k-radio>
</fieldset>
```

### Disabled

```tsx
import { Fieldset, Radio } from "@kesko/components";

export default () => (
  <Fieldset label="Delivery method">
    <Radio label="Home delivery" name="delivery" value="home" disabled />
    <Radio label="Pickup from store" name="delivery" value="pickup" defaultChecked disabled />
  </Fieldset>
);

```

```html
<fieldset class="k-fieldset">
  <legend class="k-fieldset-legend">Delivery method</legend>
  <k-radio>
    <input type="radio" id="home" name="delivery" value="home" disabled />
    <label for="home">Home delivery</label>
  </k-radio>
  <k-radio>
    <input type="radio" id="pickup" name="delivery" value="pickup" checked disabled />
    <label for="pickup">Pickup from store</label>
  </k-radio>
</fieldset>
```

### Horizontal

```tsx
import { Fieldset, Radio, Stack } from "@kesko/components";

export default () => (
  <Fieldset label="Bag size">
    <Stack direction="row" gap="lg">
      <Radio label="Small" name="bag" value="s" />
      <Radio label="Medium" name="bag" value="m" defaultChecked />
      <Radio label="Large" name="bag" value="l" />
    </Stack>
  </Fieldset>
);

```

```html
<fieldset class="k-fieldset">
  <legend class="k-fieldset-legend">Bag size</legend>
  <k-stack direction="row" gap="lg">
    <k-radio>
      <input type="radio" id="bag-s" name="bag" value="s" />
      <label for="bag-s">Small</label>
    </k-radio>
    <k-radio>
      <input type="radio" id="bag-m" name="bag" value="m" checked />
      <label for="bag-m">Medium</label>
    </k-radio>
    <k-radio>
      <input type="radio" id="bag-l" name="bag" value="l" />
      <label for="bag-l">Large</label>
    </k-radio>
  </k-stack>
</fieldset>
```

### Required

```tsx
import { Fieldset, Radio } from "@kesko/components";

export default () => (
  <Fieldset label="Payment method" required>
    <Radio label="Card" name="payment" value="card" required hideRequired />
    <Radio label="MobilePay" name="payment" value="mobilepay" required hideRequired />
    <Radio label="Invoice" name="payment" value="invoice" required hideRequired />
  </Fieldset>
);

```

```html
<fieldset class="k-fieldset">
  <legend class="k-fieldset-legend">Payment method<span class="k-label-required" aria-hidden="true">*</span></legend>
  <k-radio>
    <input type="radio" id="card" name="payment" value="card" required />
    <label for="card">Card</label>
  </k-radio>
  <k-radio>
    <input type="radio" id="mobilepay" name="payment" value="mobilepay" required />
    <label for="mobilepay">MobilePay</label>
  </k-radio>
  <k-radio>
    <input type="radio" id="invoice" name="payment" value="invoice" required />
    <label for="invoice">Invoice</label>
  </k-radio>
</fieldset>
```

### Validation

```tsx
import { Button, Fieldset, Radio, Stack } from "@kesko/components";

export default () => (
  <form onSubmit={event => event.preventDefault()}>
    <Stack>
      <Fieldset label="Payment method" required>
        <Radio label="MobilePay" name="payment" value="mobilepay" required hideRequired />
        <Radio label="Invoice" name="payment" value="invoice" required hideRequired />
        <Radio
          label="Card ending in 4242"
          name="payment"
          value="card"
          required
          hideRequired
          error="This card has expired."
        />
      </Fieldset>
      <Button type="submit">Place order</Button>
    </Stack>
  </form>
);

```

```html
<form>
  <k-stack>
    <fieldset class="k-fieldset">
      <legend class="k-fieldset-legend">Payment method<span class="k-label-required" aria-hidden="true">*</span></legend>
      <k-radio>
        <input type="radio" id="mobilepay" name="payment" value="mobilepay" required />
        <label for="mobilepay">MobilePay</label>
      </k-radio>
      <k-radio>
        <input type="radio" id="invoice" name="payment" value="invoice" required />
        <label for="invoice">Invoice</label>
      </k-radio>
      <k-radio>
        <input type="radio" id="card" name="payment" value="card" required aria-describedby="card-message" aria-invalid="true" />
        <label for="card">Card ending in 4242</label>
        <k-field-message variant="error" role="alert"><svg viewBox="0 0 24 24" aria-hidden="true" xmlns="http://www.w3.org/2000/svg"><path d="M22.113 18.023L13.745 3.08c-.75-1.343-2.738-1.338-3.49 0L1.888 18.023C1.153 19.332 2.13 21 3.633 21h16.735c1.503 0 2.476-1.666 1.745-2.978zM20.367 19.5H3.633a.504.504 0 0 1-.435-.745l8.364-14.94a.506.506 0 0 1 .875 0l8.368 14.942a.501.501 0 0 1-.438.743zm-8.885-5.66l-.31-4.785c0-.115.08-.195.194-.195h1.265c.116 0 .196.08.196.195l-.3 4.613c0 .127-.058.217-.208.242l-.61.102c-.128.023-.217-.035-.23-.172zM13 16.14c0 .552-.403.978-1 .978s-1-.425-1-.978.403-.965 1-.965 1 .425 1 .965z" fill="currentColor" /></svg><span id="card-message">This card has expired.</span></k-field-message>
      </k-radio>
    </fieldset>
    <button class="k-button" type="submit">Place order</button>
  </k-stack>
</form>
```


## Props

- `label` — `ReactNode` Label for the option. Always provide one, even when it is hidden with `hideLabel`.
- `hideLabel` — `boolean` (default: `false`) Hides the label visually while keeping it available to assistive technology.
- `description` — `ReactNode` Assistive text shown below the option, such as what choosing it leads to.
- `error` — `ReactNode` Optional error message for this option. Also marks the control invalid for assistive technology. An error about the whole group, such as nothing selected, goes on the Fieldset.
- `name` — `string` The name of the group. Every option in the group shares it, and the value of the selected option is submitted under it.
- `value` — `string` The value submitted under `name` while this option is selected.
- `checked` — `boolean` Whether this option is selected. Pair with `onChange` to control the group.
- `defaultChecked` — `boolean` Whether this option starts selected in an uncontrolled group.
- `required` — `boolean` (default: `false`) Requires one option of the group to be selected before the form submits. Draws the marker on the label and is announced to assistive technology. Put the marker on the Fieldset legend instead and pass `hideRequired` here when every option would otherwise carry one.
- `hideRequired` — `boolean` (default: `false`) Hides the required marker on the label while keeping `required` on the control.
- `disabled` — `boolean` Disables the option. Blocks interaction and drops the value from the submitted data.
- `form` — `string` The `id` of the form the control submits with. Only needed when the control sits outside that form.

## Events

- `onChange` — `(event: ChangeEvent<HTMLInputElement>) => void` Handler called when this option becomes selected.
- `onFocus` — `(event: FocusEvent<HTMLInputElement>) => void` Handler called when the control receives focus.
- `onBlur` — `(event: FocusEvent<HTMLInputElement>) => void` Handler called when the control loses focus.

## CSS custom properties

- `--k-radio-bg` (default: `var(--k-color-bg-base)`) Overrides the background color of the control.
- `--k-radio-border` (default: `var(--k-color-border-control)`) Overrides the border color of the unselected control in every state.
- `--k-radio-fill` (default: `var(--k-color-theme-primary)`) Overrides the border and dot color of the selected control.
- `--k-radio-fill-hover` (default: `var(--k-color-theme-primary-hover)`) Overrides the border and dot color of the selected control on hover and focus.
- `--k-radio-text` (default: `var(--k-color-text-base)`) Overrides the label text color.
- `--k-radio-focus` (default: `var(--k-color-border-focus)`) Overrides the focus ring color.

## Accessibility

Radio is built on a native `<input type="radio">` and `<label>`, so it behaves as expected with assistive technologies.

- **Always pass a `label`, and keep it visible.** A screen reader reads it as the name of the option, and clicking it selects the option. Options are read side by side, so a group of unlabelled circles cannot be compared.
- **Always put the group in a [Fieldset](/components/fieldset/).** The options share one `name`, and the legend names the question they answer. A required group that is left empty shows its message on the Fieldset, not under every option.
- **Start with one option selected when there is a sensible default.** Once an option is selected it can be changed but not cleared, so a group that starts empty asks for a decision. Leave it empty only when a default would be dishonest, such as a payment method, and mark the group `required`.
- **Pick the right control.** Radio is for exactly one choice out of a few. Several independent options are a [Checkbox](/components/checkbox/) group, and a setting that takes effect right away is a [Switch](/components/switch/).
- **Avoid `disabled` for validation.** A disabled option leaves the tab order and cannot explain itself. Keep it enabled and let the message say what is wrong.
- **Check contrast if you override colors.** The label needs 4.5:1 against the surface, and `--k-radio-border` and `--k-radio-fill` need 3:1 against it. Verify with the [WebAIM contrast checker](https://webaim.org/resources/contrastchecker/).

See the [accessibility guidelines](/accessibility/) and the [A11Y checklist](/a11y-checklist/) for more details.

## Integration

Install `@kesko/components` together with `@kesko/css`, which provides the design tokens and base styles it depends on, and `@kesko/themes` for your brand:

```sh
npm install @kesko/components @kesko/css @kesko/themes
```

Then load the base stylesheet and one brand theme once, in your app's entry point or root layout. Leave out `@kesko/css/components`: it mirrors the component styles for plain HTML, and `@kesko/components` already ships them.

```tsx
import "@kesko/css";
import "@kesko/themes/dist/k-rauta.css";
```

Finally, import the component into your project:

```tsx
import { Radio } from "@kesko/components";
```

Projects without React get the same markup and styling from `@kesko/css` by importing the base stylesheet, the `components` add-on and a brand theme, in that order:

```css
@import "@kesko/css";
@import "@kesko/css/components";
@import "@kesko/themes/dist/k-rauta.css";
```

The HTML examples above show the exact markup to copy.

## Resources

- [Usage guidelines](/components/usage/) — Learn how to use the component library with React, Next.js, or basic HTML.
- [Localization](/localization/) — How to translate the components for multiple languages.
- [CSS Framework](/css/) — Utilities and tokens for everything the components don’t cover.
- [Themes](/themes/) — How to customize the component library theme.
- [Accessibility checklist](/a11y-checklist/) — Interactive, browser-based Kesko accessibility checklist.

