Components

Text input

<div id="event-name" class="govuk-form-group">
  <label for="event-name-input" class="govuk-label">
    <h1 class="govuk-heading-l">
      What is the name of the event?
    </h1>
  </label>
  <input
    name="event-name"
    id="event-name-input"
    class="govuk-input"
    type="text"
  />
</div>
<TextInput
  label={
    <h1 className="govuk-heading-l">
      What is the name of the event?
    </h1>
  }
  name="event-name"
/>
Props
NameTypeDefaultDescription
idother'id' attribute to place on the base HTML element
classBlockotherBlock name override in BEM style classes applied to all elements
classModifiersotherBEM style modifiers to apply to the base HTML element
classNameotherExtra classes to apply to the base HTML element
acceptother
altother
autoCompleteother
captureother
checkedother
disabledother
formother
formActionother
formEncTypeother
formMethodother
formNoValidateother
formTargetother
heightother
listother
maxother
maxLengthother
minother
minLengthother
multipleother
namestringHTML name
patternother
placeholderother
readOnlyother
requiredother
sizeother
srcother
stepother
typeother
valueother
widthotherWidth of the field in characters (approximate)
onChangeother
defaultCheckedother
defaultValueother
suppressContentEditableWarningother
suppressHydrationWarningother
accessKeyother
autoCapitalizeother
autoFocusother
contentEditableother
contextMenuother
dirother
draggableother
enterKeyHintother
hiddenother
langother
nonceother
slotother
spellCheckother
styleother
tabIndexother
titleother
translateother
radioGroupother
roleother
aboutother
contentother
datatypeother
inlistother
prefixotherPrefix to show before the field
propertyother
relother
resourceother
revother
typeofother
vocabother
autoCorrectother
autoSaveother
colorother
itemPropother
itemScopeother
itemTypeother
itemIDother
itemRefother
resultsother
securityother
unselectableother
inputModeotherHints at the type of data that might be entered by the user while editing the element or its contents
isotherSpecify that a standard HTML element should behave like a defined custom built-in element
aria-activedescendantotherIdentifies the currently active element when DOM focus is on a composite widget, textbox, group, or application.
aria-atomicotherIndicates whether assistive technologies will present all, or only parts of, the changed region based on the change notifications defined by the aria-relevant attribute.
aria-autocompleteotherIndicates whether inputting text could trigger display of one or more predictions of the user's intended value for an input and specifies how predictions would be presented if they are made.
aria-braillelabelotherDefines a string value that labels the current element, which is intended to be converted into Braille.
aria-brailleroledescriptionotherDefines a human-readable, author-localized abbreviated description for the role of an element, which is intended to be converted into Braille.
aria-busyother
aria-checkedotherIndicates the current "checked" state of checkboxes, radio buttons, and other widgets.
aria-colcountotherDefines the total number of columns in a table, grid, or treegrid.
aria-colindexotherDefines an element's column index or position with respect to the total number of columns within a table, grid, or treegrid.
aria-colindextextotherDefines a human readable text alternative of aria-colindex.
aria-colspanotherDefines the number of columns spanned by a cell or gridcell within a table, grid, or treegrid.
aria-controlsotherIdentifies the element (or elements) whose contents or presence are controlled by the current element.
aria-currentotherIndicates the element that represents the current item within a container or set of related elements.
aria-describedbyotherIdentifies the element (or elements) that describes the object.
aria-descriptionotherDefines a string value that describes or annotates the current element.
aria-detailsotherIdentifies the element that provides a detailed, extended description for the object.
aria-disabledotherIndicates that the element is perceivable but disabled, so it is not editable or otherwise operable.
aria-dropeffectotherIndicates what functions can be performed when a dragged object is released on the drop target.
aria-errormessageotherIdentifies the element that provides an error message for the object.
aria-expandedotherIndicates whether the element, or another grouping element it controls, is currently expanded or collapsed.
aria-flowtootherIdentifies the next element (or elements) in an alternate reading order of content which, at the user's discretion, allows assistive technology to override the general default of reading in document source order.
aria-grabbedotherIndicates an element's "grabbed" state in a drag-and-drop operation.
aria-haspopupotherIndicates the availability and type of interactive popup element, such as menu or dialog, that can be triggered by an element.
aria-hiddenotherIndicates whether the element is exposed to an accessibility API.
aria-invalidotherIndicates the entered value does not conform to the format expected by the application.
aria-keyshortcutsotherIndicates keyboard shortcuts that an author has implemented to activate or give focus to an element.
aria-labelotherDefines a string value that labels the current element.
aria-labelledbyotherIdentifies the element (or elements) that labels the current element.
aria-levelotherDefines the hierarchical level of an element within a structure.
aria-liveotherIndicates that an element will be updated, and describes the types of updates the user agents, assistive technologies, and user can expect from the live region.
aria-modalotherIndicates whether an element is modal when displayed.
aria-multilineotherIndicates whether a text box accepts multiple lines of input or only a single line.
aria-multiselectableotherIndicates that the user may select more than one item from the current selectable descendants.
aria-orientationotherIndicates whether the element's orientation is horizontal, vertical, or unknown/ambiguous.
aria-ownsotherIdentifies an element (or elements) in order to define a visual, functional, or contextual parent/child relationship between DOM elements where the DOM hierarchy cannot be used to represent the relationship.
aria-placeholderotherDefines a short hint (a word or short phrase) intended to aid the user with data entry when the control has no value. A hint could be a sample value or a brief description of the expected format.
aria-posinsetotherDefines an element's number or position in the current set of listitems or treeitems. Not required if all elements in the set are present in the DOM.
aria-pressedotherIndicates the current "pressed" state of toggle buttons.
aria-readonlyotherIndicates that the element is not editable, but is otherwise operable.
aria-relevantotherIndicates what notifications the user agent will trigger when the accessibility tree within a live region is modified.
aria-requiredotherIndicates that user input is required on the element before a form may be submitted.
aria-roledescriptionotherDefines a human-readable, author-localized description for the role of an element.
aria-rowcountotherDefines the total number of rows in a table, grid, or treegrid.
aria-rowindexotherDefines an element's row index or position with respect to the total number of rows within a table, grid, or treegrid.
aria-rowindextextotherDefines a human readable text alternative of aria-rowindex.
aria-rowspanotherDefines the number of rows spanned by a cell or gridcell within a table, grid, or treegrid.
aria-selectedotherIndicates the current "selected" state of various widgets.
aria-setsizeotherDefines the number of items in the current set of listitems or treeitems. Not required if all elements in the set are present in the DOM.
aria-sortotherIndicates if items in a table or grid are sorted in ascending or descending order.
aria-valuemaxotherDefines the maximum allowed value for a range widget.
aria-valueminotherDefines the minimum allowed value for a range widget.
aria-valuenowotherDefines the current value for a range widget.
aria-valuetextotherDefines the human readable text alternative of aria-valuenow for a range widget.
dangerouslySetInnerHTMLother
onCopyother
onCopyCaptureother
onCutother
onCutCaptureother
onPasteother
onPasteCaptureother
onCompositionEndother
onCompositionEndCaptureother
onCompositionStartother
onCompositionStartCaptureother
onCompositionUpdateother
onCompositionUpdateCaptureother
onFocusother
onFocusCaptureother
onBlurother
onBlurCaptureother
onChangeCaptureother
onBeforeInputother
onBeforeInputCaptureother
onInputother
onInputCaptureother
onResetother
onResetCaptureother
onSubmitother
onSubmitCaptureother
onInvalidother
onInvalidCaptureother
onLoadother
onLoadCaptureother
onErrorother
onErrorCaptureother
onKeyDownother
onKeyDownCaptureother
onKeyPressother
onKeyPressCaptureother
onKeyUpother
onKeyUpCaptureother
onAbortother
onAbortCaptureother
onCanPlayother
onCanPlayCaptureother
onCanPlayThroughother
onCanPlayThroughCaptureother
onDurationChangeother
onDurationChangeCaptureother
onEmptiedother
onEmptiedCaptureother
onEncryptedother
onEncryptedCaptureother
onEndedother
onEndedCaptureother
onLoadedDataother
onLoadedDataCaptureother
onLoadedMetadataother
onLoadedMetadataCaptureother
onLoadStartother
onLoadStartCaptureother
onPauseother
onPauseCaptureother
onPlayother
onPlayCaptureother
onPlayingother
onPlayingCaptureother
onProgressother
onProgressCaptureother
onRateChangeother
onRateChangeCaptureother
onResizeother
onResizeCaptureother
onSeekedother
onSeekedCaptureother
onSeekingother
onSeekingCaptureother
onStalledother
onStalledCaptureother
onSuspendother
onSuspendCaptureother
onTimeUpdateother
onTimeUpdateCaptureother
onVolumeChangeother
onVolumeChangeCaptureother
onWaitingother
onWaitingCaptureother
onAuxClickother
onAuxClickCaptureother
onClickother
onClickCaptureother
onContextMenuother
onContextMenuCaptureother
onDoubleClickother
onDoubleClickCaptureother
onDragother
onDragCaptureother
onDragEndother
onDragEndCaptureother
onDragEnterother
onDragEnterCaptureother
onDragExitother
onDragExitCaptureother
onDragLeaveother
onDragLeaveCaptureother
onDragOverother
onDragOverCaptureother
onDragStartother
onDragStartCaptureother
onDropother
onDropCaptureother
onMouseDownother
onMouseDownCaptureother
onMouseEnterother
onMouseLeaveother
onMouseMoveother
onMouseMoveCaptureother
onMouseOutother
onMouseOutCaptureother
onMouseOverother
onMouseOverCaptureother
onMouseUpother
onMouseUpCaptureother
onSelectother
onSelectCaptureother
onTouchCancelother
onTouchCancelCaptureother
onTouchEndother
onTouchEndCaptureother
onTouchMoveother
onTouchMoveCaptureother
onTouchStartother
onTouchStartCaptureother
onPointerDownother
onPointerDownCaptureother
onPointerMoveother
onPointerMoveCaptureother
onPointerUpother
onPointerUpCaptureother
onPointerCancelother
onPointerCancelCaptureother
onPointerEnterother
onPointerLeaveother
onPointerOverother
onPointerOverCaptureother
onPointerOutother
onPointerOutCaptureother
onGotPointerCaptureother
onGotPointerCaptureCaptureother
onLostPointerCaptureother
onLostPointerCaptureCaptureother
onScrollother
onScrollCaptureother
onWheelother
onWheelCaptureother
onAnimationStartother
onAnimationStartCaptureother
onAnimationEndother
onAnimationEndCaptureother
onAnimationIterationother
onAnimationIterationCaptureother
onTransitionEndother
onTransitionEndCaptureother
suffixotherSuffix to show after the field
errorotherError message
hintotherHint
labelotherLabel

When to use this component

Use the text input component when you need to let users enter text that’s no longer than a single line, such as their name or phone number.

When not to use this component

Do not use the text input component if you need to let users enter longer answers that might span multiple lines. In this case, you should use the textarea component.

How it works

All text inputs must have visible labels; placeholder text is not an acceptable replacement for a label as it vanishes when users start typing.

Labels should be aligned above the text input they refer to. They should be short, direct and written in sentence case. Do not use colons at the end of labels.

If you’re asking just one question per page as recommended, you can set the contents of the <label> as the page heading. This is good practice as it means that users of screen readers will only hear the contents once.

Read more about why and how to set legends as headings.

<div id="event-name" class="govuk-form-group">
  <label for="event-name-input" class="govuk-label">
    <h1 class="govuk-heading-l">
      What is the name of the event?
    </h1>
  </label>
  <input
    name="event-name"
    id="event-name-input"
    class="govuk-input"
    type="text"
  />
</div>
<TextInput
  label={
    <h1 className="govuk-heading-l">
      What is the name of the event?
    </h1>
  }
  name="event-name"
/>

If you’re asking more than one question on the page

If you’re asking more than one question on the page, do not set the contents of the <label> as the page heading. Read more about asking multiple questions on question pages.

<div id="event-name" class="govuk-form-group">
  <label for="event-name-input" class="govuk-label">
    What is the name of the event?
  </label>
  <input
    name="event-name"
    id="event-name-input"
    class="govuk-input"
    type="text"
  />
</div>
<TextInput
  label="What is the name of the event?"
  name="event-name"
/>

Use appropriately-sized text inputs

Help users understand what they should enter by making text inputs the right size for the content they’re intended for.

By default, the width of text inputs is fluid and will fit the full width of the container they are placed into.

If you want to make the input smaller, you can either use a fixed width input, or use the width override classes to create a smaller, fluid width input.

Fixed width inputs

Use fixed width inputs for content that has a specific, known length. Postcode inputs should be postcode-sized, telephone number inputs should be telephone number-sized.

The widths are designed for specific character lengths and to be consistent across a range of browsers. They include extra padding to fit icons that some browsers might insert into the input (for example to show or generate a password).

On fixed width inputs, the width will remain fixed on all screens unless it is wider than the viewport, in which case it will shrink to fit.

<div id="width-20" class="govuk-form-group">
  <label for="width-20-input" class="govuk-label">
    20 character width
  </label>
  <input
    name="width-20"
    id="width-20-input"
    class="govuk-input"
    style="max-width:40.96ex"
    type="text"
  />
</div>
<div id="width-10" class="govuk-form-group">
  <label for="width-10-input" class="govuk-label">
    10 character width
  </label>
  <input
    name="width-10"
    id="width-10-input"
    class="govuk-input"
    style="max-width:22.86ex"
    type="text"
  />
</div>
<div id="width-5" class="govuk-form-group">
  <label for="width-5-input" class="govuk-label">
    5 character width
  </label>
  <input
    name="width-5"
    id="width-5-input"
    class="govuk-input"
    style="max-width:10.81ex"
    type="text"
  />
</div>
<div id="width-4" class="govuk-form-group">
  <label for="width-4-input" class="govuk-label">
    4 character width
  </label>
  <input
    name="width-4"
    id="width-4-input"
    class="govuk-input"
    style="max-width:9ex"
    type="text"
  />
</div>
<div id="width-3" class="govuk-form-group">
  <label for="width-3-input" class="govuk-label">
    3 character width
  </label>
  <input
    name="width-3"
    id="width-3-input"
    class="govuk-input"
    style="max-width:7.1899999999999995ex"
    type="text"
  />
</div>
<div id="width-2" class="govuk-form-group">
  <label for="width-2-input" class="govuk-label">
    2 character width
  </label>
  <input
    name="width-2"
    id="width-2-input"
    class="govuk-input"
    style="max-width:5.38ex"
    type="text"
  />
</div>
<>
  <TextInput
    label="20 character width"
    name="width-20"
    width="20"
  />
  <TextInput
    label="10 character width"
    name="width-10"
    width="10"
  />
  <TextInput
    label="5 character width"
    name="width-5"
    width="5"
  />
  <TextInput
    label="4 character width"
    name="width-4"
    width="4"
  />
  <TextInput
    label="3 character width"
    name="width-3"
    width="3"
  />
  <TextInput
    label="2 character width"
    name="width-2"
    width="2"
  />
</>

Fluid width inputs

Use the width override classes to reduce the width of an input in relation to its parent container, for example, to two-thirds.

Fluid width inputs will resize with the viewport.

<div id="full" class="govuk-form-group">
  <label for="full-input" class="govuk-label">
    Full width
  </label>
  <input
    name="full"
    id="full-input"
    class="govuk-input govuk-!-width-full"
    type="text"
  />
</div>
<div id="three-quarters" class="govuk-form-group">
  <label
    for="three-quarters-input"
    class="govuk-label"
  >
    Three-quarters width
  </label>
  <input
    name="three-quarters"
    id="three-quarters-input"
    class="govuk-input govuk-!-width-three-quarters"
    type="text"
  />
</div>
<div id="two-thirds" class="govuk-form-group">
  <label for="two-thirds-input" class="govuk-label">
    Two-thirds width
  </label>
  <input
    name="two-thirds"
    id="two-thirds-input"
    class="govuk-input govuk-!-width-two-thirds"
    type="text"
  />
</div>
<div id="one-half" class="govuk-form-group">
  <label for="one-half-input" class="govuk-label">
    One-half width
  </label>
  <input
    name="one-half"
    id="one-half-input"
    class="govuk-input govuk-!-width-one-half"
    type="text"
  />
</div>
<div id="one-third" class="govuk-form-group">
  <label for="one-third-input" class="govuk-label">
    One-third width
  </label>
  <input
    name="one-third"
    id="one-third-input"
    class="govuk-input govuk-!-width-one-third"
    type="text"
  />
</div>
<div id="one-quarter" class="govuk-form-group">
  <label for="one-quarter-input" class="govuk-label">
    One-quarter width
  </label>
  <input
    name="one-quarter"
    id="one-quarter-input"
    class="govuk-input govuk-!-width-one-quarter"
    type="text"
  />
</div>
<>
  <TextInput
    label="Full width"
    name="full"
    className="govuk-!-width-full"
  />
  <TextInput
    label="Three-quarters width"
    name="three-quarters"
    className="govuk-!-width-three-quarters"
  />
  <TextInput
    label="Two-thirds width"
    name="two-thirds"
    className="govuk-!-width-two-thirds"
  />
  <TextInput
    label="One-half width"
    name="one-half"
    className="govuk-!-width-one-half"
  />
  <TextInput
    label="One-third width"
    name="one-third"
    className="govuk-!-width-one-third"
  />
  <TextInput
    label="One-quarter width"
    name="one-quarter"
    className="govuk-!-width-one-quarter"
  />
</>

Hint text

Use hint for help that’s relevant to the majority of users, like how their information will be used, or where to find it.

The name you’ll use on promotional material.
<div id="event-name" class="govuk-form-group">
  <label for="event-name-input" class="govuk-label">
    <h1 class="govuk-heading-l">
      What is the name of the event?
    </h1>
  </label>
  <div id="event-name-hint" class="govuk-hint">
    The name you’ll use on promotional material.
  </div>
  <input
    name="event-name"
    aria-describedby="event-name-hint"
    id="event-name-input"
    class="govuk-input"
    type="text"
  />
</div>
<TextInput
  label={
    <h1 className="govuk-heading-l">
      What is the name of the event?
    </h1>
  }
  name="event-name"
  hint="The name you’ll use on promotional material."
/>

When not to use hint text

Do not use long paragraphs and lists in hint text. Screen readers read out the entire text when users interact with the form element. This could frustrate users if the text is long.

Avoid links

Do not include links within hint text. While screen readers will read out the link text when describing the field, they will not tell users that the text is a link.

Numbers

Asking for whole numbers

If you’re asking the user to enter a whole number and you want to bring up the numeric keypad on a mobile device, set the inputMode attribute to numeric and the pattern attribute to [0-9]*. See how to do this in the HTML and Nunjucks tabs in the following example.

Must be between 6 and 8 digits long
<div id="account-number" class="govuk-form-group">
  <label
    for="account-number-input"
    class="govuk-label"
  >
    <h1 class="govuk-heading-l">
      What is your account number?
    </h1>
  </label>
  <div id="account-number-hint" class="govuk-hint">
    Must be between 6 and 8 digits long
  </div>
  <input
    name="account-number"
    inputmode="numeric"
    pattern="[0-9]*"
    aria-describedby="account-number-hint"
    id="account-number-input"
    class="govuk-input"
    style="max-width:22.86ex"
    type="text"
  />
</div>
<TextInput
  label={
    <h1 className="govuk-heading-l">
      What is your account number?
    </h1>
  }
  name="account-number"
  hint="Must be between 6 and 8 digits long"
  inputMode="numeric"
  pattern="[0-9]*"
  width={10}
/>

You should also turn off HTML5 validation to prevent browsers from validating the pattern attribute.

There is specific guidance on how to ask for:

Asking for decimal numbers

If you’re asking the user to enter a number that might include decimal places, use input type="text" without inputMode or pattern attributes.

Do not set the inputMode attribute to decimal as it causes some devices to bring up a keypad without a key for the decimal separator.

<div id="weight" class="govuk-form-group">
  <label for="weight-input" class="govuk-label">
    Weight, in kilograms
  </label>
  <div class="govuk-input__wrapper">
    <input
      name="weight"
      id="weight-input"
      class="govuk-input"
      style="max-width:10.81ex"
      type="text"
    />
    <div
      class="govuk-input__suffix"
      aria-hidden="true"
    >
      kg
    </div>
  </div>
</div>
<TextInput
  label="Weight, in kilograms"
  name="weight"
  width={5}
  suffix="kg"
/>

Avoid using inputs with a type of number

Do not use <input type="number"> unless your user research shows that there’s a need for it. With <input type="number"> there’s a risk of users accidentally incrementing a number when they’re trying to do something else - for example, scroll up or down the page. And if the user tries to enter something that’s not a number, there’s no explicit feedback about what they’re doing wrong.

Prefixes and suffixes

Use prefixes and suffixes to help users enter things like currencies and measurements.

<div id="cost-per-item" class="govuk-form-group">
  <label
    for="cost-per-item-input"
    class="govuk-label"
  >
    <h1 class="govuk-heading-l">
      What is the cost per item, in pounds?
    </h1>
  </label>
  <div class="govuk-input__wrapper">
    <div
      class="govuk-input__prefix"
      aria-hidden="true"
    >
      £
    </div>
    <input
      name="cost-per-item"
      id="cost-per-item-input"
      class="govuk-input"
      style="max-width:10.81ex"
      type="text"
    />
    <div
      class="govuk-input__suffix"
      aria-hidden="true"
    >
      per item
    </div>
  </div>
</div>
<TextInput
  label={
    <h1 className="govuk-heading-l">
      What is the cost per item, in pounds?
    </h1>
  }
  name="cost-per-item"
  width={5}
  prefix="£"
  suffix="per item"
/>

Prefixes and suffixes are useful when there’s a commonly understood symbol or abbreviation for the type of information you’re asking for. Do not rely on prefixes or suffixes alone, because screen readers will not read them out.

If you need a specific type of information, say so in the input label or hint text as well. For example, put ‘Cost, in pounds’ in the input label and use the ‘£’ symbol in the prefix.

Position prefixes and suffixes so that they’re outside of their input. This is to avoid interfering with some browsers that might insert an icon into the input (for example to show or generate a password).

Some users may miss that the input already has a suffix or prefix, and enter a prefix or suffix into the input. Allow for this in your validation and do not show an error.

Text inputs with a prefix

<div id="cost" class="govuk-form-group">
  <label for="cost-input" class="govuk-label">
    <h1 class="govuk-heading-l">
      What is the cost in pounds?
    </h1>
  </label>
  <div class="govuk-input__wrapper">
    <div
      class="govuk-input__prefix"
      aria-hidden="true"
    >
      £
    </div>
    <input
      name="cost"
      id="cost-input"
      class="govuk-input"
      style="max-width:10.81ex"
      type="text"
    />
  </div>
</div>
<TextInput
  label={
    <h1 className="govuk-heading-l">
      What is the cost in pounds?
    </h1>
  }
  name="cost"
  width={5}
  prefix="£"
/>

Text inputs with a suffix

<div id="weight" class="govuk-form-group">
  <label for="weight-input" class="govuk-label">
    <h1 class="govuk-heading-l">
      What is the weight in kilograms?
    </h1>
  </label>
  <div class="govuk-input__wrapper">
    <input
      name="weight"
      id="weight-input"
      class="govuk-input"
      style="max-width:10.81ex"
      type="text"
    />
    <div
      class="govuk-input__suffix"
      aria-hidden="true"
    >
      kg
    </div>
  </div>
</div>
<TextInput
  label={
    <h1 className="govuk-heading-l">
      What is the weight in kilograms?
    </h1>
  }
  name="weight"
  width={5}
  suffix="kg"
/>

Use the autoComplete prop

Use the autoComplete attribute / prop on text inputs to help users complete forms more quickly. This lets you specify an input’s purpose so browsers can autofill the information on a user’s behalf if they’ve entered it previously.

For example, to enable autofill on a postcode field, set the autoComplete prop to postal-code. See how to do this in the HTML and Nunjucks tabs in the following example.

<div id="postcode" class="govuk-form-group">
  <label for="postcode-input" class="govuk-label">
    Postcode
  </label>
  <input
    name="postcode"
    autocomplete="postal-code"
    id="postcode-input"
    class="govuk-input"
    style="max-width:22.86ex"
    type="text"
  />
</div>
<TextInput
  label="Postcode"
  name="postcode"
  width="10"
  autoComplete="postal-code"
/>

If you are working in production and there is a relevant input purpose, you’ll need to use the autoComplete attribute to meet WCAG 2.1 Level AA.

You will not normally need to use the autoComplete attribute in prototypes, as users will not generally be using their own devices.

Do not disable copy and paste

Users often need to copy and paste information into a text input, so do not stop them from doing this.

How and when to spellcheck a user’s input

Sometimes, browsers will spellcheck the information a user puts into a text input. If a user enters something which is recognised as a spelling error, sighted users will see a red line under the word.

If you are asking users for information which is not appropriate to spellcheck, like a reference number, name, email address or National Insurance number, disable the spellcheck.

To do this set the spellCheck attribute to false as shown in this example.

<div id="name" class="govuk-form-group">
  <label for="name-input" class="govuk-label">
    Name
  </label>
  <input
    name="name"
    spellcheck="false"
    id="name-input"
    class="govuk-input"
    type="text"
  />
</div>
<TextInput
  label="Name"
  name="name"
  spellCheck={false}
/>

Browsers do not consistently spellcheck user’s input by default. If you are asking a question where spellcheck would be useful, set the spellCheck attribute to true.

<div id="description" class="govuk-form-group">
  <label for="description-input" class="govuk-label">
    Description
  </label>
  <input
    name="description"
    spellcheck="true"
    id="description-input"
    class="govuk-input"
    type="text"
  />
</div>
<TextInput
  label="Description"
  name="description"
  spellCheck
/>

Error messages

Error messages should be styled like this:

The name you’ll use on promotional material.

Error: Enter an event name

<div
  id="event-name"
  class="govuk-form-group govuk-form-group--error"
>
  <label for="event-name-input" class="govuk-label">
    <h1 class="govuk-heading-l">
      What is the name of the event?
    </h1>
  </label>
  <div id="event-name-hint" class="govuk-hint">
    The name you’ll use on promotional material.
  </div>
  <p
    id="event-name-error"
    class="govuk-error-message"
  >
    <span class="govuk-visually-hidden">Error:</span>
    Enter an event name
  </p>
  <input
    name="event-name"
    aria-describedby="event-name-hint event-name-error"
    id="event-name-input"
    class="govuk-input govuk-input--error"
    type="text"
  />
</div>
<TextInput
  label={
    <h1 className="govuk-heading-l">
      What is the name of the event?
    </h1>
  }
  name="event-name"
  hint="The name you’ll use on promotional material."
  error="Enter an event name"
/>

If the input has a prefix or a suffix

Error: Enter a cost per item, in pounds

<div
  id="cost-per-item"
  class="govuk-form-group govuk-form-group--error"
>
  <label
    for="cost-per-item-input"
    class="govuk-label"
  >
    <h1 class="govuk-heading-l">
      What is the cost per item, in pounds?
    </h1>
  </label>
  <p
    id="cost-per-item-error"
    class="govuk-error-message"
  >
    <span class="govuk-visually-hidden">Error:</span>
    Enter a cost per item, in pounds
  </p>
  <div class="govuk-input__wrapper">
    <div
      class="govuk-input__prefix"
      aria-hidden="true"
    >
      £
    </div>
    <input
      name="cost-per-item"
      aria-describedby="cost-per-item-error"
      id="cost-per-item-input"
      class="govuk-input govuk-input--error"
      style="max-width:10.81ex"
      type="text"
    />
    <div
      class="govuk-input__suffix"
      aria-hidden="true"
    >
      per item
    </div>
  </div>
</div>
<TextInput
  label={
    <h1 className="govuk-heading-l">
      What is the cost per item, in pounds?
    </h1>
  }
  name="cost-per-item"
  width={5}
  prefix="£"
  suffix="per item"
  error="Enter a cost per item, in pounds"
/>

Make sure errors follow the guidance in error message and have specific error messages for specific error states.

If the input is empty

Say ‘Enter [whatever it is]’. For example, ‘Enter your first name’.

If the input is too long

Say ‘[whatever it is] must be [number] characters or fewer’. For example, ‘Address line 1 must be 35 characters or fewer’.

If the input is too short

Say ‘[whatever it is] must be [number] characters or more’. For example, ‘Full name must be 2 characters or more’.

If the input is too long or too short

Say ‘[whatever it is] must be between [number] and [number] characters’. For example, ‘Last name must be between 2 and 35 characters’.

If the input uses characters that are not allowed and you know what the characters are

Say ‘[whatever it is] must not include [characters]’. For example, ‘Town or city must not include è and £’.

If the input uses characters that are not allowed and you do not know what the characters are

Say ‘[whatever it is] must only include [list of allowed characters]’. For example, ‘Full name must only include letters a to z, hyphens, spaces and apostrophes’.

If the input is not a number

Say ‘[whatever it is] must be a number [optional example]’. For example, ‘Hours worked a week must be a number, like 30’.

If the input is not a whole number

Say ‘[whatever it is] must be a whole number [optional example]’. For example, ‘Hours worked a week must be a whole number, like 30’.

If the number is too low

Say ‘[whatever it is] must be [lowest] or more’. For example, ‘Hours worked a week must be 16 or more’.

If the number is too high

Say ‘[whatever it is] must be [highest] or fewer’. For example, ‘Hours worked a week must be 99 or fewer’.

If the input must be between 2 numbers

Say ‘[whatever it is] must be between [lowest] and [highest]’. For example, ‘Hours worked a week must be between 16 and 99’.

If the input is not an amount of money and the field allows decimals

Say ‘[whatever it is] must be an amount of money [optional example that includes decimals and non-decimals]’. For example, ‘How much you earn an hour must be an amount of money, like 7.50 or 8’.

If the input is not an amount of money and the field needs decimals

Say ‘[whatever it is] must be an amount of money [optional example that includes decimals]’. For example, ‘How much you earn an hour must be an amount of money, like 7.50 or 8.00’.

If the input is an amount of money that needs decimals

Say ‘[whatever it is] must include pence, like 123.45 or 156.00’. For example, ‘How much you earn a week must include pence, like 123.45 or 156.00’.

If the input is an amount of money that must not have decimals

Say ‘[whatever it is] must not include pence, like 123 or 156’. For example, ‘How much you earn a week must not include pence, like 123 or 156’.