HTML coding style
GOV.UK Design System
The GOV.UK design system is recommended for all html pages and a basic page template is provided as a starting point.
Browser support
The GOV.UK Service Manual lists the minimum browsers that GOV.UK services are required to support. Tools such as GOV.UK Frontend, that are used to help build services, may have stricter standards of browser support.
Therefore, you will need to test your code in different browsers depending on which part of MHCLG you are working in.
Your page should work with only HTML, before adding any CSS or JavaScript. Read building a resilient frontend using progressive enhancement.
Document structure
Use HTML5 to structure your page semantically. Use ARIA roles to help older assistive technologies map the sections correctly.
Léonie Watson explains how to use ARIA landmark roles to deliver the best experience for screen reader users.
This document does not prescribe whether to use single or double quotes in attributes, whether to omit values from attributes that do not need them or whether to add trailing slashes to void elements. However, the approach you adopt should be consistent throughout your code.
Individual element guidance
Headings
Headings should be in order - for example <h1>
then <h2>
, but not <h1>
then <h3>
.
There should only be one <h1>
element in a page.
Text emphasis
Italics should be avoided according to the GOV.UK content style guide.
Bold can be used sparingly, but can make large blocks of text difficult to read.
Semantically, words voiced with emphasis can be marked up with <em>
, whereas words conveying a sense of urgency or warning should be marked up with <strong>
. In theory screen readers could adopt a different tone of voice for this markup, though none of the major ones currently do.
Browsers will render em
in italics and strong
in bold by default, so you may need to override em
to not use italics.
As a rule, avoid using <i>
or <b>
, which are only useful in rare cases. It is usually better to use the font-style
and font-weight
CSS properties.
Images
Read the Design System’s Images section.
Buttons vs links
Links should be used for navigating to another page. Buttons should be used for submitting forms or interactions within the page (for example, expanding an element). Empty links (<a href="#">
) should be avoided.
Links should not open new tabs or windows by default, but if users choose to do so (through keyboard shortcuts or right-click context menu) then we should respect their choice.
Visually hidden elements
Sometimes it can be helpful to provide additional content for screen reader users that might not be needed for sighted users. For example, the ‘Skip to main content’ link covered earlier.
Do not use display: none
on this text, as this will get ignored by screen readers.
Instead, use CSS which ensures the text gets ‘conceptually’ rendered, even if the result is not visible on the screen. You can use the Sass mixins from govuk-frontend or the classes govuk-visually-hidden
and govuk-visually-hidden-focusable
.
Visually hidden text is often a sign that something can be simplified or made visible to benefit sighted users too, so should be used sparingly.