1. Government Frontend Component Guide
  2. Search

Component

Search

Search box

A search box with label and attached submit button. The component must be used within an HTML form. The search input has a name=”q” attribute and a customisable ID and NAME.

It can be used on white or on govuk-blue using the on_govuk_blue option.

Markup such as heading tags can be included in the label using the label_text option. Styling is not included in the component for heading tags in labels, however this is what the search results page does.

Search for usage of this component on GitHub

How it looks (preview all)

How to call this component

<%= render "govuk_publishing_components/components/search", {
} %>

Accessibility acceptance criteria

The search box should:

  • be used inside a form with the role of ‘search’, to indicate it as a search landmark
  • have a clear label to identify the search functionality, which is visible to all users

Other examples

Apply custom styling to the label and set search value (preview)

<%= render "govuk_publishing_components/components/search", {
  inline_label: false,
  label_text: sanitize("<h1>Search GOV.UK</h1>"),
  value: "driving licence"
} %>

Stop the label appearing inline (preview)

<%= render "govuk_publishing_components/components/search", {
  inline_label: false
} %>

For use on govuk blue background (preview)

<%= render "govuk_publishing_components/components/search", {
  on_govuk_blue: true
} %>

Change label text (preview)

<%= render "govuk_publishing_components/components/search", {
  label_text: "Search"
} %>

Set id for search input (preview)

<%= render "govuk_publishing_components/components/search", {
  id: "my_unique_id"
} %>

Large version (preview)

<%= render "govuk_publishing_components/components/search", {
  size: "large"
} %>

Change field name (preview)

To be used if you need to change the default name ‘q’

<%= render "govuk_publishing_components/components/search", {
  name: "my_own_fieldname"
} %>

With aria controls attribute (preview)

The aria-controls attribute is a ‘relationship attribute’ which denotes which elements in a page an interactive element or set of elements has control over and affects. For places like the finders where the page is updated dynamically after value changes to the input.

<%= render "govuk_publishing_components/components/search", {
  aria_controls: "wrapper"
} %>