Unofficial
Internal
Search box
Unofficial Experimental
A single-line, form field for searching, with submit button.
(Heavily inspired by the Search component in the GOV.UK Component Guide.)
<form
method="get"
action="https://www.google.co.uk/search"
>
<div
id="q"
class="govuk-form-group govuk-form-group--standalone not-govuk-standalone-input not-govuk-standalone-input--fixed-width not-govuk-search-box"
>
<label
for="q-input"
class="govuk-label govuk-label--hidden"
aria-hidden="true"
>
Search Google
</label>
<input
name="q"
id="q-input"
placeholder="Search Google"
class="govuk-input govuk-input--fixed-width not-govuk-standalone-input__input"
style="max-width:31.910000000000004ex"
type="text"
/>
<button
data-module="govuk-button"
type="submit"
class="govuk-button not-govuk-standalone-input__button"
>
Search
<svg
class="not-govuk-search-box__icon"
width="27"
height="27"
viewBox="0 0 27 27"
fill="none"
xmlns="http://www.w3.org/2000/svg"
aria-hidden="true"
focusable="false"
>
<circle
cx="12.0161"
cy="11.0161"
r="8.51613"
stroke="currentColor"
stroke-width="3"
></circle>
<line
x1="17.8668"
y1="17.3587"
x2="26.4475"
y2="25.9393"
stroke="currentColor"
stroke-width="3"
></line>
</svg>
</button>
</div>
</form>
<form
method="get"
action="https://www.google.co.uk/search"
>
<SearchBox
name="q"
label="Search Google"
width={15}
/>
</form>
Props
Name | Type | Default | Description |
---|---|---|---|
id | other | 'id' attribute to place on the base HTML element | |
classBlock | other | Block name override in BEM style classes applied to all elements | |
classModifiers | other | BEM style modifiers to apply to the base HTML element | |
className | other | Extra classes to apply to the base HTML element | |
accept | other | ||
alt | other | ||
autoComplete | other | ||
capture | other | ||
checked | other | ||
disabled | other | ||
form | other | ||
formAction | other | ||
formEncType | other | ||
formMethod | other | ||
formNoValidate | other | ||
formTarget | other | ||
height | other | ||
list | other | ||
max | other | ||
maxLength | other | ||
min | other | ||
minLength | other | ||
multiple | other | ||
name | string | HTML name | |
pattern | other | ||
placeholder | other | ||
readOnly | other | ||
required | other | ||
size | other | ||
src | other | ||
step | other | ||
type | other | ||
value | other | ||
width | other | Width of the field in characters (approximate) | |
onChange | other | ||
defaultChecked | other | ||
defaultValue | other | ||
suppressContentEditableWarning | other | ||
suppressHydrationWarning | other | ||
accessKey | other | ||
autoCapitalize | other | ||
autoFocus | other | ||
contentEditable | other | ||
contextMenu | other | ||
dir | other | ||
draggable | other | ||
enterKeyHint | other | ||
hidden | other | ||
lang | other | ||
nonce | other | ||
slot | other | ||
spellCheck | other | ||
style | other | ||
tabIndex | other | ||
title | other | ||
translate | other | ||
radioGroup | other | ||
role | other | ||
about | other | ||
content | other | ||
datatype | other | ||
inlist | other | ||
prefix | other | Prefix to show before the field | |
property | other | ||
rel | other | ||
resource | other | ||
rev | other | ||
typeof | other | ||
vocab | other | ||
autoCorrect | other | ||
autoSave | other | ||
color | other | ||
itemProp | other | ||
itemScope | other | ||
itemType | other | ||
itemID | other | ||
itemRef | other | ||
results | other | ||
security | other | ||
unselectable | other | ||
inputMode | other | Hints at the type of data that might be entered by the user while editing the element or its contents | |
is | other | Specify that a standard HTML element should behave like a defined custom built-in element | |
aria-activedescendant | other | Identifies the currently active element when DOM focus is on a composite widget, textbox, group, or application. | |
aria-atomic | other | Indicates 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-autocomplete | other | Indicates 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-braillelabel | other | Defines a string value that labels the current element, which is intended to be converted into Braille. | |
aria-brailleroledescription | other | Defines a human-readable, author-localized abbreviated description for the role of an element, which is intended to be converted into Braille. | |
aria-busy | other | ||
aria-checked | other | Indicates the current "checked" state of checkboxes, radio buttons, and other widgets. | |
aria-colcount | other | Defines the total number of columns in a table, grid, or treegrid. | |
aria-colindex | other | Defines an element's column index or position with respect to the total number of columns within a table, grid, or treegrid. | |
aria-colindextext | other | Defines a human readable text alternative of aria-colindex. | |
aria-colspan | other | Defines the number of columns spanned by a cell or gridcell within a table, grid, or treegrid. | |
aria-controls | other | Identifies the element (or elements) whose contents or presence are controlled by the current element. | |
aria-current | other | Indicates the element that represents the current item within a container or set of related elements. | |
aria-describedby | other | Identifies the element (or elements) that describes the object. | |
aria-description | other | Defines a string value that describes or annotates the current element. | |
aria-details | other | Identifies the element that provides a detailed, extended description for the object. | |
aria-disabled | other | Indicates that the element is perceivable but disabled, so it is not editable or otherwise operable. | |
aria-dropeffect | other | Indicates what functions can be performed when a dragged object is released on the drop target. | |
aria-errormessage | other | Identifies the element that provides an error message for the object. | |
aria-expanded | other | Indicates whether the element, or another grouping element it controls, is currently expanded or collapsed. | |
aria-flowto | other | Identifies 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-grabbed | other | Indicates an element's "grabbed" state in a drag-and-drop operation. | |
aria-haspopup | other | Indicates the availability and type of interactive popup element, such as menu or dialog, that can be triggered by an element. | |
aria-hidden | other | Indicates whether the element is exposed to an accessibility API. | |
aria-invalid | other | Indicates the entered value does not conform to the format expected by the application. | |
aria-keyshortcuts | other | Indicates keyboard shortcuts that an author has implemented to activate or give focus to an element. | |
aria-label | other | Defines a string value that labels the current element. | |
aria-labelledby | other | Identifies the element (or elements) that labels the current element. | |
aria-level | other | Defines the hierarchical level of an element within a structure. | |
aria-live | other | Indicates 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-modal | other | Indicates whether an element is modal when displayed. | |
aria-multiline | other | Indicates whether a text box accepts multiple lines of input or only a single line. | |
aria-multiselectable | other | Indicates that the user may select more than one item from the current selectable descendants. | |
aria-orientation | other | Indicates whether the element's orientation is horizontal, vertical, or unknown/ambiguous. | |
aria-owns | other | Identifies 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-placeholder | other | Defines 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-posinset | other | Defines 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-pressed | other | Indicates the current "pressed" state of toggle buttons. | |
aria-readonly | other | Indicates that the element is not editable, but is otherwise operable. | |
aria-relevant | other | Indicates what notifications the user agent will trigger when the accessibility tree within a live region is modified. | |
aria-required | other | Indicates that user input is required on the element before a form may be submitted. | |
aria-roledescription | other | Defines a human-readable, author-localized description for the role of an element. | |
aria-rowcount | other | Defines the total number of rows in a table, grid, or treegrid. | |
aria-rowindex | other | Defines an element's row index or position with respect to the total number of rows within a table, grid, or treegrid. | |
aria-rowindextext | other | Defines a human readable text alternative of aria-rowindex. | |
aria-rowspan | other | Defines the number of rows spanned by a cell or gridcell within a table, grid, or treegrid. | |
aria-selected | other | Indicates the current "selected" state of various widgets. | |
aria-setsize | other | Defines 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-sort | other | Indicates if items in a table or grid are sorted in ascending or descending order. | |
aria-valuemax | other | Defines the maximum allowed value for a range widget. | |
aria-valuemin | other | Defines the minimum allowed value for a range widget. | |
aria-valuenow | other | Defines the current value for a range widget. | |
aria-valuetext | other | Defines the human readable text alternative of aria-valuenow for a range widget. | |
dangerouslySetInnerHTML | other | ||
onCopy | other | ||
onCopyCapture | other | ||
onCut | other | ||
onCutCapture | other | ||
onPaste | other | ||
onPasteCapture | other | ||
onCompositionEnd | other | ||
onCompositionEndCapture | other | ||
onCompositionStart | other | ||
onCompositionStartCapture | other | ||
onCompositionUpdate | other | ||
onCompositionUpdateCapture | other | ||
onFocus | other | ||
onFocusCapture | other | ||
onBlur | other | ||
onBlurCapture | other | ||
onChangeCapture | other | ||
onBeforeInput | other | ||
onBeforeInputCapture | other | ||
onInput | other | ||
onInputCapture | other | ||
onReset | other | ||
onResetCapture | other | ||
onSubmit | other | ||
onSubmitCapture | other | ||
onInvalid | other | ||
onInvalidCapture | other | ||
onLoad | other | ||
onLoadCapture | other | ||
onError | other | ||
onErrorCapture | other | ||
onKeyDown | other | ||
onKeyDownCapture | other | ||
onKeyPress | other | ||
onKeyPressCapture | other | ||
onKeyUp | other | ||
onKeyUpCapture | other | ||
onAbort | other | ||
onAbortCapture | other | ||
onCanPlay | other | ||
onCanPlayCapture | other | ||
onCanPlayThrough | other | ||
onCanPlayThroughCapture | other | ||
onDurationChange | other | ||
onDurationChangeCapture | other | ||
onEmptied | other | ||
onEmptiedCapture | other | ||
onEncrypted | other | ||
onEncryptedCapture | other | ||
onEnded | other | ||
onEndedCapture | other | ||
onLoadedData | other | ||
onLoadedDataCapture | other | ||
onLoadedMetadata | other | ||
onLoadedMetadataCapture | other | ||
onLoadStart | other | ||
onLoadStartCapture | other | ||
onPause | other | ||
onPauseCapture | other | ||
onPlay | other | ||
onPlayCapture | other | ||
onPlaying | other | ||
onPlayingCapture | other | ||
onProgress | other | ||
onProgressCapture | other | ||
onRateChange | other | ||
onRateChangeCapture | other | ||
onResize | other | ||
onResizeCapture | other | ||
onSeeked | other | ||
onSeekedCapture | other | ||
onSeeking | other | ||
onSeekingCapture | other | ||
onStalled | other | ||
onStalledCapture | other | ||
onSuspend | other | ||
onSuspendCapture | other | ||
onTimeUpdate | other | ||
onTimeUpdateCapture | other | ||
onVolumeChange | other | ||
onVolumeChangeCapture | other | ||
onWaiting | other | ||
onWaitingCapture | other | ||
onAuxClick | other | ||
onAuxClickCapture | other | ||
onClick | other | ||
onClickCapture | other | ||
onContextMenu | other | ||
onContextMenuCapture | other | ||
onDoubleClick | other | ||
onDoubleClickCapture | other | ||
onDrag | other | ||
onDragCapture | other | ||
onDragEnd | other | ||
onDragEndCapture | other | ||
onDragEnter | other | ||
onDragEnterCapture | other | ||
onDragExit | other | ||
onDragExitCapture | other | ||
onDragLeave | other | ||
onDragLeaveCapture | other | ||
onDragOver | other | ||
onDragOverCapture | other | ||
onDragStart | other | ||
onDragStartCapture | other | ||
onDrop | other | ||
onDropCapture | other | ||
onMouseDown | other | ||
onMouseDownCapture | other | ||
onMouseEnter | other | ||
onMouseLeave | other | ||
onMouseMove | other | ||
onMouseMoveCapture | other | ||
onMouseOut | other | ||
onMouseOutCapture | other | ||
onMouseOver | other | ||
onMouseOverCapture | other | ||
onMouseUp | other | ||
onMouseUpCapture | other | ||
onSelect | other | ||
onSelectCapture | other | ||
onTouchCancel | other | ||
onTouchCancelCapture | other | ||
onTouchEnd | other | ||
onTouchEndCapture | other | ||
onTouchMove | other | ||
onTouchMoveCapture | other | ||
onTouchStart | other | ||
onTouchStartCapture | other | ||
onPointerDown | other | ||
onPointerDownCapture | other | ||
onPointerMove | other | ||
onPointerMoveCapture | other | ||
onPointerUp | other | ||
onPointerUpCapture | other | ||
onPointerCancel | other | ||
onPointerCancelCapture | other | ||
onPointerEnter | other | ||
onPointerLeave | other | ||
onPointerOver | other | ||
onPointerOverCapture | other | ||
onPointerOut | other | ||
onPointerOutCapture | other | ||
onGotPointerCapture | other | ||
onGotPointerCaptureCapture | other | ||
onLostPointerCapture | other | ||
onLostPointerCaptureCapture | other | ||
onScroll | other | ||
onScrollCapture | other | ||
onWheel | other | ||
onWheelCapture | other | ||
onAnimationStart | other | ||
onAnimationStartCapture | other | ||
onAnimationEnd | other | ||
onAnimationEndCapture | other | ||
onAnimationIteration | other | ||
onAnimationIterationCapture | other | ||
onTransitionEnd | other | ||
onTransitionEndCapture | other | ||
suffix | other | Suffix to show after the field | |
button | other | Submit button text | |
error | other | Error message | |
hint | other | Hint | |
label | other | Label |
Stories
Standard
A standard Search box.
<div
id="q"
class="govuk-form-group govuk-form-group--standalone not-govuk-standalone-input not-govuk-search-box"
>
<label
for="q-input"
class="govuk-label govuk-label--hidden"
aria-hidden="true"
>
Search
</label>
<input
name="q"
id="q-input"
placeholder="Search"
class="govuk-input not-govuk-standalone-input__input"
type="text"
/>
<button
data-module="govuk-button"
type="submit"
class="govuk-button not-govuk-standalone-input__button"
>
Search
<svg
class="not-govuk-search-box__icon"
width="27"
height="27"
viewBox="0 0 27 27"
fill="none"
xmlns="http://www.w3.org/2000/svg"
aria-hidden="true"
focusable="false"
>
<circle
cx="12.0161"
cy="11.0161"
r="8.51613"
stroke="currentColor"
stroke-width="3"
></circle>
<line
x1="17.8668"
y1="17.3587"
x2="26.4475"
y2="25.9393"
stroke="currentColor"
stroke-width="3"
></line>
</svg>
</button>
</div>
<SearchBox name="q" />
Custom label
<div
id="q"
class="govuk-form-group govuk-form-group--standalone not-govuk-standalone-input not-govuk-search-box"
>
<label
for="q-input"
class="govuk-label govuk-label--hidden"
aria-hidden="true"
>
Query
</label>
<input
name="q"
id="q-input"
placeholder="Query"
class="govuk-input not-govuk-standalone-input__input"
type="text"
/>
<button
data-module="govuk-button"
type="submit"
class="govuk-button not-govuk-standalone-input__button"
>
Search
<svg
class="not-govuk-search-box__icon"
width="27"
height="27"
viewBox="0 0 27 27"
fill="none"
xmlns="http://www.w3.org/2000/svg"
aria-hidden="true"
focusable="false"
>
<circle
cx="12.0161"
cy="11.0161"
r="8.51613"
stroke="currentColor"
stroke-width="3"
></circle>
<line
x1="17.8668"
y1="17.3587"
x2="26.4475"
y2="25.9393"
stroke="currentColor"
stroke-width="3"
></line>
</svg>
</button>
</div>
<SearchBox name="q" label="Query" />
Hint
If you provide a hint, it will be displayed instead of the label.
<div
id="q"
class="govuk-form-group govuk-form-group--standalone not-govuk-standalone-input not-govuk-search-box"
>
<label
for="q-input"
class="govuk-label govuk-label--hidden"
aria-hidden="true"
>
Search
</label>
<div
id="q-hint"
class="govuk-hint govuk-hint--hidden"
aria-hidden="true"
>
What are you looking for?
</div>
<input
name="q"
aria-describedby="q-hint"
id="q-input"
placeholder="What are you looking for?"
class="govuk-input not-govuk-standalone-input__input"
type="text"
/>
<button
data-module="govuk-button"
type="submit"
class="govuk-button not-govuk-standalone-input__button"
>
Search
<svg
class="not-govuk-search-box__icon"
width="27"
height="27"
viewBox="0 0 27 27"
fill="none"
xmlns="http://www.w3.org/2000/svg"
aria-hidden="true"
focusable="false"
>
<circle
cx="12.0161"
cy="11.0161"
r="8.51613"
stroke="currentColor"
stroke-width="3"
></circle>
<line
x1="17.8668"
y1="17.3587"
x2="26.4475"
y2="25.9393"
stroke="currentColor"
stroke-width="3"
></line>
</svg>
</button>
</div>
<SearchBox
name="q"
hint="What are you looking for?"
/>
Custom submit button text
The text of the submit button is visually hidden, but can be customised for screen-readers.
Fixed width
<div
id="q"
class="govuk-form-group govuk-form-group--standalone not-govuk-standalone-input not-govuk-standalone-input--fixed-width not-govuk-search-box"
>
<label
for="q-input"
class="govuk-label govuk-label--hidden"
aria-hidden="true"
>
Search
</label>
<input
name="q"
id="q-input"
placeholder="Search"
class="govuk-input govuk-input--fixed-width not-govuk-standalone-input__input"
style="max-width:22.86ex"
type="text"
/>
<button
data-module="govuk-button"
type="submit"
class="govuk-button not-govuk-standalone-input__button"
>
Search
<svg
class="not-govuk-search-box__icon"
width="27"
height="27"
viewBox="0 0 27 27"
fill="none"
xmlns="http://www.w3.org/2000/svg"
aria-hidden="true"
focusable="false"
>
<circle
cx="12.0161"
cy="11.0161"
r="8.51613"
stroke="currentColor"
stroke-width="3"
></circle>
<line
x1="17.8668"
y1="17.3587"
x2="26.4475"
y2="25.9393"
stroke="currentColor"
stroke-width="3"
></line>
</svg>
</button>
</div>
<SearchBox name="q" width="10" />
Fluid width
<div
id="q"
class="govuk-form-group govuk-form-group--standalone not-govuk-standalone-input not-govuk-search-box govuk-!-width-one-half"
>
<label
for="q-input"
class="govuk-label govuk-label--hidden"
aria-hidden="true"
>
Search
</label>
<input
name="q"
id="q-input"
placeholder="Search"
class="govuk-input not-govuk-standalone-input__input"
type="text"
/>
<button
data-module="govuk-button"
type="submit"
class="govuk-button not-govuk-standalone-input__button"
>
Search
<svg
class="not-govuk-search-box__icon"
width="27"
height="27"
viewBox="0 0 27 27"
fill="none"
xmlns="http://www.w3.org/2000/svg"
aria-hidden="true"
focusable="false"
>
<circle
cx="12.0161"
cy="11.0161"
r="8.51613"
stroke="currentColor"
stroke-width="3"
></circle>
<line
x1="17.8668"
y1="17.3587"
x2="26.4475"
y2="25.9393"
stroke="currentColor"
stroke-width="3"
></line>
</svg>
</button>
</div>
<SearchBox
name="q"
className="govuk-!-width-one-half"
/>
Error
Currently errors are visually hidden, so it is best to avoid them. They will however be accessible to screen-readers, and the field will still be highlighted in red.
<div
id="q"
class="govuk-form-group govuk-form-group--error govuk-form-group--standalone not-govuk-standalone-input not-govuk-standalone-input--error not-govuk-search-box"
>
<label
for="q-input"
class="govuk-label govuk-label--hidden"
aria-hidden="true"
>
Search
</label>
<p
id="q-error"
class="govuk-error-message govuk-error-message--hidden"
aria-hidden="true"
>
<span class="govuk-visually-hidden">Error:</span>
Something went wrong
</p>
<input
name="q"
aria-describedby="q-error"
id="q-input"
placeholder="Search"
class="govuk-input govuk-input--error not-govuk-standalone-input__input"
type="text"
/>
<button
data-module="govuk-button"
type="submit"
class="govuk-button not-govuk-standalone-input__button"
>
Search
<svg
class="not-govuk-search-box__icon"
width="27"
height="27"
viewBox="0 0 27 27"
fill="none"
xmlns="http://www.w3.org/2000/svg"
aria-hidden="true"
focusable="false"
>
<circle
cx="12.0161"
cy="11.0161"
r="8.51613"
stroke="currentColor"
stroke-width="3"
></circle>
<line
x1="17.8668"
y1="17.3587"
x2="26.4475"
y2="25.9393"
stroke="currentColor"
stroke-width="3"
></line>
</svg>
</button>
</div>
<SearchBox name="q" error="Something went wrong" />
Disabled
<div
id="q"
class="govuk-form-group govuk-form-group--standalone not-govuk-standalone-input not-govuk-search-box"
>
<label
for="q-input"
class="govuk-label govuk-label--hidden"
aria-hidden="true"
>
Search
</label>
<input
name="q"
disabled=""
id="q-input"
placeholder="Search"
class="govuk-input not-govuk-standalone-input__input"
type="text"
/>
<button
aria-disabled="true"
data-module="govuk-button"
disabled=""
type="submit"
class="govuk-button not-govuk-standalone-input__button"
>
Search
<svg
class="not-govuk-search-box__icon"
width="27"
height="27"
viewBox="0 0 27 27"
fill="none"
xmlns="http://www.w3.org/2000/svg"
aria-hidden="true"
focusable="false"
>
<circle
cx="12.0161"
cy="11.0161"
r="8.51613"
stroke="currentColor"
stroke-width="3"
></circle>
<line
x1="17.8668"
y1="17.3587"
x2="26.4475"
y2="25.9393"
stroke="currentColor"
stroke-width="3"
></line>
</svg>
</button>
</div>
<SearchBox name="q" disabled />