--- url: "https://design-system.service.gov.uk/styles/page-template/" titulek: "Page template – GOV.UK Design System" h1: "Page template" popis: "Template combines the boilerplate markup and components needed for a basic GOV.UK page" jazyk: "en" kanonicka: "https://design-system.service.gov.uk/styles/page-template/" drobecky: ["Home", "Styles"] zdroj: "live" wayback_snapshot: "" stazeno: "2026-09-14 01:23:02" znaku: 32729 slov: 4583 kodovani: "utf-8" sha256: "3517800cb98aeab1625d6bb0c05ab6943b9ee8c740dfab67c7e3ef07b671187f" --- # Page template Use this template to keep your pages consistent with the rest of GOV.UK. This page template combines the boilerplate markup and [components](/components/) needed for a basic GOV.UK page. It includes: - JavaScript that adds a `.govuk-frontend-supported` class, which is required by components with JavaScript behaviour - the [Skip link component](/components/skip-link/) , [Header component](/components/header/) and [Footer component](/components/footer/) - the favicon, and other related theme icons In the examples provided, we show both HTML and [Nunjucks](https://frontend.design-system.service.gov.uk/use-nunjucks/). You can use the HTML examples if you are not able to use Nunjucks. If you use HTML you’ll need to update it manually when new versions are released. If you’re using Nunjucks you can get this page template by installing GOV.UK Frontend. You’ll get updates to the page template when we update GOV.UK Frontend. ## Default This example shows the minimum required for a GOV.UK page. - HTML - Nunjucks HTML ``` GOV.UK - The best place to find government services and information Skip to main content

Default page template

``` Nunjucks ``` {% block head %} {% endblock %} {% block content %}

Default page template

{% endblock %} {% block bodyEnd %} {% endblock %} ``` ## Customised page template You can customise the page template, for example, by: - adding a service name and navigation - including a [Back link component](/components/back-link/) or [Phase banner component](/components/phase-banner/) - HTML - Nunjucks HTML ``` GOV.UK - Customised page template
Skip to main content

This is a new service – your feedback will help us to improve it.

Back

Customised page template

``` Nunjucks ``` {% from "govuk/components/back-link/macro.njk" import govukBackLink %} {% from "govuk/components/cookie-banner/macro.njk" import govukCookieBanner %} {% from "govuk/components/skip-link/macro.njk" import govukSkipLink %} {% from "govuk/components/header/macro.njk" import govukHeader %} {% from "govuk/components/phase-banner/macro.njk" import govukPhaseBanner %} {% from "govuk/components/footer/macro.njk" import govukFooter %} {% set htmlClasses = "app-html-class" %} {% set htmlLang = "en" %} {% set assetUrl = "YOUR-DOMAIN" %} {% set themeColor = "blue" %} {% set bodyClasses = "app-body-class" %} {% set bodyAttributes = { "data-test": "My value", "data-other": "report:details" } %} {% set containerClasses = "app-width-container" %} {% set mainClasses = "app-main-class" %} {% block pageTitle %}GOV.UK - Customised page template{% endblock %} {% block headIcons %} {{ super() }} {% endblock %} {% block head %} {% endblock %} {% block bodyStart %}
{{ govukCookieBanner({ ariaLabel: "Cookies on [name of service]", messages: [ { headingText: "Cookies on [name of service]", html: '

We use some essential cookies to make this service work.

We’d also like to use analytics cookies so we can understand how you use the service and make improvements.

', actions: [ { text: "Accept analytics cookies", type: "submit", name: "cookies[analytics]", value: "yes" }, { text: "Reject analytics cookies", type: "submit", name: "cookies[analytics]", value: "no" }, { text: "View cookies", href: "#" } ] } ] }) }}
{% endblock %} {% block govukSkipLink %} {{ govukSkipLink({ href: "#main-content", text: "Skip to main content" }) }} {% endblock %} {% block govukServiceNavigation %} {{ govukServiceNavigation({ serviceName: "Service name", serviceUrl: "#", navigation: [ { href: "#", text: "Navigation item 1", active: true }, { href: "#", text: "Navigation item 2" }, { href: "#", text: "Navigation item 3" } ] }) }} {% endblock %} {% block headerEnd %} {{ govukPhaseBanner({ tag: { text: "Alpha" }, html: 'This is a new service – your feedback will help us to improve it.' }) }} {% endblock %} {% block containerStart %} {{ govukBackLink({ href: "#", text: "Back" }) }} {% endblock %} {% block main %} {{ super() }} {% endblock %} {% block content %}

Customised page template

{% endblock %} {% block govukFooter %} {{ govukFooter({ meta: { items: [ { href: "#", text: "Help" }, { href: "#", text: "Cookies" }, { href: "#", text: "Contact" }, { href: "#", text: "Terms and conditions" } ] } }) }} {% endblock %} {% block bodyEnd %} {% endblock %} ``` ## Changing template content If you’re using Nunjucks, you can change the template’s content using options. How you set an option depends on whether it’s a ‘variable’ option or a ‘block’ option. To set a ‘variable’ option, use `set` to pass in a single value or string. For example, to add a class to the `` element using the `bodyClasses` option: ``` {% set bodyClasses = "EXAMPLE-CLASS" %} ``` By default, the template contains a [Skip link component](/components/skip-link/), [Header component](/components/header/) and [Footer component](/components/footer/), all of which require ‘blocks’ to change. To set a ‘block’ option, use `block` to pass in a multiline value or HTML markup. For example, to add a block of HTML before the closing `` element in the page template using the `bodyEnd` option: ``` {% block bodyEnd %}

Example text

{% endblock %} ``` To change the components that are included in the page template by default, set their equivalent blocks. For example: ``` {% block govukHeader %} {{ govukHeader ({ homepageUrl: "/custom-url" }) }} {% endblock %} ``` ## Template blocks and options Options are listed within the template blocks where they’re used: - `` and `` - `` and metadata - page header - width container and main content - footer - other options ### `` and `` Use options in `` and `` to: - configure classes and attributes on the `` element - configure classes and attributes on the `` element - add content at the start or end of the `` element #### Configure classes and attributes on the `` element `htmlClasses` (Variable) Add a class to the `` element. `htmlLang` (Variable) Set the language of the whole document. If your `` and `<main>` element are in a different language to the rest of the page, use `htmlLang` to set the language of the rest of the page. #### Configure classes and attributes on the `<body>` element `bodyClasses` (Variable) Add a class to the `<body>` element. `bodyAttributes` (Variable) Add attributes to the `<body>` element. Add each attribute and its value in the `bodyAttributes` object. #### Add content at the start or end of the `<body>` element `bodyStart` (Block) Add content after the opening `<body>` element. For example: the [Cookie banner component](/components/cookie-banner/). `bodyEnd` (Block) Add content just before the closing `</body>` element. ### `<head>` and metadata Use options in `<head>` and metadata to: - configure where your page can access GOV.UK Frontend assets - customise icons and theme colours - set the page’s title - add custom metadata to the `<head>` element (like a `<link>` to your services stylesheet) #### Configure where your page can access GOV.UK Frontend assets `assetPath` (Variable) Specify a path to the [GOV.UK Frontend assets](https://frontend.design-system.service.gov.uk/import-font-and-images-assets/) (icons, images, font files). If you’re using the refreshed GOV.UK brand, you may need to update this path to point to the updated assets. `assetUrl` (Variable) Set the domain for assets where an absolute URL is required, for example the Open Graph image. #### Customise icons and theme colours `opengraphImageUrl` (Variable) Set the URL for the Open Graph image meta tag. The URL must be absolute, including the protocol and domain name. If you’re using the refreshed GOV.UK brand, you may need to update this path to point to the updated assets. `themeColor` (Variable) Set the [toolbar colour on some devices](https://developer.chrome.com/blog/support-for-theme-color-in-chrome-39-for-android). `headIcons` (Block) Override the default icons used for GOV.UK branded pages. For example: `<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />`. #### Set the page’s title `pageTitle` (Variable) Override the default page title (`<title>` element). `pageTitleLang` (Variable) Set the language of the `<title>` element if it’s different to `htmlLang`. #### Add custom metadata to the `<head>` element `head` (Block) Add additional items inside the `<head>` element. For example: `<meta name="description" content="My page description">`. Use options in page header to: - replace the Skip Link rendered before the `<header>` - add classes or attributes to the `<header>` element - add extra content at the start or end of the `<header>` element - add a Service Navigation component - replace the default content from the header #### Add extra content at the start or end of the `<header>` element `headerStart` (Block) Add content after the opening `<header>` element. `headerEnd` (Block) Add content just before the closing `</header>` element. For example: the [Phase banner component](/components/phase-banner/). #### Replace the default content from the header Override the `<header>` element and the `headerStart`, `govukHeader`, `govukServiceNavigation`, and `headerEnd` blocks. `govukHeader` (Block) Override the GOV.UK Header without changing the rest of the `<header>` element. ### Width container and main content The page template renders your content in a `<main>` tag, wrapped in a container limiting the content’s width. Use options in width container and main content to: - add classes to the container limiting the content’s width - add content at the start or end of the container - add classes or attributes to the `<main>` element - replace the container or `<main>` element with your own #### Render your content inside the template `content` (Block) Add content that needs to appear in the `<main>` element. #### Add classes or attributes to the container `containerClasses` (Variable) Add a class to the container. This is useful if you want to make the page wrapper a fixed width. `containerAttributes` (Variable) Add other attributes than `class` to the container element. Add each attribute and its value in the `containerAttributes` object. #### Add extra content at the start or end of the container `containerStart` (Block) Add content after the opening `<div class=”govuk-width-container”>` element that limits the width of the page. For example: the [Back link component](/components/back-link), [Breadcrumbs component](/components/breadcrumbs). `beforeContent` (Block) Deprecated - Use `containerStart` instead. Add content that needs to appear outside the `<main>` element. For example: the [Back link component](/components/back-link), [Breadcrumbs component](/components/breadcrumbs). `containerEnd` (Block) Add content just before the closing `</div>` of the width container. #### Add classes or attributes to the `<main>` element `mainClasses` (Variable) Add a class to the `<main>` element. `mainLang` (Variable) Set the language of the `<main>` element if it’s different to `htmlLang`. `mainAttributes` (Variable) Add other attributes than `class` and `lang` to the `<main>` element. Add each attribute and its value in the `mainAttributes` object. #### Replace the container or `<main>` element `container` (Block) Override the default container limiting the width of the page, including the `<main>` element it wraps. `main` (Block) Override the whole `<main>` element. Use options in footer to: - add classes or attributes to the `<footer>` element - add extra content at the start or end of the `<footer>` element - replace the default content from the footer #### Add extra content at the start or end of the `<footer>` element `footerStart` (Block) Add content after the opening `<footer>` element. `footerEnd` (Block) Add content just before the closing `</footer>` element. #### Replace the default content from the footer Override the `<footer>` element and the `govukFooter`, `footerStart`, and `footerEnd` blocks. `govukfooter` (Block) Override the GOV.UK Footer without changing the rest of the `<footer>` element. ### Other options #### Security `cspNonce` (Variable) Add a nonce attribute to the script for your Content Security Policy (CSP). Provide a nonce that hostile actors cannot guess, as otherwise they can easily find a way around your CSP. However, you should use this attribute only if you’re not able to include the hash for the inline scripts in your service’s CSP. ## Help improve this style To help make sure that this page is useful, relevant and up to date, you can: - take part in the [‘Page template’ discussion on GitHub](https://github.com/alphagov/govuk-design-system-backlog/issues/268) and share your research - [propose a change on GitHub](https://github.com/alphagov/govuk-design-system/edit/main/src/styles/page-template/index.md) – read more about [how to propose changes in GitHub](/community/propose-a-content-change-using-github/) ## Need help? If you’ve got a question about the GOV.UK Design System, [contact the team](/contact/).