Skip to main content
Components

Radios

Let users select a single option from a list using the radios component.

Children are Items, each with an Input, followed by a Conditional where it reveals one.

Read the Design System guidance for radios

Import

import * as Radios from 'govuk-react/radios';

Examples

Default

Code
<Radios.Field
  idPrefix="where-do-you-live"
  legend="Where do you live?"
>
  {items}
</Radios.Field>

Radio small

Code
<Radios.Field
  idPrefix="where-do-you-live"
  legend="Where do you live?"
  small
>
  {items}
</Radios.Field>

Radio inline

Code
<Radios.Field
  idPrefix="where-do-you-live"
  legend="Have you changed your name?"
  hint="This includes changing your last name or spelling your name differently."
  inline
>
  {(
    <>
      <Radios.ItemComposite id="changed-name" name="changed-name" value="yes" label="Yes" />
      <Radios.ItemComposite id="changed-name-2" name="changed-name" value="no" label="No" />
    </>
  )}
</Radios.Field>

Radio preselected

Code
<Radios.Field
  idPrefix="where-do-you-live"
  legend="Where do you live?"
>
  {(
    <>
      <Radios.ItemComposite id="pre" name="pre" value="yes" label="Yes" defaultChecked />
      <Radios.ItemComposite id="pre-2" name="pre" value="no" label="No" disabled />
    </>
  )}
</Radios.Field>

Radio with hint text

Code
<Radios.Field
  idPrefix="where-do-you-live"
  legend="How do you want to sign in?"
>
  {(
    <>
      <Radios.ItemComposite
        id="sign-in"
        name="sign-in"
        value="gateway"
        label="Sign in with Government Gateway"
        hint="You’ll have a user ID if you’ve registered for Self Assessment or filed a tax return online before."
      />
      <Radios.ItemComposite
        id="sign-in-2"
        name="sign-in"
        value="verify"
        label="Sign in with GOV.UK Verify"
        hint="You’ll have an account if you’ve already proved your identity with either Barclays, CitizenSafe, Digidentity, Experian, Post Office, Royal Mail or SecureIdentity."
      />
    </>
  )}
</Radios.Field>

With error

Code
<Radios.Field
  idPrefix="where-do-you-live"
  legend="Where do you live?"
  errorMessage="Select the country where you live"
>
  {items}
</Radios.Field>

With conditional

Code
<Radios.Field
  idPrefix="where-do-you-live"
  legend="How would you prefer to be contacted?"
>
  {(
    <>
      <Radios.ItemComposite
        id="contact"
        name="contact"
        value="email"
        label="Email"
        defaultChecked
        conditional={<InputField id="contact-by-email" name="contact-by-email" type="email" label="Email address" />}
      />
      <Radios.ItemComposite
        id="contact-2"
        name="contact"
        value="phone"
        label="Phone"
        conditional={<InputField id="contact-by-phone" name="contact-by-phone" type="tel" label="Phone number" />}
      />
      <Radios.ItemComposite id="contact-3" name="contact" value="text" label="Text message" />
    </>
  )}
</Radios.Field>

API reference

Radios.Root

Let users select a single option from a list using the radios component.

Children are Items, each with an Input, followed by a Conditional where it reveals one.

PropType
inlineboolean
smallboolean

Radios.Conditional

Content revealed while its radio is checked, straight after its Item. Pass the radio's checked or defaultChecked as checked.

PropType
checkedboolean

Radios.Divider

No props of its own. Other props are passed to the element it renders.

Radios.Field

Let users select a single option from a list using the radios component.

Children are ItemComposites and Dividers.

PropType
legendSize"s" | "m" | "l" | "xl"
legendIsPageHeadingboolean
smallboolean
inlineboolean
idPrefixRequired

This is used to prefix the id attribute for each radio item input, hint and error message, separated by -.

string
legendRequired

The legend for the fieldset used by the radios component.

ReactNode
hint

Can be used to add a hint to the radios component.

ReactNode
errorMessage

Can be used to add an error message to the radios component. The error message component will not display if you use a falsy value for errorMessage, for example false or null.

ReactNode
items

Prefer children, which memoise and re-render better.

(ItemCompositeProps | { divider: any; })[]

Radios.Hint

No props of its own. Other props are passed to the element it renders.

Radios.Input

PropType
controls

The id of the Conditional this radio reveals.

string

Radios.Item

No props of its own. Other props are passed to the element it renders.

Radios.ItemComposite

PropType
labelRequired

The label used by each radio item within the radios component.

ReactNode
hint

Can be used to add a hint to each radio item within the radios component.

ReactNode
conditional

Provide additional content to reveal when the radio is checked.

ReactNode

Radios.Label

PropType
size"s" | "m" | "l" | "xl"
isPageHeading

Whether the label also acts as the heading for the page.

boolean