Skip to content

Email template documentation

Tom Byers edited this page Mar 5, 2024 · 11 revisions

Email template documentation

Email branding

The jinja template can render emails with 1 of 4 different brands.

The different brands the email template can use. They are: 1. GOV.UK only, 2. GOV.UK and your logo, 3. Your logo, Your logo on a colour

Note: 2. is effectively brand 1 + brand 3.

Email templates for services without an associated logo will use the first brand, GOV.UK, by default.

Each of the other brands require certain attributes for the template to render them successfully.

Diagrams showing how each brand looks in emails. All are left-aligned. GOV.UK only just shows the crown on black, GOV.UK and your logo adds your logo underneath, your logo has your logo instead of the crown and on white with a bar of your brand colour to the left and your logo on a colour is the same but without the bar and on your brand colour

Note: the term 'government identity' refers to logos from the government identity system (PDF, 4.2MB).

The dimensions of logos vary. Their height will be set to either 27px, if the branding has text or 54px, if not. The width will adjust to keep the aspect-ratio (the default for HTML rendering). Note: the image resolution needs to be twice the size to look good on high resolution displays (so 54px for 27px or 108px for 54px).

Possible branding variations (for testing)

When testing changes to the email template, it is important to be aware of all the possible variations because of the randomness of HTML rendering in some email clients and screen readers (ie. https://github.com/alphagov/notifications-utils/pull/1061).

Brand type (from web page) variation brand_type database field sections of template used
GOV.UK N/A null section with if govuk_banner shows, no others do
GOV.UK and branding branding below is logo without text both section with if govuk_banner shows along with section with if brand_logo and not brand_banner, brand_alt_text will be set
GOV.UK and branding branding below is logo with text both section with if govuk_banner shows, along with section with if brand_logo and not brand_banner, brand_text will be set
GOV.UK and branding branding below is government branding both section with if govuk_banner shows along with section with if brand_logo and not brand_banner, brand_text will be set and brand_colour will be the colour line next to the logo
Branding only logo without text org section with if brand_logo and not brand_banner shows, brand_alt_text will be set
Branding only logo with text org section with if brand_logo and not brand_banner shows, brand_text will be set
Branding only government branding org section with if brand_logo and not brand_banner shows, brand_text will be set and brand_colour will be the colour line next to the logo
Branding banner logo without text org_banner section with if brand_banner shows, `brand_alt_text will be set
Branding banner logo with text org_banner section with if brand_banner shows, `brand_text will be set

Previewing the current branding

You can view the email template (with the current branding) at the /_email endpoint. So on production this would be:

https://www.notifications.service.gov.uk/_email

Accessibility hacks

The following hacks have been added to make the template work with assistive technologies.

No spacer images

A common hack for HTML emails is to use blank images, set to a dimension to create empty space in your layout.

Because of the issue with alt text, any spacer images are announced to the user, which is not the intention. For this reason we should try not to use them.

Use line break element for layout space

Another common hack is to use space characters encoded as HTML entities (ie &nbsp;), for empty space in your layout. These are announced to users of screenreaders so should not be used. A <br /> tag, which is not part of the content of the document, should be used instead.

Email hacks

HTML emails will be viewed on a large range of client programs and devices. The engine used to render the email can also change. Outlook, for example, has changed its renderer through the versions (see this history of outlook email rendering).

Because of this, our email template relies on hacks to let it display consistently across clients/devices.

Meta tag to turn off format-detection

Adding the following stops phone numbers being turned into links.

Example

<meta content="telephone=no" name="format-detection" />

Duplicate CSS in different parts of the document

Clients will apply CSS depending on how it is defined but this is not consistent so multiple applications are needed.

Examples

CSS duplicated between the document head and inline styles.

  <style type="text/css">
    body { margin:0 !important; }
   <body style="margin: 0">

Styles duplicated between inline CSS and HTML4-style attributes on the element.

  <table
      style="width: 100% !important;"
      width="100%"
  >

Layout using tables

CSS used for layout is ignored by many clients. The pre-CSS method of using tables instead is currently the best way to build layouts that work across the greatest number of clients/devices. See this article on why use tables for layout in emails.

We give all our tables role="presentation" to ensure assistive technologies ignore them. We also zero their border, cell-padding and cell-spacing to ensure clients don't apply their own version of these values.

Conditional comments for Outlook

Microsoft-specific conditional comments can be used to deliver blocks of HTML only to certain versions of Outlook.

See this article on using outlook conditional comments for more detail.

   <!--[if (gte mso 9)|(IE)]>
   ...
   <![endif]-->

Use of !important in CSS

Clients can add their own CSS to emails. Using !important means the preceeding styles have a better chance of overwriting any CSS specific to that client.

Use of inline CSS

Some clients strip CSS out from the head of the email. Using inline CSS ensures elements will still be styled if this happens.

Email preheaders

The first line in the <body> of the template is used by clients to show a preview of the email (see the commit that adds the preheader for details.)

We use CSS to hide it from the email when viewed in full.

Uppercase margin CSS

outlook.com strips margins out from CSS but capitalising them means it ignores them. This form is still recognised as valid CSS by all other clients. See this article on margins in outlook.com for details.

Use of bgcolor instead of background-color in CSS

Support for the CSS property background-color across clients is buggy so we use the HTML4-style bgcolor attribute instead. See this guide on support for background-color.

Clone this wiki locally