# Header ## Introduction The header component is used at the top of every GOV.UK page, to help users navigate. ## Guidance Find out when to use the header component in your service in the [GOV.UK Design System](https://design-system.service.gov.uk/components/header). ## Quick start examples ### Header [Preview this example in the Frontend review app](http://govuk-frontend-review.herokuapp.com/components/header/preview) #### Markup #### Macro {% from "header/macro.njk" import govukHeader %} {{ govukHeader({}) }} ### Header with service name [Preview this example in the Frontend review app](http://govuk-frontend-review.herokuapp.com/components/header/with-service-name/preview) #### Markup #### Macro {% from "header/macro.njk" import govukHeader %} {{ govukHeader({ "serviceName": "Service Name", "serviceUrl": "/components/header" }) }} ### Header with navigation [Preview this example in the Frontend review app](http://govuk-frontend-review.herokuapp.com/components/header/with-navigation/preview) #### Markup #### Macro {% from "header/macro.njk" import govukHeader %} {{ govukHeader({ "navigation": [ { "href": "#1", "text": "Navigation item 1", "active": true }, { "href": "#2", "text": "Navigation item 2" }, { "href": "#3", "text": "Navigation item 3" }, { "href": "#4", "text": "Navigation item 4" } ] }) }} ### Header with service name and navigation [Preview this example in the Frontend review app](http://govuk-frontend-review.herokuapp.com/components/header/with-service-name-and-navigation/preview) #### Markup #### Macro {% from "header/macro.njk" import govukHeader %} {{ govukHeader({ "serviceName": "Service Name", "serviceUrl": "/components/header", "navigation": [ { "href": "#1", "text": "Navigation item 1", "active": true }, { "href": "#2", "text": "Navigation item 2" }, { "href": "#3", "text": "Navigation item 3" }, { "href": "#4", "text": "Navigation item 4" } ] }) }} ## Requirements ### Build tool configuration When compiling the Sass files you'll need to define includePaths to reference the node_modules directory. Below is a sample configuration using gulp .pipe(sass({ includePaths: 'node_modules/' })) ### Static asset path configuration In order to include the images used in the components, you need to configure your app to show these assets. Below is a sample configuration using Express js: app.use('/assets', express.static(path.join(__dirname, '/node_modules/govuk-frontend/assets'))) ## Component arguments If you are using Nunjucks,then macros take the following arguments **If you’re using Nunjucks macros in production be aware that using `html` arguments, or ones ending with `Html` can be a [security risk](https://en.wikipedia.org/wiki/Cross-site_scripting). More about it in the [Nunjucks documentation](https://mozilla.github.io/nunjucks/api.html#user-defined-templates-warning).**
Name Type Required Description
homepageUrl string No The url of the homepage. Defaults to /
assetsPath string No The public path for the assets folder. If not provided it defaults to /assets/images
productName string No Header title that is placed next to GOV.UK. Used for product names (i.e. Pay, Verify)
serviceName string No Header title that is placed next to GOV.UK. Used for product names (i.e. Pay, Verify)
serviceUrl string No Url for the service name anchor.
navigation array No An array of navigation item objects.
navigation.{}.text string No Text of the navigation item.
navigation.{}.href string No Url of the navigation item anchor. Both `href` and `text` attributes for navigation items need to be provided to create an item.
navigation.{}.active boolean No Flag to mark the navigation item as active or not.
navigationClasses string No Optional classes that can be added to the navigation section of the header.
containerClasses string No Optional classes that can be added to the container, useful if you want to make the header fixed width.
classes string No Optional additional classes to add to the header container.
attributes object No Any extra HTML attributes (for example data attributes) to add to the header container.
**If you’re using Nunjucks macros in production be aware that using `html` arguments, or ones ending with `Html` can be a [security risk](https://en.wikipedia.org/wiki/Cross-site_scripting). More about it in the [Nunjucks documentation](https://mozilla.github.io/nunjucks/api.html#user-defined-templates-warning).** ### Setting up Nunjucks views and paths Below is an example setup using express configure views: nunjucks.configure('node_modules/govuk-frontend/components', { autoescape: true, cache: false, express: app }) ## Contribution Guidelines can be found at [on our Github repository.](https://github.com/alphagov/govuk-frontend/blob/master/CONTRIBUTING.md "link to contributing guidelines on our github repository") ## License MIT