Skip to main content

Form elements Search input

Use a search input to help users find something specific by entering a word, phrase or characters.

Open this example in a new tab: search input
<div class="nhsuk-form-group nhsuk-search-input">
  <label class="nhsuk-label nhsuk-label--s" for="example">
    Search
  </label>
  <div class="nhsuk-input-wrapper nhsuk-search-input__wrapper">
    <input class="nhsuk-input nhsuk-search-input__input nhsuk-input--width-10" id="example" name="example" type="search" autocomplete="off">
    <button class="nhsuk-button nhsuk-button--icon nhsuk-button--small nhsuk-search-input__button" data-module="nhsuk-button" type="submit" aria-label="Search">
      <svg class="nhsuk-icon nhsuk-icon--search" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="16" height="16" focusable="false" aria-hidden="true">
        <path d="m20.7 18.9-4.1-4.1a7 7 0 1 0-1.4 1.4l4 4.1a1 1 0 0 0 1.5 0c.4-.4.4-1 0-1.4ZM6 10.6a5 5 0 1 1 10 0 5 5 0 0 1-10 0Z" />
      </svg>
    </button>
  </div>
</div>
Nunjucks macro options

Use options to customise the appearance, content and behaviour of a component when using a macro, for example, changing the text.

Some options are required for the macro to work. These are marked as "Required" in the option description. Deprecated options are marked as "Deprecated".

If you're using Nunjucks macros in production with "html" options, or ones ending with "html", you must sanitise the HTML to protect against cross-site scripting exploits.

Primary options
Name Type Description
id string The ID of the input. Defaults to the value of name.
name string Required. The name of the input, which is submitted with the form data.
value string Optional initial value of the input.
disabled boolean If true, input will be disabled.
describedBy string One or more element IDs to add to the aria-describedby attribute, used to provide additional descriptive information for screenreader users.
label object Required. The label used by the search input component. See macro options for label.
hint object Can be used to add a hint to a search input component. See macro options for hint.
errorMessage object Can be used to add an error message to the search input component. The error message component will not display if you use a falsy value for errorMessage, for example false or null. See macro options for errorMessage.
prefix object Can be used to add a prefix to the search input component. See macro options for prefix.
suffix object Can be used to add a suffix to the search input component. See macro options for suffix.
code boolean If set to true, use a monospace font for codes or sequences.
width integer Optional fixed width for the search input component – 2, 3, 4, 5, 10, 20 or 30.
large boolean If set to true, larger input size will be used.
formGroup object Additional options for the form group containing the search input component. See macro options for formGroup.
classes string Classes to add to the input.
autocomplete string Attribute to meet WCAG success criterion 1.3.5: Identify input purpose, for instance "bday-day". See the Autofill section in the HTML standard for a full list of attributes that can be used. Default is "off".
pattern string Attribute to provide a regular expression pattern, used to match allowed character combinations for the input value.
inputWrapper object Additional options for the wrapping element containing the search input component. See macro options for inputWrapper.
attributes object HTML attributes (for example data attributes) to add to the input.
button object Optional object allowing customisation of the search button. See button macro options using button component macro.
Options for prefix object
Name Type Description
text string Required. Required. If html is set, this is not required. Text to use within the prefix. If html is provided, the text option will be ignored.
html string Required. Required. If text is set, this is not required. HTML to use within the prefix. If html is provided, the text option will be ignored.
classes string Classes to add to the prefix.
attributes object HTML attributes (for example data attributes) to add to the prefix element.
Options for suffix object
Name Type Description
text string Required. If html is set, this is not required. Text to use within the suffix. If html is provided, the text option will be ignored.
html string Required. If text is set, this is not required. HTML to use within the suffix. If html is provided, the text option will be ignored.
classes string Classes to add to the suffix element.
attributes object HTML attributes (for example data attributes) to add to the suffix element.
Options for formGroup object
Name Type Description
classes string Classes to add to the form group (for example to show error state for the whole group).
attributes object HTML attributes (for example data attributes) to add to the form group.
beforeInput object Content to add before the input used by the search input component. See macro options for formGroup beforeInput.
afterInput object Content to add after the input used by the search input component. See macro options for formGroup afterInput.
Options for formGroup beforeInput object
Name Type Description
text string Required. Text to add before the input. If html is provided, the text option will be ignored.
html string Required. HTML to add before the input. If html is provided, the text option will be ignored.
Options for formGroup afterInput object
Name Type Description
text string Required. Text to add after the input. If html is provided, the text option will be ignored.
html string Required. HTML to add after the input. If html is provided, the text option will be ignored.
Options for inputWrapper object
Name Type Description
classes string Classes to add to the wrapping element.
attributes object HTML attributes (for example data attributes) to add to the wrapping element.
Options for button component
Name Type Description
variant string Optional variant of search button – "brand", "login", "reverse", "secondary", "secondary-solid" or "warning".
classes string Classes to add to the search button.
ariaLabel string Button text exposed to assistive technologies, like screen readers, when only an icon is used.
icon object Can be used to add an icon to the search button. See macro options for button icon.
Options for button icon object
Name Type Description
name string Required. Icon name for the button – for example, "search", "arrow-right", "plus" or "minus".
html string Required. HTML to use for the icon, as an alternative to the name option. If html is provided, the name option will be ignored.
placement string Required. Placement of the icon within the button – "start" or "end".
Options for label component
Name Type Description
id string The ID of the label.
text string Required. If html is set, this is not required. Text to use within the label. If html is provided, the text option will be ignored.
html string Required. If text is set, this is not required. HTML to use within the label. If html is provided, the text option will be ignored.
caller nunjucks-block Not strictly a parameter but Nunjucks code convention. Using a call block enables you to call a macro with all the text inside the tag. This is helpful if you want to pass a lot of content into a macro. To use it, you will need to wrap the entire label component in a call block.
for string The value of the for attribute, the ID of the input the label is associated with.
isPageHeading boolean Whether the label also acts as the heading for the page.
size string Size of the label – "s", "m", "l" or "xl".
classes string Classes to add to the label tag.
attributes object HTML attributes (for example data attributes) to add to the label tag.
{% from "search-input/macro.njk" import searchInput %}

{{ searchInput({
  label: {
    text: "Search",
    size: "s"
  },
  name: "example",
  id: "example",
  classes: "nhsuk-input--width-10"
}) }}

When to use search input

Use the search input component to help users find a topic, person, task, place or other type of record when navigation alone is not practical.

You can enable search in the header component. Use this to provide a global search.

When not to use search input

Do not rely on search in place of a well-structured information architecture and navigation.

How to use search input

When a user types into the input, a cross icon button appears which allows users to clear the input. This is an enhancement for browsers that support it. Some browsers such as Firefox will not show it.

Open this example in a new tab: search input nhs number
<div class="nhsuk-form-group nhsuk-search-input">
  <label class="nhsuk-label nhsuk-label--m" for="example">
    Search patients
  </label>
  <div class="nhsuk-hint" id="example-hint">
    Search by name, NHS number, postcode, or date of birth
  </div>
  <div class="nhsuk-input-wrapper nhsuk-search-input__wrapper">
    <input class="nhsuk-input nhsuk-search-input__input nhsuk-input--width-10" id="example" name="example" type="search" value="LS1 4AP" aria-describedby="example-hint" autocomplete="off">
    <button class="nhsuk-button nhsuk-button--icon nhsuk-button--small nhsuk-search-input__button" data-module="nhsuk-button" type="submit" aria-label="Search">
      <svg class="nhsuk-icon nhsuk-icon--search" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="16" height="16" focusable="false" aria-hidden="true">
        <path d="m20.7 18.9-4.1-4.1a7 7 0 1 0-1.4 1.4l4 4.1a1 1 0 0 0 1.5 0c.4-.4.4-1 0-1.4ZM6 10.6a5 5 0 1 1 10 0 5 5 0 0 1-10 0Z" />
      </svg>
    </button>
  </div>
</div>
Nunjucks macro options

Use options to customise the appearance, content and behaviour of a component when using a macro, for example, changing the text.

Some options are required for the macro to work. These are marked as "Required" in the option description. Deprecated options are marked as "Deprecated".

If you're using Nunjucks macros in production with "html" options, or ones ending with "html", you must sanitise the HTML to protect against cross-site scripting exploits.

Primary options
Name Type Description
id string The ID of the input. Defaults to the value of name.
name string Required. The name of the input, which is submitted with the form data.
value string Optional initial value of the input.
disabled boolean If true, input will be disabled.
describedBy string One or more element IDs to add to the aria-describedby attribute, used to provide additional descriptive information for screenreader users.
label object Required. The label used by the search input component. See macro options for label.
hint object Can be used to add a hint to a search input component. See macro options for hint.
errorMessage object Can be used to add an error message to the search input component. The error message component will not display if you use a falsy value for errorMessage, for example false or null. See macro options for errorMessage.
prefix object Can be used to add a prefix to the search input component. See macro options for prefix.
suffix object Can be used to add a suffix to the search input component. See macro options for suffix.
code boolean If set to true, use a monospace font for codes or sequences.
width integer Optional fixed width for the search input component – 2, 3, 4, 5, 10, 20 or 30.
large boolean If set to true, larger input size will be used.
formGroup object Additional options for the form group containing the search input component. See macro options for formGroup.
classes string Classes to add to the input.
autocomplete string Attribute to meet WCAG success criterion 1.3.5: Identify input purpose, for instance "bday-day". See the Autofill section in the HTML standard for a full list of attributes that can be used. Default is "off".
pattern string Attribute to provide a regular expression pattern, used to match allowed character combinations for the input value.
inputWrapper object Additional options for the wrapping element containing the search input component. See macro options for inputWrapper.
attributes object HTML attributes (for example data attributes) to add to the input.
button object Optional object allowing customisation of the search button. See button macro options using button component macro.
Options for prefix object
Name Type Description
text string Required. Required. If html is set, this is not required. Text to use within the prefix. If html is provided, the text option will be ignored.
html string Required. Required. If text is set, this is not required. HTML to use within the prefix. If html is provided, the text option will be ignored.
classes string Classes to add to the prefix.
attributes object HTML attributes (for example data attributes) to add to the prefix element.
Options for suffix object
Name Type Description
text string Required. If html is set, this is not required. Text to use within the suffix. If html is provided, the text option will be ignored.
html string Required. If text is set, this is not required. HTML to use within the suffix. If html is provided, the text option will be ignored.
classes string Classes to add to the suffix element.
attributes object HTML attributes (for example data attributes) to add to the suffix element.
Options for formGroup object
Name Type Description
classes string Classes to add to the form group (for example to show error state for the whole group).
attributes object HTML attributes (for example data attributes) to add to the form group.
beforeInput object Content to add before the input used by the search input component. See macro options for formGroup beforeInput.
afterInput object Content to add after the input used by the search input component. See macro options for formGroup afterInput.
Options for formGroup beforeInput object
Name Type Description
text string Required. Text to add before the input. If html is provided, the text option will be ignored.
html string Required. HTML to add before the input. If html is provided, the text option will be ignored.
Options for formGroup afterInput object
Name Type Description
text string Required. Text to add after the input. If html is provided, the text option will be ignored.
html string Required. HTML to add after the input. If html is provided, the text option will be ignored.
Options for inputWrapper object
Name Type Description
classes string Classes to add to the wrapping element.
attributes object HTML attributes (for example data attributes) to add to the wrapping element.
Options for button component
Name Type Description
variant string Optional variant of search button – "brand", "login", "reverse", "secondary", "secondary-solid" or "warning".
classes string Classes to add to the search button.
ariaLabel string Button text exposed to assistive technologies, like screen readers, when only an icon is used.
icon object Can be used to add an icon to the search button. See macro options for button icon.
Options for button icon object
Name Type Description
name string Required. Icon name for the button – for example, "search", "arrow-right", "plus" or "minus".
html string Required. HTML to use for the icon, as an alternative to the name option. If html is provided, the name option will be ignored.
placement string Required. Placement of the icon within the button – "start" or "end".
Options for label component
Name Type Description
id string The ID of the label.
text string Required. If html is set, this is not required. Text to use within the label. If html is provided, the text option will be ignored.
html string Required. If text is set, this is not required. HTML to use within the label. If html is provided, the text option will be ignored.
caller nunjucks-block Not strictly a parameter but Nunjucks code convention. Using a call block enables you to call a macro with all the text inside the tag. This is helpful if you want to pass a lot of content into a macro. To use it, you will need to wrap the entire label component in a call block.
for string The value of the for attribute, the ID of the input the label is associated with.
isPageHeading boolean Whether the label also acts as the heading for the page.
size string Size of the label – "s", "m", "l" or "xl".
classes string Classes to add to the label tag.
attributes object HTML attributes (for example data attributes) to add to the label tag.
{% from "search-input/macro.njk" import searchInput %}

{{ searchInput({
  label: {
    text: "Search patients",
    size: "m"
  },
  hint: {
    text: "Search by name, NHS number, postcode, or date of birth"
  },
  name: "example",
  id: "example",
  classes: "nhsuk-input--width-10",
  value: "LS1 4AP"
}) }}

The search button can include a text label, for example "Find".

Depending on the hierarchy of the page, the search input can use a secondary button.

Open this example in a new tab: search input secondary button
<div class="nhsuk-form-group nhsuk-search-input">
  <label class="nhsuk-label nhsuk-label--m" for="example">
    Find a patient by NHS number
  </label>
  <div class="nhsuk-hint" id="example-hint">
    For example <span class="nhsuk-u-nowrap">999 123 4567</span>
  </div>
  <div class="nhsuk-input-wrapper nhsuk-search-input__wrapper">
    <input class="nhsuk-input nhsuk-search-input__input nhsuk-input--width-10 nhsuk-input--code" id="example" name="example" type="search" aria-describedby="example-hint" autocomplete="off">
    <button class="nhsuk-button nhsuk-button--secondary nhsuk-button--icon nhsuk-button--small nhsuk-search-input__button" data-module="nhsuk-button" type="submit" aria-label="Search">
      <svg class="nhsuk-icon nhsuk-icon--search" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="16" height="16" focusable="false" aria-hidden="true">
        <path d="m20.7 18.9-4.1-4.1a7 7 0 1 0-1.4 1.4l4 4.1a1 1 0 0 0 1.5 0c.4-.4.4-1 0-1.4ZM6 10.6a5 5 0 1 1 10 0 5 5 0 0 1-10 0Z" />
      </svg>
      <span class="nhsuk-button__content">Find</span>
    </button>
  </div>
</div>
Nunjucks macro options

Use options to customise the appearance, content and behaviour of a component when using a macro, for example, changing the text.

Some options are required for the macro to work. These are marked as "Required" in the option description. Deprecated options are marked as "Deprecated".

If you're using Nunjucks macros in production with "html" options, or ones ending with "html", you must sanitise the HTML to protect against cross-site scripting exploits.

Primary options
Name Type Description
id string The ID of the input. Defaults to the value of name.
name string Required. The name of the input, which is submitted with the form data.
value string Optional initial value of the input.
disabled boolean If true, input will be disabled.
describedBy string One or more element IDs to add to the aria-describedby attribute, used to provide additional descriptive information for screenreader users.
label object Required. The label used by the search input component. See macro options for label.
hint object Can be used to add a hint to a search input component. See macro options for hint.
errorMessage object Can be used to add an error message to the search input component. The error message component will not display if you use a falsy value for errorMessage, for example false or null. See macro options for errorMessage.
prefix object Can be used to add a prefix to the search input component. See macro options for prefix.
suffix object Can be used to add a suffix to the search input component. See macro options for suffix.
code boolean If set to true, use a monospace font for codes or sequences.
width integer Optional fixed width for the search input component – 2, 3, 4, 5, 10, 20 or 30.
large boolean If set to true, larger input size will be used.
formGroup object Additional options for the form group containing the search input component. See macro options for formGroup.
classes string Classes to add to the input.
autocomplete string Attribute to meet WCAG success criterion 1.3.5: Identify input purpose, for instance "bday-day". See the Autofill section in the HTML standard for a full list of attributes that can be used. Default is "off".
pattern string Attribute to provide a regular expression pattern, used to match allowed character combinations for the input value.
inputWrapper object Additional options for the wrapping element containing the search input component. See macro options for inputWrapper.
attributes object HTML attributes (for example data attributes) to add to the input.
button object Optional object allowing customisation of the search button. See button macro options using button component macro.
Options for prefix object
Name Type Description
text string Required. Required. If html is set, this is not required. Text to use within the prefix. If html is provided, the text option will be ignored.
html string Required. Required. If text is set, this is not required. HTML to use within the prefix. If html is provided, the text option will be ignored.
classes string Classes to add to the prefix.
attributes object HTML attributes (for example data attributes) to add to the prefix element.
Options for suffix object
Name Type Description
text string Required. If html is set, this is not required. Text to use within the suffix. If html is provided, the text option will be ignored.
html string Required. If text is set, this is not required. HTML to use within the suffix. If html is provided, the text option will be ignored.
classes string Classes to add to the suffix element.
attributes object HTML attributes (for example data attributes) to add to the suffix element.
Options for formGroup object
Name Type Description
classes string Classes to add to the form group (for example to show error state for the whole group).
attributes object HTML attributes (for example data attributes) to add to the form group.
beforeInput object Content to add before the input used by the search input component. See macro options for formGroup beforeInput.
afterInput object Content to add after the input used by the search input component. See macro options for formGroup afterInput.
Options for formGroup beforeInput object
Name Type Description
text string Required. Text to add before the input. If html is provided, the text option will be ignored.
html string Required. HTML to add before the input. If html is provided, the text option will be ignored.
Options for formGroup afterInput object
Name Type Description
text string Required. Text to add after the input. If html is provided, the text option will be ignored.
html string Required. HTML to add after the input. If html is provided, the text option will be ignored.
Options for inputWrapper object
Name Type Description
classes string Classes to add to the wrapping element.
attributes object HTML attributes (for example data attributes) to add to the wrapping element.
Options for button component
Name Type Description
variant string Optional variant of search button – "brand", "login", "reverse", "secondary", "secondary-solid" or "warning".
classes string Classes to add to the search button.
ariaLabel string Button text exposed to assistive technologies, like screen readers, when only an icon is used.
icon object Can be used to add an icon to the search button. See macro options for button icon.
Options for button icon object
Name Type Description
name string Required. Icon name for the button – for example, "search", "arrow-right", "plus" or "minus".
html string Required. HTML to use for the icon, as an alternative to the name option. If html is provided, the name option will be ignored.
placement string Required. Placement of the icon within the button – "start" or "end".
Options for label component
Name Type Description
id string The ID of the label.
text string Required. If html is set, this is not required. Text to use within the label. If html is provided, the text option will be ignored.
html string Required. If text is set, this is not required. HTML to use within the label. If html is provided, the text option will be ignored.
caller nunjucks-block Not strictly a parameter but Nunjucks code convention. Using a call block enables you to call a macro with all the text inside the tag. This is helpful if you want to pass a lot of content into a macro. To use it, you will need to wrap the entire label component in a call block.
for string The value of the for attribute, the ID of the input the label is associated with.
isPageHeading boolean Whether the label also acts as the heading for the page.
size string Size of the label – "s", "m", "l" or "xl".
classes string Classes to add to the label tag.
attributes object HTML attributes (for example data attributes) to add to the label tag.
{% from "search-input/macro.njk" import searchInput %}

{{ searchInput({
  label: {
    text: "Find a patient by NHS number",
    size: "m"
  },
  hint: {
    html: 'For example <span class="nhsuk-u-nowrap">999 123 4567</span>'
  },
  name: "example",
  id: "example",
  classes: "nhsuk-input--width-10 nhsuk-input--code",
  button: {
    text: "Find",
    variant: "secondary"
  }
}) }}

The search input can be large, depending on the context of the page. For example, you can use a large input on a dedicated search page.

Open this example in a new tab: search input large
<div class="nhsuk-form-group nhsuk-search-input nhsuk-search-input--large">
  <h1 class="nhsuk-label-wrapper">
    <label class="nhsuk-label nhsuk-label--l" for="example">
      Search
    </label>
  </h1>
  <div class="nhsuk-input-wrapper nhsuk-input-wrapper--large nhsuk-search-input__wrapper">
    <input class="nhsuk-input nhsuk-input--large nhsuk-search-input__input nhsuk-input--width-20" id="example" name="example" type="search" autocomplete="off">
    <button class="nhsuk-button nhsuk-button--icon nhsuk-search-input__button" data-module="nhsuk-button" type="submit" aria-label="Search">
      <svg class="nhsuk-icon nhsuk-icon--search" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="16" height="16" focusable="false" aria-hidden="true">
        <path d="m20.7 18.9-4.1-4.1a7 7 0 1 0-1.4 1.4l4 4.1a1 1 0 0 0 1.5 0c.4-.4.4-1 0-1.4ZM6 10.6a5 5 0 1 1 10 0 5 5 0 0 1-10 0Z" />
      </svg>
    </button>
  </div>
</div>
Nunjucks macro options

Use options to customise the appearance, content and behaviour of a component when using a macro, for example, changing the text.

Some options are required for the macro to work. These are marked as "Required" in the option description. Deprecated options are marked as "Deprecated".

If you're using Nunjucks macros in production with "html" options, or ones ending with "html", you must sanitise the HTML to protect against cross-site scripting exploits.

Primary options
Name Type Description
id string The ID of the input. Defaults to the value of name.
name string Required. The name of the input, which is submitted with the form data.
value string Optional initial value of the input.
disabled boolean If true, input will be disabled.
describedBy string One or more element IDs to add to the aria-describedby attribute, used to provide additional descriptive information for screenreader users.
label object Required. The label used by the search input component. See macro options for label.
hint object Can be used to add a hint to a search input component. See macro options for hint.
errorMessage object Can be used to add an error message to the search input component. The error message component will not display if you use a falsy value for errorMessage, for example false or null. See macro options for errorMessage.
prefix object Can be used to add a prefix to the search input component. See macro options for prefix.
suffix object Can be used to add a suffix to the search input component. See macro options for suffix.
code boolean If set to true, use a monospace font for codes or sequences.
width integer Optional fixed width for the search input component – 2, 3, 4, 5, 10, 20 or 30.
large boolean If set to true, larger input size will be used.
formGroup object Additional options for the form group containing the search input component. See macro options for formGroup.
classes string Classes to add to the input.
autocomplete string Attribute to meet WCAG success criterion 1.3.5: Identify input purpose, for instance "bday-day". See the Autofill section in the HTML standard for a full list of attributes that can be used. Default is "off".
pattern string Attribute to provide a regular expression pattern, used to match allowed character combinations for the input value.
inputWrapper object Additional options for the wrapping element containing the search input component. See macro options for inputWrapper.
attributes object HTML attributes (for example data attributes) to add to the input.
button object Optional object allowing customisation of the search button. See button macro options using button component macro.
Options for prefix object
Name Type Description
text string Required. Required. If html is set, this is not required. Text to use within the prefix. If html is provided, the text option will be ignored.
html string Required. Required. If text is set, this is not required. HTML to use within the prefix. If html is provided, the text option will be ignored.
classes string Classes to add to the prefix.
attributes object HTML attributes (for example data attributes) to add to the prefix element.
Options for suffix object
Name Type Description
text string Required. If html is set, this is not required. Text to use within the suffix. If html is provided, the text option will be ignored.
html string Required. If text is set, this is not required. HTML to use within the suffix. If html is provided, the text option will be ignored.
classes string Classes to add to the suffix element.
attributes object HTML attributes (for example data attributes) to add to the suffix element.
Options for formGroup object
Name Type Description
classes string Classes to add to the form group (for example to show error state for the whole group).
attributes object HTML attributes (for example data attributes) to add to the form group.
beforeInput object Content to add before the input used by the search input component. See macro options for formGroup beforeInput.
afterInput object Content to add after the input used by the search input component. See macro options for formGroup afterInput.
Options for formGroup beforeInput object
Name Type Description
text string Required. Text to add before the input. If html is provided, the text option will be ignored.
html string Required. HTML to add before the input. If html is provided, the text option will be ignored.
Options for formGroup afterInput object
Name Type Description
text string Required. Text to add after the input. If html is provided, the text option will be ignored.
html string Required. HTML to add after the input. If html is provided, the text option will be ignored.
Options for inputWrapper object
Name Type Description
classes string Classes to add to the wrapping element.
attributes object HTML attributes (for example data attributes) to add to the wrapping element.
Options for button component
Name Type Description
variant string Optional variant of search button – "brand", "login", "reverse", "secondary", "secondary-solid" or "warning".
classes string Classes to add to the search button.
ariaLabel string Button text exposed to assistive technologies, like screen readers, when only an icon is used.
icon object Can be used to add an icon to the search button. See macro options for button icon.
Options for button icon object
Name Type Description
name string Required. Icon name for the button – for example, "search", "arrow-right", "plus" or "minus".
html string Required. HTML to use for the icon, as an alternative to the name option. If html is provided, the name option will be ignored.
placement string Required. Placement of the icon within the button – "start" or "end".
Options for label component
Name Type Description
id string The ID of the label.
text string Required. If html is set, this is not required. Text to use within the label. If html is provided, the text option will be ignored.
html string Required. If text is set, this is not required. HTML to use within the label. If html is provided, the text option will be ignored.
caller nunjucks-block Not strictly a parameter but Nunjucks code convention. Using a call block enables you to call a macro with all the text inside the tag. This is helpful if you want to pass a lot of content into a macro. To use it, you will need to wrap the entire label component in a call block.
for string The value of the for attribute, the ID of the input the label is associated with.
isPageHeading boolean Whether the label also acts as the heading for the page.
size string Size of the label – "s", "m", "l" or "xl".
classes string Classes to add to the label tag.
attributes object HTML attributes (for example data attributes) to add to the label tag.
{% from "search-input/macro.njk" import searchInput %}

{{ searchInput({
  label: {
    text: "Search",
    size: "l",
    isPageHeading: true
  },
  name: "example",
  id: "example",
  large: true,
  classes: "nhsuk-input--width-20"
}) }}

Help us improve this guidance

Share insights or feedback and take part in the discussion. We use GitHub as a collaboration space. All the information on it is open to the public.

Feed back or share insights on GitHub

Read more about how to feed back or share insights.

If you have any questions, get in touch with the service manual team.

Updated: June 2026