Skip to main content

Get started

You can start using the latest version of the ONS Design System in your service right now. All of the styles, assets and components are production ready.

Include the compiled CSS and JS

All of the global styles and individual component code is compiled and made available via a CDN.

Each release of the Design System is tagged with a version e.g. which forms part of the url of the compiled files for a specific release.

The following files are deployed to the CDN which can be referenced in a service or project:

  • main.css - Responsive CSS file of all components.
  • main.js - Bundled JavaScript modules.

To reference the files in your service you would use the following url structures (the [VERSION] should be replaced with the required release version e.g. ):

  • https://cdn.ons.gov.uk/sdc/design-system/[VERSION]/css/main.css
  • https://cdn.ons.gov.uk/sdc/design-system/[VERSION]/scripts/main.js

Each release deployed to the CDN is always available. This allows services to plan upgrades to new versions.

Favicons

Favicons have been created for Safari, Chrome and Edge/Internet Explorer for desktop and mobile. Place the following references into the head of all pages within your service to make use of the available favicons. The [VERSION] should be replaced with the required release version.

<meta name="msapplication-config" content="https://cdn.ons.gov.uk/sdc/design-system/[VERSION]/favicons/browserconfig.json">
<link rel="icon" type="image/x-icon" href="/favicons/favicon.ico">
<link rel="icon" type="image/png" href="https://cdn.ons.gov.uk/sdc/design-system/[VERSION]/favicons/favicon-32x32.png" sizes="32x32">
<link rel="icon" type="image/png" href="https://cdn.ons.gov.uk/sdc/design-system/[VERSION]/favicons/favicon-16x16.png" sizes="16x16">
<link rel="mask-icon" color="#5bbad5" href="https://cdn.ons.gov.uk/sdc/design-system/[VERSION]/favicons/safari-pinned-tab.svg">
<link rel="apple-touch-icon" type="image/png" href="https://cdn.ons.gov.uk/sdc/design-system/[VERSION]/favicons/apple-touch-icon.png" sizes="180x180">
<link rel="manifest" href="https://cdn.ons.gov.uk/sdc/design-system/[VERSION]/favicons/manifest.json">

Using components

The components section contains all of the available components that have been tested for accessibility and usability and are ready for production. Each component has been developed using mobile first principles and will render appropriately across all compatible viewports.

Each component contains examples and any context specific variants. You can copy the html directly from the example from the html tab. See the example below:

Open this example in a new window
<div class="panel panel--info panel--no-title">
  <span class="u-vh">Important information: </span>
  <div class="panel__body">
    <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
    <ul>
      <li>VAT</li>
      <li>Internet sales</li>
    </ul>
  </div>
</div>
Nunjucks macro options
Name Type Required Description
body string true The contents of the panel. This can be a string of HTML
title string false The title for the panel. If this is not provided the inline/no title version will be rendered
titleTag string false The html tag to wrap the title text in. Will default to a div (for error summaries this is set to h1)
type string false The type of panel to render. Available options are success, warn, error, branded, warn-branded and announcement
spacious boolean false Will render a more spacious version of the panel if set to true
classes string false Custom classes to add to the panel
id string false Custom id to add to the panel
attributes object false HTML attributes to apply to the panel (e.g. data attributes)
icon string false Set this to the name of the icon you want to be included before the contents of the panel
assistiveTextPrefix string false Overrides the visually hidden accessible default prefix text. Available for the following panels with no title:
  • information and branded (‘Important information: ‘)
  • success (‘Completed: ‘)
  • warn and warn-branded (‘Warning: ‘),
  • error (‘Error: ‘)
iconSize string false Set this to the size of the icon you want can be set to “m”, “l” “xl” to match heading size. Defaults to the size of regualar text
iconsPath string false Set this to the path to the icon you want to be included before the contents of the panel
dsExample boolean false Defaulted to true in Design System examples but wont be set when used outside of the Design System. This will stop the page focusing on the panel on load - only for use in DS examples
{% from "components/panel/_macro.njk" import onsPanel %}
{{
    onsPanel({
        "body": '<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p><ul><li>VAT</li><li>Internet sales</li></ul>'
    })
}}

{% macro onsPanel(params) %}
    {% if params is defined and params and params.classes is defined and params.classes %}
        {% set classes = ' ' + params.classes %}
    {% endif %}
    {% if params is not defined or params.title is not defined and params.type != "bare" %}
        {% set noTitleClass = ' panel--no-title' %}
    {% endif %}
    {% if params is defined and params and params.type is defined and params.type %}
        {% set typeClass = ' panel--' + params.type %}
    {% else %}
        {% set typeClass = ' panel--info' %}
    {% endif %}
    {% if params is defined and params.type == "warn-branded" %}
        {% set containerClass = 'census-warning' %}
    {% endif %}
    {% if params is defined and params.type == "announcement" %}
        {% set containerClass = 'announcement' %}
    {% endif %}
    {% if params is defined and params and params.spacious is defined and params.spacious %}
        {% set spaciousClass = ' panel--spacious' %}
    {% endif %}
    {% if params is defined and params and params.type == "warn-branded" or params.type == "announcement" %}
    <div class="{{containerClass}}">
        <div class="container">
    {% endif %}
        <div {% if params is defined and params and params.type == 'error' and params.title is defined and params.title %}aria-labelledby="error-summary-title" role="alert" tabindex="-1" {% if params.dsExample != true %}autofocus="autofocus" {% endif %}{% endif %}class="panel{{ typeClass }}{{ iconClass }}{{ noTitleClass }}{{ spaciousClass }}{{ classes }}"{% if params is defined and params and params.attributes is defined and params.attributes %}{% for attribute, value in (params.attributes.items() if params is defined and params and params.attributes is mapping and params.attributes.items is defined and params.attributes.items else params.attributes) %}{{attribute}}="{{value}}" {% endfor %}{% endif %}{% if params is defined and params and params.id is defined and params.id %} id="{{params.id}}"{% endif %}>
            {% if params is defined and params and params.type == "warn" or params.type == "warn-branded" %}
                <span class="panel__icon" aria-hidden="true">!</span>
                <span class="u-vh">{{ params.assistiveTextPrefix | default("Warning: ") }}</span>
            {% endif %}
            {% if params is defined and params and params.type == "announcement" %}
                {% from "components/icons/_macro.njk" import onsIcon %}
                <span class="panel__icon" aria-hidden="true">
                    {{
                        onsIcon({
                            "icon": 'arrow-forward'
                        })
                    }}
                </span>
                <span class="u-vh">{{ params.assistiveTextPrefix | default("Announcement: ") }}</span>
            {% endif %}
            {% if params is defined and params %}
                {% if params.title is defined and params.title %}
                    {% if params is defined and params and params.type == 'error' %}
                        {% set defaultTitleTag = "h2" %}
                    {% else %}
                        {% set defaultTitleTag = "div" %}
                    {% endif %}
                    {% set titleTag = params.titleTag | default(defaultTitleTag) %}
                    <div class="panel__header">
                        <{{ titleTag }} id="error-summary-title" {% if params is defined and params and params.type is defined and params.type %}data-qa="{{ params.type }}-header"{% endif %} class="panel__title u-fs-r--b">{{ params.title | safe }}</{{ titleTag }}>
                    </div>
                {% else %}
                    {% if params.type is not defined or params.type == "branded" %}
                        <span class="u-vh">{{ params.assistiveTextPrefix | default("Important information: ") }}</span>
                    {% else %}
                        {% if params.type is defined and params.type == "success" %}
                            <span class="u-vh">{{ params.assistiveTextPrefix | default("Completed: ") }}</span>
                        {% elif params.type is defined and params.type == "error" %}
                            <span class="u-vh">{{ params.assistiveTextPrefix | default("Error: ") }}</span>
                        {% endif %}
                    {% endif %}
                {% endif %}
                {% if params.icon is defined and params.icon %}
                    {% from "components/icons/_macro.njk" import onsIcon %}
                    <span class= "panel__icon u-fs-{{ params.iconSize }}">
                        {{
                            onsIcon({
                                "icon": params.icon,
                                "iconSize": params.iconSize
                            })
                        }}
                    </span>
                {% endif %}
            {% endif %}
            <div class="panel__body{% if params is defined and params and params.iconSize is defined and params.iconSize %} svg-icon-margin--{{ params.iconSize }}{% endif %}" {% if params is defined and params and params.attributes is defined and params.attributes %}{% for attribute, value in (params.attributes.items() if params is defined and params and params.attributes is mapping and params.attributes.items is defined and params.attributes.items else params.attributes) %}{{attribute}}="{{value}}" {% endfor %}{% endif %}>{{ (params.body if params else "") | safe }}
                {{ caller() if caller }}
            </div>
        </div>
    {% if params is defined and params and params.type == "warn-branded" or params.type == "announcement"  %}
        </div>
    </div>
    {% endif %}
{% endmacro %}

@mixin panel-type($name, $color, $color-bg) {
  .panel {
    &--#{$name} {
      background: $color-bg;
      border-color: $color;
    }
    &--#{$name} & {
      &__header {
        background: $color;
      }
    }
  }
}
.census-warning {
  background: $color-branded-tertiary;
}
.announcement {
  background-color: $color-black;
}
.panel {
  border-radius: 0;
  position: relative;
  // Removes inherited bottom margin to make whitespace inside panel equal
  > *:last-child {
    margin-bottom: 0;
  }
  .field {
    margin-bottom: 0;
  }
  &:focus {
    box-shadow: none;
    outline: 4px solid $color-focus !important;
    outline-offset: 0;
  }
  &__header {
    border-radius: 0;
    color: $color-white;
    margin: 0;
    padding: 0.75rem 1rem;
  }
  &__title {
    margin: 0;
  }
  &__body {
    padding: 1rem;
    // Removes inherited bottom margin to make whitespace inside panel equal
    > *:last-child,
    strong > *:last-child {
      margin-bottom: 0;
    }
    &.svg-icon-margin--xxl {
      padding-left: 3.3rem !important;
    }
    &.svg-icon-margin--xl {
      padding-left: 2.8rem !important;
    }
    &.svg-icon-margin--l {
      padding-left: 2.5rem !important;
    }
    &.svg-icon-margin--m {
      padding-left: 2.2rem !important;
    }
    &.svg-icon-margin--s {
      padding-left: 1.4rem !important;
    }
  }
  &__error {
    color: $color-errors;
  }
  &--warn {
    border: 0 !important;
    margin-bottom: 1rem;
    padding: 0;
    &--footer {
      background-color: $color-grey-4 !important;
      margin-bottom: 0;
      padding: 1rem 0 !important;
    }
  }
  &--warn-branded,
  &--announcement {
    border: 0 !important;
    color: $color-white;
    margin-bottom: 0;
    padding: 1rem 0 !important;
    & a {
      color: inherit;
      text-decoration: underline solid $color-white 1px;
    }
    & a:hover {
      text-decoration-thickness: 2px;
    }
  }
  &--announcement {
    & a:focus {
      box-shadow: 0 -2px #fd0, 0 4px #fd0 !important; // Override focus style because the black border is not visible on a black background
    }
  }
  &--no-title {
    border-left: 8px solid transparent;
    padding: 1rem;
    .panel__body {
      background: none;
      padding: 0;
    }
    &.panel--warn {
      padding: 0;
    }
  }
  &--spacious {
    padding: 1rem;
    @include mq(m) {
      padding: 2rem;
    }
  }
  &--warn &,
  &--warn-branded &,
  &--announcement & {
    &__body {
      font-weight: $font-weight-bold;
      min-height: 2rem; // Height of icon
      padding: 0.222rem 0 0.222rem 2.8rem; // Alignment tweak
    }
    &__icon {
      background: $color-black;
      border-radius: 50%;
      color: $color-white;
      font-size: 1.5rem;
      font-weight: 900;
      line-height: 2rem;
      min-height: 2rem;
      min-width: 2rem;
      text-align: center;
    }
  }
  &--announcement & {
    &__body div > *:last-child {
      margin-bottom: 0;
    }
    &__icon {
      display: flex;
      svg {
        margin: auto;
      }
    }
  }
  &--warn-branded & {
    &__icon {
      background-color: $color-white;
      color: $color-branded-tertiary;
    }
  }
  &--announcement & {
    &__icon {
      background-color: $color-white;
      color: $color-black;
    }
  }
  &--success & {
    &__icon {
      fill: $color-success;
      left: 0;
      padding-left: 1rem;
      .svg-icon {
        margin-top: -15% !important;
      }
    }
    &__body {
      padding-left: 1.8rem;
    }
  }
  &--bare & {
    &__icon {
      height: 1.3rem;
      width: 1.3rem;
    }
    &__body {
      padding: 0.1rem 0 0 1.5rem;
    }
  }
  &--bare,
  &--success,
  &--warn,
  &--warn-branded,
  &--announcement {
    .panel__icon {
      position: absolute;
    }
  }
}
@include panel-type(error, $color-errors, $color-errors-tint);
@include panel-type(success, $color-success, $color-success-tint);
@include panel-type(info, $color-info, $color-info-tint);
@include panel-type(branded, $color-branded, $color-branded-tint);
@include panel-type(warn, $color-white, $color-white);
@include panel-type(warn-branded, $color-branded-tertiary, $color-branded-tertiary);
@include panel-type(announcement, $color-black, $color-black);