GOV.UK Design System
GOV.UK Frontend is the MIT-licensed CSS, JavaScript and Nunjucks behind GOV.UK services. The Design System is the guidance around it: 37 components, 35 patterns, 13 styles, all user-researched. Anyone may use the code and the patterns. Only services on GOV.UK may use the GOV.UK brand (crown, header, GDS Transport font). This skill gives you both, offline, at a pinned version.
Pinned source: see VERSION. Regenerate with node scripts/build-references.mjs (needs
node, git, npm; fetches upstream, takes about a minute).
Workflow
- Decide the branding mode first (section below). It changes the header, font, colours,
icons and
theme-color, and it is the thing agents get wrong most. - Pick with
references/CHOOSING.md(every component's and pattern's "when to use" and "when not to use" in one file), then openreferences/INDEX.mdand read only the component, pattern and style files the task needs. Every component file has: guidance, when to use, when not to use, the Nunjucks macro options table, and the exact HTML each example renders to. Large files (footer, summary-list, radios) are best grepped for a heading or class name. - Copy markup from the references, do not write it from memory. Class names,
data-moduleattributes,aria-describedbyordering and id conventions are all load-bearing. Paste the HTML or the Nunjucks example, then change the content. - Start pages from
assets/page-template.html(the rendered default template) or extendgovuk/template.njkin Nunjucks. Swap the header per the branding mode. - Run the checklist at the end before reporting done.
Branding mode: on GOV.UK or not?
Is the service on a *.service.gov.uk / gov.uk domain, run by UK government?
yes -> GOV.UK branded. Use govukHeader, crown, GDS Transport, blue #1d70b8.
no -> Unbranded. Follow references/frontend/using-govuk-frontend-without-govuk-branding.mdUnbranded (charities, councils' arms-length bodies, companies, side projects, prototypes for non-gov clients) means:
- Header: use the
generic-headercomponent (govukGenericHeader), nevergovukHeader, never the crown SVG, never "GOV.UK" in the header, title or copy. - Font: do not ship the GDS Transport
.woff/.woff2files. Its licence is limited to gov.uk domains. Override in Sass:
(@use "pkg:govuk-frontend" as * with ( $govuk-font-family: ("Helvetica Neue", Helvetica, Arial, sans-serif), $govuk-functional-colours: (brand: #388E3C) );pkg:needssass --pkg-importer=node, or use thenode_modules/govuk-frontend/dist/govukpath.) With precompiled CSS you cannot override the font. Either compile Sass or add a rule after the stylesheet that setsfont-familyon.govuk-templatedescendants and delete the fonts folder. - Assets: replace
favicon.ico,favicon.svg,govuk-icon-180.png,govuk-icon-192.png,govuk-icon-512.png,govuk-icon-mask.svg,govuk-opengraph-image.pngwith your own. Keep the file names, the CSS expects them. <meta name="theme-color">: set to your brand colour, not#1d70b8.- Footer: the footer component defaults to the Open Government Licence text and logo and
"© Crown copyright". Keep the component, pass
contentLicence: nulland your owncopyright(in HTML: delete thegovuk-footer__licence-*elements and change the copyright link). - Everything else (grid, typography scale, form components, patterns, focus states, error handling) is fine to use as-is and is the whole point.
Install
Never guess a version or CDN path. Check: npm view govuk-frontend version. Details in
references/frontend/installing-with-npm.md, include-css.md, import-javascript.md,
import-font-and-images-assets.md.
- npm (production):
npm i govuk-frontend sass. Sass:@use "govuk-frontend" as *;or thewith (...)form above. Copynode_modules/govuk-frontend/dist/govuk/assets/{fonts,images,manifest.json}to/assets/, or set$govuk-assets-path. - Precompiled (trying it out): copy
dist/govuk/govuk-frontend.min.css,govuk-frontend.min.jsandassets/from the release zip, or for a throwaway prototype load them fromhttps://cdn.jsdelivr.net/npm/govuk-frontend@<version>/dist/govuk/. No Sass overrides possible, so an unbranded build on this path must overridefont-familywith a CSS rule after the stylesheet. Move to npm before it ships. - JavaScript, always both lines: the class-toggle script as the first thing in
<body>, andinitAll()(orcreateAll(Component)per component) as a module at the end.
Without the first line, components stay in their no-JS state. Without<body class="govuk-template__body"> <script>document.body.className += ' js-enabled' + ('noModule' in HTMLScriptElement.prototype ? ' govuk-frontend-supported' : '');</script> ... <script type="module">import { initAll } from '/javascripts/govuk-frontend.min.js'; initAll()</script>initAll, the error summary does not take focus, radios' conditional reveals never open, the button double-click guard is off. - Templating: Nunjucks macros are first-party (
references/frontend/use-nunjucks.md; set the loader path tonode_modules/govuk-frontend/dist). Community ports exist for Jinja (govuk-frontend-jinja), Rails (govuk-components), .NET, Java and React (govuk-react-jsx); with those, still validate the output against the HTML in the references, the HTML is the contract.
Page anatomy
Every page: <html class="govuk-template">, <body class="govuk-template__body">, skip link,
header, <div class="govuk-width-container">, <main class="govuk-main-wrapper" id="main-content">,
footer. Content that is text or a form goes in govuk-grid-row > govuk-grid-column-two-thirds.
Page <title> is Page heading – Service name, and Error: is prefixed when the page shows
errors. See references/styles/page-template.md and layout.md.
Forms and question pages
The bulk of GOV.UK's research is here. Read references/patterns/question-pages.md,
validation.md, check-answers.md, and the "ask users for" pattern for each data type
(names.md, dates.md, addresses.md, email-addresses.md, phone-numbers.md, ...).
- One question per page by default. The
<label>or<legend>IS the<h1>(isPageHeading: true, classesgovuk-label--l/govuk-fieldset__legend--l). Use agovuk-caption-lspan for the section name. Several questions on one page: a statement<h1>, then--mlabels and legends. - Never asterisks. Mark optional fields with "(optional)" in the label.
- Hint text via the
hintoption; never placeholders. - Errors: error summary at the top of
main(linking#field-id, focused on load by JS) plusgovuk-error-messageinside the form group,govuk-form-group--error,govuk-input--error, andaria-describedby="<id>-hint <id>-error"in that order. Error message text starts with a visually hidden "Error:" (the macro adds it). Follow the wording rules in each "ask users for" pattern; they give exact error messages. - Date of birth:
date-inputwithnamePrefix,autocomplete: bday-day/month/year, hint "For example, 27 3 2024" (use a real past date). - Buttons: sentence case, verb first,
Continue/Save and continue/Confirm and send. One primary button per page, left aligned. Usegovuk-button-groupfor pairs. - Set
novalidateon the form so the GOV.UK error pattern runs instead of browser bubbles.
Checklist before done
- Branding mode decided and applied (header, font, icons, theme-color).
- govuk-frontend version verified, not guessed; CSS, JS bootstrap line and
initAllpresent. - Markup matches a reference example (compare class names and
data-module). - Label or legend is the page heading; no asterisks; hints not placeholders.
- Error summary + inline errors +
--errorclasses +aria-describedbyorder +Error:title. - Copy is sentence case, plain English, no "please", no "click here".
- Ran an accessibility check (axe or similar) on the rendered page if a browser is available.
Common mistakes
| Mistake | Fix |
|---|---|
Crown, govukHeader or GDS Transport on a non-government product |
Generic header, font override, own icons |
| Pinning an old major (v4/v5) from memory | npm view govuk-frontend version; v6 changed the type scale, header and colours |
| Loading CSS only, no JS bootstrap line | Add both script lines; components need govuk-frontend-supported on <body> |
| Heading above the form plus a separate label | Make the label or legend the heading with isPageHeading |
Hand-written class names (govuk-input-error, govuk-radio) |
Copy from the reference HTML; BEM names are exact |
| Inline error but no error summary, or summary not linked | Both, summary links to the input id |
Copying .govuk-* classes and restyling them |
Add your own app-* classes alongside; never edit govuk-* (see references/get-started/extending-and-modifying-components.md) |
| Using the design system for marketing or brochure sites | It is a transactional system; use it for services, forms, dashboards, admin tools |