What is govuk-frontend?
The govuk-frontend npm package provides a set of reusable, accessible components and styles for building user interfaces that align with the UK Government Digital Service (GDS) design principles. It is designed to help developers create consistent, user-friendly, and accessible web applications and services.
What are govuk-frontend's main functionalities?
Typography
GOV.UK Frontend provides a set of typography styles that ensure text is readable and accessible. The 'govuk-body' class is used to style paragraphs according to GDS standards.
<p class="govuk-body">This is a paragraph with GOV.UK Frontend styling.</p>
Buttons
GOV.UK Frontend includes styles for buttons that make them visually consistent and accessible. The 'govuk-button' class is used to style buttons.
<button class="govuk-button">Submit</button>
Forms
GOV.UK Frontend provides styles and components for creating accessible forms. The 'govuk-form-group', 'govuk-label', and 'govuk-input' classes are used to style form elements.
<form><div class="govuk-form-group"><label class="govuk-label" for="input-id">Label text</label><input class="govuk-input" id="input-id" name="input-name" type="text"></div></form>
Navigation
GOV.UK Frontend includes styles for navigation elements to ensure they are accessible and consistent. The 'govuk-nav', 'govuk-nav__list', 'govuk-nav__item', and 'govuk-nav__link' classes are used to style navigation menus.
<nav class="govuk-nav"><ul class="govuk-nav__list"><li class="govuk-nav__item"><a class="govuk-nav__link" href="#">Home</a></li><li class="govuk-nav__item"><a class="govuk-nav__link" href="#">About</a></li></ul></nav>
Notifications
GOV.UK Frontend provides components for displaying notifications and alerts. The 'govuk-notification-banner', 'govuk-notification-banner__header', 'govuk-notification-banner__title', and 'govuk-notification-banner__content' classes are used to style notification banners.
<div class="govuk-notification-banner"><div class="govuk-notification-banner__header"><h2 class="govuk-notification-banner__title">Important</h2></div><div class="govuk-notification-banner__content"><p class="govuk-notification-banner__heading">This is a notification message.</p></div></div>
Other packages similar to govuk-frontend
bootstrap
Bootstrap is a popular front-end framework for developing responsive and mobile-first websites. It provides a wide range of components and utilities similar to GOV.UK Frontend but is more general-purpose and not specifically tailored to government services.
foundation-sites
Foundation is another front-end framework that offers a variety of responsive components and styles. Like Bootstrap, it is a general-purpose framework and does not specifically adhere to government design principles.
uswds
The U.S. Web Design System (USWDS) provides a set of design guidelines and components for building accessible and consistent government websites in the United States. It is similar to GOV.UK Frontend but tailored to U.S. government standards.
GOV.UK Frontend
GOV.UK Frontend contains the code you need to start building a user interface
for government platforms and services.
See live examples of GOV.UK Frontend components, and guidance on when to use
them in your service, in the GOV.UK Design System.
Contact the team
GOV.UK Frontend is maintained by a team at Government Digital Service. If you want to know more about GOV.UK Frontend, please email the Design System
team or get in touch with them on Slack.
Quick start
There are 2 ways to start using GOV.UK Frontend in your app.
Once installed, you will be able to use the code from the examples in the
GOV.UK Design System in your service.
1. Install with npm (recommended)
We recommend installing GOV.UK Frontend using node package manager
(npm).
2. Install by using compiled files
You can also download the compiled and minified assets (CSS, JavaScript) from
GitHub.
Importing styles
You need to import the GOV.UK Frontend styles into the main Sass file in your
project. You should place the below code before your own Sass rules (or Sass
imports) if you want to override GOV.UK Frontend with your own styles.
To import add the below to your Sass file:
@import "node_modules/govuk-frontend/govuk/all";
More details on importing styles
Importing JavaScript
Some of the JavaScript included in GOV.UK Frontend improves the usability and
accessibility of the components. You should make sure that you are importing and
initialising Javascript in your application to ensure that all users can use it successfully.
You can include Javascript for all components either by copying the all.js
from node_modules/govuk-frontend/govuk/
into your application or referencing the file directly:
<script src="<path-to-govuk-frontend-all-file>/all.js"></script>
Next you need to initialise the script by adding:
<script>window.GOVUKFrontend.initAll()</script>
More details on importing Javascript and advanced options
Importing assets
In order to import GOV.UK Frontend images and fonts to your project, you should configure your application to reference or copy the relevant GOV.UK Frontend assets.
More details on importing assets
Getting updates
To be notified when there’s a new release, you can either:
Find out how to update with npm.
Licence
Unless stated otherwise, the codebase is released under the MIT License. This
covers both the codebase and any sample code in the documentation. The
documentation is © Crown copyright and available under the terms of the
Open Government 3.0 licence.
Contribution guidelines
If you want to help us build GOV.UK Frontend, view our contribution
guidelines.
4.3.0 (Feature release)
New features
Customise the Open Graph image URL without duplicate meta tags
You can now customise the Open Graph image URL included in the head
by setting the opengraphImageUrl
Nunjucks option.
Also, the default Open Graph image URL meta tag will now only be included if you set the either opengraphImageUrl
or assetUrl
.
This was added in pull request #2673: Allow Open Graph image URL to be customised.
Localise the content licence and copyright statements
When using the footer Nunjucks macro, you can now translate the text of the Open Government Licence (OGL) and Crown copyright statements using the contentLicence
and copyright
parameters.
Visit The National Archives' documentation on OGL and Crown copyright for information on what you need to include in these statements.
This was added in pull request #2702: Allow localisation of content licence and copyright notices in Footer.
Pass HTML directly into compatible components
If using the Nunjucks macros, you can now pass HTML content directly into compatible components using the Nunjucks call syntax. If HTML is provided through the call syntax, the nunjucks macro will ignore the HTML and text options.
Components updated to support this syntax are:
- Details
- Error summary (mapped to
descriptionHtml
parameter) - Inset text
- Notification banner
- Panel
This was added in pull request #2734: Update various components to be callable.
Use new override classes to apply static spacing
You can now use static spacing override classes to apply spacing from the static spacing scale to elements of your design.
The new classes start with: govuk-!-static-
followed by either margin-
or padding-
, and then a spacing unit number.
To apply spacing in a single direction, include left-
, right-
, top-
, or bottom-
just before the spacing unit.
For example:
govuk-!-static-margin-9
will apply a 60px margin to all sides of the element at all screen sizesgovuk-!-static-padding-right-5
will apply 25px of padding to the right side of the element at all screen sizesgovuk-!-static-margin-0
will remove all margins at all screen sizes
This was added in pull request #2672: Add static spacing override classes. Thanks to @patrickpatrickpatrick for this contribution.
Deprecated features
Remove deprecated govuk-header__navigation--no-service-name
class in the header
We've deprecated the govuk-header__navigation--no-service-name
class, and will remove it in a future major release.
This was added in pull request #2694: Deprecate .govuk-header__navigation--no-service-name.
Recommended changes
We've recently made some non-breaking changes to GOV.UK Frontend. Implementing these changes will make your service work better.
Add hidden
to the mobile menu button in the header component
If you're not using the Nunjucks macros, add the hidden
attribute to the mobile menu button in the header component. The mobile menu button is govuk-header__menu-button
.
We've changed the header's mobile menu functionality to use the hidden
attribute instead of using CSS to show/hide the mobile menu. Adding hidden
to the mobile menu button by default will make sure that it does not display for users when javascript does not load.
This was added in pull request 2727: Make use of hidden in header navigation functionality. Thanks to @NickColley and @kr8n3r for their contributions.
Fixes
In pull request 2678: Replace ex units with ems for input lengths, we changed how we define input lengths in our CSS. Browsers might now display these inputs as being slightly wider than before. The difference is usually fewer than 3 pixels.
We’ve also made fixes in the following pull requests: