Skip to main content
Components

Text input

Help users enter information with the text input component.

Read the Design System guidance for text input

Import

import { Input, InputField, InputPrefix, InputSuffix, InputWrapper } from 'govuk-react/input';

Examples

Default

Code
<InputField
  id="event-name"
  name="event-name"
  label="What is the name of the event?"
/>

Input with hint text

Code
<InputField
  id="event-name"
  name="event-name"
  label="What is the name of the event?"
  hint="The name you’ll use on promotional material"
/>

Input with hint text error

Code
<InputField
  id="event-name"
  name="event-name"
  label="What is the name of the event?"
  hint="The name you’ll use on promotional material"
  errorMessage="Enter an event name"
/>

With prefix and suffix

Code
<InputField
  id="cost-per-item"
  name="costPerItem"
  label="What is the cost per item, in pounds?"
  prefix="£"
  suffix="per item"
  width={5}
  spellCheck={false}
/>

With type and auto complete

Code
<InputField
  id="email"
  name="email"
  label="Email address"
  type="email"
  autoComplete="email"
  spellCheck={false}
/>

As page heading

Code
<InputField
  id="event-name"
  name="event-name"
  label="What is the name of the event?"
  labelSize="l"
  labelIsPageHeading
/>

API reference

Input

Help users enter information with the text input component.

PropType
errorboolean
width

A number of characters, or a fraction of the container.

2 | 3 | 4 | 5 | 10 | 20 | 30 | FluidWidth
extraLetterSpacingboolean

InputField

Help users enter information with the text input component.

PropType
labelSize"s" | "m" | "l" | "xl"
labelIsPageHeadingboolean
width

A number of characters, or a fraction of the container.

2 | 3 | 4 | 5 | 10 | 20 | 30 | FluidWidth
extraLetterSpacingboolean
label

The label used by the text input component.

ReactNode
hint

Can be used to add a hint to a text input component.

ReactNode
errorMessage

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

ReactNode
prefix

Can be used to add a prefix to the text input component.

ReactNode
suffix

Can be used to add a suffix to the text input component.

ReactNode

InputPrefix

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

InputSuffix

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

InputWrapper

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