
# Fieldset



> Fieldset component is used to group together several related form controls. This helps to make these groups accessible for assistive technologies.

## Examples

### Default

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

export default () => (
  <Fieldset label="Delivery address">
    <Input label="Street address" name="street" autoComplete="street-address" />
    <Select label="City" name="city" placeholder="Choose a city">
      <option value="helsinki">Helsinki</option>
      <option value="espoo">Espoo</option>
      <option value="vantaa">Vantaa</option>
    </Select>
    <Input label="Postal code" name="postal" inputMode="numeric" autoComplete="postal-code" />
  </Fieldset>
);

```

```html
<fieldset class="k-fieldset">
  <legend class="k-fieldset-legend">Delivery address</legend>
  <k-input>
    <label class="k-label" for="street">Street address</label>
    <div class="k-field">
      <input id="street" name="street" autocomplete="street-address" />
    </div>
  </k-input>
  <k-select>
    <label class="k-label" for="city">City</label>
    <div class="k-field">
      <select id="city" name="city">
        <option value="">Choose a city</option>
        <option value="helsinki">Helsinki</option>
        <option value="espoo">Espoo</option>
        <option value="vantaa">Vantaa</option>
      </select>
      <svg slot="end" viewBox="0 0 24 24" aria-hidden="true" xmlns="http://www.w3.org/2000/svg"><path d="M18.747 10.313l-6.465 6.464a.401.401 0 0 1-.565 0l-6.464-6.465a.401.401 0 0 1 0-.564l.495-.495a.401.401 0 0 1 .565 0L12 14.94l5.688-5.687a.401.401 0 0 1 .565 0l.495.495a.401.401 0 0 1 0 .565z" fill="currentColor" /></svg>
    </div>
  </k-select>
  <k-input>
    <label class="k-label" for="postal">Postal code</label>
    <div class="k-field">
      <input id="postal" name="postal" inputmode="numeric" autocomplete="postal-code" />
    </div>
  </k-input>
</fieldset>
```

### Assistive text

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

export default () => (
  <Fieldset label="Contact person" description="Who the driver calls if nobody answers the door.">
    <Input label="Name" name="contact-name" autoComplete="name" />
    <Input label="Phone" name="contact-phone" type="tel" autoComplete="tel" />
    <Textarea label="Delivery instructions" name="instructions" placeholder="Door code, floor, where to leave the order" />
  </Fieldset>
);

```

```html
<fieldset class="k-fieldset" aria-describedby="contact-description">
  <legend class="k-fieldset-legend">Contact person</legend>
  <p class="k-field-description" id="contact-description">Who the driver calls if nobody answers the door.</p>
  <k-input>
    <label class="k-label" for="contact-name">Name</label>
    <div class="k-field">
      <input id="contact-name" name="contact-name" autocomplete="name" />
    </div>
  </k-input>
  <k-input>
    <label class="k-label" for="contact-phone">Phone</label>
    <div class="k-field">
      <input id="contact-phone" name="contact-phone" type="tel" autocomplete="tel" />
    </div>
  </k-input>
  <k-textarea>
    <label class="k-label" for="instructions">Delivery instructions</label>
    <div class="k-field">
      <textarea id="instructions" name="instructions" placeholder="Door code, floor, where to leave the order"></textarea>
    </div>
  </k-textarea>
</fieldset>
```

### Checkbox group

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

export default () => (
  <Fieldset label="Order updates">
    <Checkbox label="Email" name="updates" value="email" defaultChecked />
    <Checkbox label="Text message" name="updates" value="text" />
    <Checkbox label="Push notification" name="updates" value="push" />
  </Fieldset>
);

```

```html
<fieldset class="k-fieldset">
  <legend class="k-fieldset-legend">Order updates</legend>
  <k-checkbox>
    <input type="checkbox" id="email" name="updates" value="email" checked />
    <label for="email">Email</label>
  </k-checkbox>
  <k-checkbox>
    <input type="checkbox" id="text" name="updates" value="text" />
    <label for="text">Text message</label>
  </k-checkbox>
  <k-checkbox>
    <input type="checkbox" id="push" name="updates" value="push" />
    <label for="push">Push notification</label>
  </k-checkbox>
</fieldset>
```

### Custom style

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

const compact = {
  "--k-fieldset-gap": "var(--k-space-2xs)",
  "--k-fieldset-border": "var(--k-color-border-primary)",
  "--k-fieldset-radius": "var(--k-radius-md)",
  "--k-fieldset-legend-size": "var(--k-font-size-md)",
  "--k-fieldset-legend-text": "var(--k-color-text-primary)",
};

export default () => (
  <Fieldset label="Card holder" variant="outline" style={compact}>
    <Input label="First name" name="first-name" autoComplete="given-name" />
    <Input label="Last name" name="last-name" autoComplete="family-name" />
  </Fieldset>
);

```

```html
<fieldset
  class="k-fieldset"
  variant="outline"
  style="
    --k-fieldset-gap: var(--k-space-2xs);
    --k-fieldset-border: var(--k-color-border-primary);
    --k-fieldset-radius: var(--k-radius-md);
    --k-fieldset-legend-size: var(--k-font-size-md);
    --k-fieldset-legend-text: var(--k-color-text-primary);"
>
  <legend class="k-fieldset-legend">Card holder</legend>
  <k-input>
    <label class="k-label" for="first-name">First name</label>
    <div class="k-field">
      <input id="first-name" name="first-name" autocomplete="given-name" />
    </div>
  </k-input>
  <k-input>
    <label class="k-label" for="last-name">Last name</label>
    <div class="k-field">
      <input id="last-name" name="last-name" autocomplete="family-name" />
    </div>
  </k-input>
</fieldset>
```

### Disabled

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

export default () => (
  <Fieldset label="Delivery address" disabled>
    <Input label="Street address" name="street" autoComplete="street-address" />
    <Select label="City" name="city" placeholder="Choose a city">
      <option value="helsinki">Helsinki</option>
      <option value="espoo">Espoo</option>
      <option value="vantaa">Vantaa</option>
    </Select>
    <Input label="Postal code" name="postal" inputMode="numeric" autoComplete="postal-code" />
  </Fieldset>
);

```

```html
<fieldset class="k-fieldset" disabled>
  <legend class="k-fieldset-legend">Delivery address</legend>
  <k-input>
    <label class="k-label" for="street">Street address</label>
    <div class="k-field">
      <input id="street" name="street" autocomplete="street-address" />
    </div>
  </k-input>
  <k-select>
    <label class="k-label" for="city">City</label>
    <div class="k-field">
      <select id="city" name="city">
        <option value="">Choose a city</option>
        <option value="helsinki">Helsinki</option>
        <option value="espoo">Espoo</option>
        <option value="vantaa">Vantaa</option>
      </select>
      <svg slot="end" viewBox="0 0 24 24" aria-hidden="true" xmlns="http://www.w3.org/2000/svg"><path d="M18.747 10.313l-6.465 6.464a.401.401 0 0 1-.565 0l-6.464-6.465a.401.401 0 0 1 0-.564l.495-.495a.401.401 0 0 1 .565 0L12 14.94l5.688-5.687a.401.401 0 0 1 .565 0l.495.495a.401.401 0 0 1 0 .565z" fill="currentColor" /></svg>
    </div>
  </k-select>
  <k-input>
    <label class="k-label" for="postal">Postal code</label>
    <div class="k-field">
      <input id="postal" name="postal" inputmode="numeric" autocomplete="postal-code" />
    </div>
  </k-input>
</fieldset>
```

### Hidden label

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

export default () => (
  <Fieldset label="Name" hideLabel>
    <Input label="First name" name="first-name" autoComplete="given-name" />
    <Input label="Last name" name="last-name" autoComplete="family-name" />
  </Fieldset>
);

```

```html
<fieldset class="k-fieldset">
  <legend class="k-fieldset-legend k-visually-hidden">Name</legend>
  <k-input>
    <label class="k-label" for="first-name">First name</label>
    <div class="k-field">
      <input id="first-name" name="first-name" autocomplete="given-name" />
    </div>
  </k-input>
  <k-input>
    <label class="k-label" for="last-name">Last name</label>
    <div class="k-field">
      <input id="last-name" name="last-name" autocomplete="family-name" />
    </div>
  </k-input>
</fieldset>
```

### Nested

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

export default () => (
  <Fieldset label="Delivery address">
    <Input label="Street address" name="street" autoComplete="street-address" />
    <Input label="Postal code" name="postal" inputMode="numeric" autoComplete="postal-code" />
    <Fieldset label="If nobody is home">
      <Radio label="Leave the order at the door" name="absent" value="door" defaultChecked />
      <Radio label="Take the order back to the store" name="absent" value="store" />
    </Fieldset>
  </Fieldset>
);

```

```html
<fieldset class="k-fieldset">
  <legend class="k-fieldset-legend">Delivery address</legend>
  <k-input>
    <label class="k-label" for="street">Street address</label>
    <div class="k-field">
      <input id="street" name="street" autocomplete="street-address" />
    </div>
  </k-input>
  <k-input>
    <label class="k-label" for="postal">Postal code</label>
    <div class="k-field">
      <input id="postal" name="postal" inputmode="numeric" autocomplete="postal-code" />
    </div>
  </k-input>
  <fieldset class="k-fieldset">
    <legend class="k-fieldset-legend">If nobody is home</legend>
    <k-radio>
      <input type="radio" id="door" name="absent" value="door" checked />
      <label for="door">Leave the order at the door</label>
    </k-radio>
    <k-radio>
      <input type="radio" id="store" name="absent" value="store" />
      <label for="store">Take the order back to the store</label>
    </k-radio>
  </fieldset>
</fieldset>
```

### Outline

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

export default () => (
  <Fieldset label="Delivery address" variant="outline">
    <Input label="Street address" name="street" autoComplete="street-address" />
    <Select label="City" name="city" placeholder="Choose a city">
      <option value="helsinki">Helsinki</option>
      <option value="espoo">Espoo</option>
      <option value="vantaa">Vantaa</option>
    </Select>
    <Input label="Postal code" name="postal" inputMode="numeric" autoComplete="postal-code" />
  </Fieldset>
);

```

```html
<fieldset class="k-fieldset" variant="outline">
  <legend class="k-fieldset-legend">Delivery address</legend>
  <k-input>
    <label class="k-label" for="street">Street address</label>
    <div class="k-field">
      <input id="street" name="street" autocomplete="street-address" />
    </div>
  </k-input>
  <k-select>
    <label class="k-label" for="city">City</label>
    <div class="k-field">
      <select id="city" name="city">
        <option value="">Choose a city</option>
        <option value="helsinki">Helsinki</option>
        <option value="espoo">Espoo</option>
        <option value="vantaa">Vantaa</option>
      </select>
      <svg slot="end" viewBox="0 0 24 24" aria-hidden="true" xmlns="http://www.w3.org/2000/svg"><path d="M18.747 10.313l-6.465 6.464a.401.401 0 0 1-.565 0l-6.464-6.465a.401.401 0 0 1 0-.564l.495-.495a.401.401 0 0 1 .565 0L12 14.94l5.688-5.687a.401.401 0 0 1 .565 0l.495.495a.401.401 0 0 1 0 .565z" fill="currentColor" /></svg>
    </div>
  </k-select>
  <k-input>
    <label class="k-label" for="postal">Postal code</label>
    <div class="k-field">
      <input id="postal" name="postal" inputmode="numeric" autocomplete="postal-code" />
    </div>
  </k-input>
</fieldset>
```

### Radio group

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

export default () => (
  <Fieldset label="Payment method">
    <Radio label="Card" name="payment" value="card" defaultChecked />
    <Radio label="Invoice" name="payment" value="invoice" />
    <Radio label="Pay at pickup" name="payment" value="pickup" />
  </Fieldset>
);

```

```html
<fieldset class="k-fieldset">
  <legend class="k-fieldset-legend">Payment method</legend>
  <k-radio>
    <input type="radio" id="card" name="payment" value="card" checked />
    <label for="card">Card</label>
  </k-radio>
  <k-radio>
    <input type="radio" id="invoice" name="payment" value="invoice" />
    <label for="invoice">Invoice</label>
  </k-radio>
  <k-radio>
    <input type="radio" id="pickup" name="payment" value="pickup" />
    <label for="pickup">Pay at pickup</label>
  </k-radio>
</fieldset>
```

### Required

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

export default () => (
  <Stack gap="xl" alignment="stretch">
    <Fieldset label="Card holder" required>
      <Input label="First name" name="first-name" autoComplete="given-name" required hideRequired />
      <Input label="Last name" name="last-name" autoComplete="family-name" required hideRequired />
    </Fieldset>
    <Fieldset label="Billing address" required hideRequired>
      <Input label="Street address" name="street" autoComplete="street-address" required hideRequired />
      <Input label="Postal code" name="postal" inputMode="numeric" autoComplete="postal-code" required hideRequired />
    </Fieldset>
  </Stack>
);

```

```html
<k-stack gap="xl" alignment="stretch">
  <fieldset class="k-fieldset">
    <legend class="k-fieldset-legend">Card holder<span class="k-label-required" aria-hidden="true">*</span></legend>
    <k-input>
      <label class="k-label" for="first-name">First name</label>
      <div class="k-field">
        <input id="first-name" name="first-name" autocomplete="given-name" required />
      </div>
    </k-input>
    <k-input>
      <label class="k-label" for="last-name">Last name</label>
      <div class="k-field">
        <input id="last-name" name="last-name" autocomplete="family-name" required />
      </div>
    </k-input>
  </fieldset>
  <fieldset class="k-fieldset">
    <legend class="k-fieldset-legend">Billing address</legend>
    <k-input>
      <label class="k-label" for="street">Street address</label>
      <div class="k-field">
        <input id="street" name="street" autocomplete="street-address" required />
      </div>
    </k-input>
    <k-input>
      <label class="k-label" for="postal">Postal code</label>
      <div class="k-field">
        <input id="postal" name="postal" inputmode="numeric" autocomplete="postal-code" required />
      </div>
    </k-input>
  </fieldset>
</k-stack>
```

### Fields in a row

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

export default () => (
  <Fieldset label="Amount">
    <Stack direction="row">
      <Input label="Quantity" name="quantity" inputMode="numeric" defaultValue="2" style={{ "--k-input-inline-size": "8rem" }} />
      <Select label="Unit" name="unit" defaultValue="kg" style={{ "--k-select-inline-size": "8rem" }}>
        <option value="kg">kg</option>
        <option value="g">g</option>
        <option value="pcs">pcs</option>
      </Select>
    </Stack>
    <Input label="Note to the picker" name="note" placeholder="Ripe ones, please" />
  </Fieldset>
);

```

```html
<fieldset class="k-fieldset">
  <legend class="k-fieldset-legend">Amount</legend>
  <k-stack direction="row">
    <k-input style="--k-input-inline-size: 8rem;">
      <label class="k-label" for="quantity">Quantity</label>
      <div class="k-field">
        <input id="quantity" name="quantity" inputmode="numeric" value="2" />
      </div>
    </k-input>
    <k-select style="--k-select-inline-size: 8rem;">
      <label class="k-label" for="unit">Unit</label>
      <div class="k-field">
        <select id="unit" name="unit">
          <option value="kg" selected>kg</option>
          <option value="g">g</option>
          <option value="pcs">pcs</option>
        </select>
        <svg slot="end" viewBox="0 0 24 24" aria-hidden="true" xmlns="http://www.w3.org/2000/svg"><path d="M18.747 10.313l-6.465 6.464a.401.401 0 0 1-.565 0l-6.464-6.465a.401.401 0 0 1 0-.564l.495-.495a.401.401 0 0 1 .565 0L12 14.94l5.688-5.687a.401.401 0 0 1 .565 0l.495.495a.401.401 0 0 1 0 .565z" fill="currentColor" /></svg>
      </div>
    </k-select>
  </k-stack>
  <k-input>
    <label class="k-label" for="note">Note to the picker</label>
    <div class="k-field">
      <input id="note" name="note" placeholder="Ripe ones, please" />
    </div>
  </k-input>
</fieldset>
```

### Validation

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

export default () => (
  <Fieldset label="Delivery address" error="We don't deliver to this address yet.">
    <Input label="Street address" name="street" defaultValue="Satamakatu 3" autoComplete="street-address" />
    <Input label="Postal code" name="postal" defaultValue="48100" inputMode="numeric" autoComplete="postal-code" />
  </Fieldset>
);

```

```html
<fieldset class="k-fieldset" aria-describedby="address-message">
  <legend class="k-fieldset-legend">Delivery address</legend>
  <k-input>
    <label class="k-label" for="street">Street address</label>
    <div class="k-field">
      <input id="street" name="street" value="Satamakatu 3" autocomplete="street-address" />
    </div>
  </k-input>
  <k-input>
    <label class="k-label" for="postal">Postal code</label>
    <div class="k-field">
      <input id="postal" name="postal" value="48100" inputmode="numeric" autocomplete="postal-code" />
    </div>
  </k-input>
  <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="address-message">We don't deliver to this address yet.</span></k-field-message>
</fieldset>
```


## Props

- `label` — `ReactNode` Label for the group, rendered as the `<legend>`. Always provide one, even when it is hidden with `hideLabel`.
- `hideLabel` — `boolean` (default: `false`) Hides the legend visually while keeping it available to assistive technology.
- `variant` — `"plain" | "outline"` (default: `"plain"`) The style of the group. `outline` draws a border around the fields with the legend sitting on it.
- `description` — `ReactNode` Assistive text for the whole group, shown under the legend.
- `error` — `ReactNode` Optional error message for the whole group, shown after the fields. Use it for an error no single field owns, such as a choice missing from a group of radio buttons. When a required group of radio buttons has nothing selected on submit, a built-in message shows here on its own; `error` replaces it.
- `required` — `boolean` (default: `false`) Draws the required marker on the legend. The controls inside decide what is actually required.
- `hideRequired` — `boolean` (default: `false`) Hides the required marker on the legend. Use it when the form says once that every field is required.
- `disabled` — `boolean` Disables every control inside the group and drops their values from the submitted data.
- `name` — `string` The name of the group.
- `form` — `string` The `id` of the form the group belongs to. Only needed when the group sits outside that form.

## CSS custom properties

- `--k-fieldset-gap` (default: `var(--k-space-md)`) Overrides the space between the legend, the fields and the messages.
- `--k-fieldset-border` (default: `var(--k-color-text-base)`) Overrides the border color of the outline variant.
- `--k-fieldset-radius` (default: `var(--k-radius-lg)`) Overrides the border radius of the outline variant.
- `--k-fieldset-legend-size` (default: `var(--k-font-size-lg)`) Overrides the font size of the legend.
- `--k-fieldset-legend-text` (default: `var(--k-color-text-base)`) Overrides the text color of the legend.

## Accessibility

Fieldset is built on a native `<fieldset>` with a `<legend>`, so assistive technology reads the `label` as the name of the group and announces it with the controls inside.

- **Always pass a `label`.** The label is what names the group. If there is no room for it, pass `hideLabel` rather than leaving it out.
- **Keep the label short.** Some screen readers read it before every control's own label, so a long one is repeated many times. Put detail in `description` instead.
- **Group only what belongs together.** A fieldset earns its place when the fields share one meaning, such as the lines of an address or the options of one choice. A group that already has a name, such as a form under its own heading or inside a dialog, does not need a second one from a Fieldset.
- **Fieldset is not a form.** Put everything people fill in and send together inside a [Form](/components/form/). Fieldset names the parts inside it that share one meaning.
- **Put a group's error on the group.** An error no single field owns, such as nothing chosen in a group of radio buttons, goes in `error` so it is read with the group. An error about one field stays on that field. The message shows after everything in the group, so when radio buttons share a group with other fields, give the radio buttons a Fieldset of their own. A required [Radio](/components/radio/) group that is left empty shows the browser's own message here without any extra code.
- **`disabled` switches off every control inside.** Reach for it only when the whole group does not apply right now, and say why nearby. Disabled controls leave the tab order and cannot explain themselves.
- **Check contrast if you override colors.** The label needs 4.5:1 against the surface, and `--k-fieldset-border` needs 3:1 against it in the outline variant. 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 { Fieldset } 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.

