- iOS:
searchBar, configureAppearance(for:)in govuk-once/govuk-mobile-ios-app/Production/govuk_ios/ViewControllers/HomeViewController.swift at 1e520fc1 - iOS:
SearchBarViewin govuk-once/govuk-mobile-ios-app/Production/govuk_ios/SwiftUIViews/SearchBarView.swift at 1e520fc1 - iOS:
fills.surfaceSearchin govuk-once/govuk-mobile-ios-gov-kit/GovKitUI/Sources/Colors/GOVUKColors+Fills.swift at 8a7641e - Figma: none linked yet
- Apple Human Interface Guidelines: Search fields
- Material Symbols, the icons it draws
Search field
Lets the user type what they're looking for and search for it, such as searching GOV.UK from the home screen, or filtering a list of countries.
Native component
Searching
When the user taps the field, Cancel appears beside it, and stays until they press it, as on the app’s home screen. While they type, a button in the field clears what they typed. Cancel clears it too, and puts the field back as it was. Try it in the header below.
Driving and transport. Money and tax. Benefits. Care.
Driving and transport. Money and tax. Benefits. Care.
Pressing Search on the keyboard sends the form to its action, with what the user typed as q, so a prototype of several pages can show a page of results for it:
<govuk-app-search-field action="results.html"></govuk-app-search-field>
In the app, starting a search swaps the home screen’s widgets for the user’s previous searches, and Cancel swaps them back. To do the same in one page, listen for the field being focused and for Cancel being pressed:
document.addEventListener('focusin', event => {
if (event.target.matches('[type="search"]')) showPreviousSearches()
})
document.addEventListener('click', event => {
if (event.target.closest('button[name="cancel"]')) showWidgets()
})
Icons
The app’s magnifier and clear button are SF Symbols, which may only be used on Apple’s platforms, so the field draws Material Symbols instead, rounded: search and cancel.
Known differences from the app
- The app’s snapshots only show the field before the user taps it. While they are searching, the field draws Cancel as the app’s code sets it, as text. iOS 26 may draw it differently.
- The field shows it is being typed in by its caret and Cancel, as iOS does, without the yellow focus outline other components have.
- The keyboard is the phone’s or computer’s own, not iOS’s.
Examples
Empty
HTML
<govuk-app-search-field></govuk-app-search-field>
With a search typed in
HTML
<govuk-app-search-field value="Renew passport"></govuk-app-search-field>
Searching a list
HTML
<govuk-app-search-field label="Search for a country"></govuk-app-search-field>
Going to a page of results
HTML
<govuk-app-search-field action="#results"></govuk-app-search-field>
Inputs
| Attribute | Type | Default | Description |
|---|---|---|---|
placeholder |
string |
Search |
What the field says while it's empty, and its name for screen readers unless it has a label. |
label |
string |
Its name for screen readers, if the placeholder doesn't say what it searches, such as Search for a country. | |
value |
string |
What is already typed in the field, such as the search the user made to get to a page of results. | |
name |
string |
q |
The name what the user typed is sent under when they search. |
action |
string |
The page to go to when the user searches, such as a page of results. Without it, the same page, with what they typed added to its address. |
Content
Nothing.
Outputs
input: From the field, each time the text changes, including when Clear or Cancel empties it.submit: From its form, when the user presses Search on the keyboard. The form then goes to its action.click: From Cancel, a button named cancel, when it is pressed, after it has cleared the field. Listen for it to put back what the search covered, such as the home screen's widgets.
Rules
- On the home screen, put it in the <govuk-app-home-header>. Elsewhere, put it at the top of the content, above what it searches.
- Leave the placeholder as Search, as the app does everywhere. Where the field searches something narrower than GOV.UK, such as a list of countries, say so to screen readers with a label.
- Give it an action to go to a page of results in a prototype of several pages.
When not to use it
| When | Use instead |
|---|---|
| To search for something on a card of its own, such as a vehicle's registration | govuk-app-search-box |
| To ask a question the user answers to carry on, such as their postcode | govuk-app-text-field type="postcode" |
| To ask GOV.UK Chat | govuk-app-chat-input |
iOS