Styles

Spacing

The responsive spacing scale

The Design System uses a responsive spacing scale which adapts based on screen size. For example, if you apply spacing unit 9 to a margin, it will be 60px on large screens and 40px on small screens.

GOV.UK Frontend spacing scale
Spacing unit Large screens Small screens
9 60px 40px
8 50px 30px
7 40px 25px
6 30px 20px
5 25px 15px
4 20px 15px
3 15px 15px
2 10px 10px
1 5px 5px
0 0 0

Spacing override classes

Occasionally, you might need to make minor adjustments like adding or removing spacing to elements of your design. You can use the responsive spacing override classes for this.

Using the override classes

The spacing override classes are structured to allow you to apply any size of the scale, using margin or padding in any direction.

For example, govuk-!-margin-9 will set a margin of 60px on large screens and 40px on small screens.

To add padding use -padding instead of -margin.

If you want to add the margin or padding in a particular direction, add left for left, right for right, top for top, or bottom for bottom. For example, -margin-top will set margin-top, -padding-right will set padding-right. If you do not specify a direction, the margin or padding will be applied to all sides of the element.

The last part of the class represents the value you want to apply. For example, in govuk-!-margin-9, the -9 represents 9 on the spacing scale.

Examples

<div class="govuk-!-padding-bottom-9"></div>
<div class="govuk-!-padding-bottom-8"></div>
<div class="govuk-!-padding-bottom-7"></div>
<div class="govuk-!-padding-bottom-6"></div>
<div class="govuk-!-padding-bottom-5"></div>
<div class="govuk-!-padding-bottom-4"></div>
<div class="govuk-!-padding-bottom-3"></div>
<div class="govuk-!-padding-bottom-2"></div>
<div class="govuk-!-padding-bottom-1"></div>
<p class="govuk-body govuk-!-margin-bottom-9">A paragraph with a margin-bottom override (spacing unit 9).</p>
<p class="govuk-body govuk-!-margin-bottom-8">A paragraph with a margin-bottom override (spacing unit 8).</p>
<p class="govuk-body govuk-!-margin-bottom-7">A paragraph with a margin-bottom override (spacing unit 7).</p>
<p class="govuk-body govuk-!-margin-bottom-6">A paragraph with a margin-bottom override (spacing unit 6).</p>
<p class="govuk-body govuk-!-margin-bottom-5">A paragraph with a margin-bottom override (spacing unit 5).</p>
<p class="govuk-body govuk-!-margin-bottom-4">A paragraph with a margin-bottom override (spacing unit 4).</p>
<p class="govuk-body govuk-!-margin-bottom-3">A paragraph with a margin-bottom override (spacing unit 3).</p>
<p class="govuk-body govuk-!-margin-bottom-2">A paragraph with a margin-bottom override (spacing unit 2).</p>
<p class="govuk-body govuk-!-margin-bottom-1">A paragraph with a margin-bottom override (spacing unit 1).</p>
<p class="govuk-body govuk-!-margin-bottom-0">A paragraph with a margin-bottom override (spacing unit 0).</p>

Spacing on custom components

If you’re building your own components and want to reference the spacing scale directly in your SCSS file you can use the spacing scale through a mixin or a function.

Using the responsive spacing mixin

To use the responsive spacing scale, include the govuk-responsive-margin or govuk-responsive-padding mixins.

For example, to apply spacing unit 6 for 30px padding on large screens and 20px on small screens, use:

@include govuk-responsive-padding(6);

You can also add an argument to apply margin or padding in a single direction.

For example, to apply spacing unit 6 for a 30px bottom margin on large screens and a 20px bottom margin on small screens, use:

@include govuk-responsive-margin(6, "bottom");

Using the static spacing function

If you want to apply large screen spacing at all breakpoints, use the govuk-spacing function instead.

For example, to apply spacing unit 6 for 30px top padding on both large and small screens, use:

padding-top: govuk-spacing(6);

For negative spacing, use a negative spacing unit number.

For example, to apply spacing unit -3 for a negative 15px top margin on both large and small screens, use:

margin-top: govuk-spacing(-3);

Width override classes

If you need to constrain the width of an element independently of the grid system, you can use width override classes.

As with the spacing override classes the width override classes start with govuk-!-. The second part of the class name signifies the width on larger screen sizes. For example, govuk-!-width-one-half will apply a width of 50% and govuk-!-width-two-thirdswill apply a width of 66.66%.

These examples are for the generic width override classes - read specific guidance on setting text input width.

<div class="govuk-form-group">
  <label class="govuk-label" for="full">
    Full width
  </label>
  <input class="govuk-input govuk-!-width-full" id="full" name="full" type="text">
</div>

<div class="govuk-form-group">
  <label class="govuk-label" for="three-quarters">
    Three-quarters width
  </label>
  <input class="govuk-input govuk-!-width-three-quarters" id="three-quarters" name="three-quarters" type="text">
</div>

<div class="govuk-form-group">
  <label class="govuk-label" for="two-thirds">
    Two-thirds width
  </label>
  <input class="govuk-input govuk-!-width-two-thirds" id="two-thirds" name="two-thirds" type="text">
</div>

<div class="govuk-form-group">
  <label class="govuk-label" for="one-half">
    One-half width
  </label>
  <input class="govuk-input govuk-!-width-one-half" id="one-half" name="one-half" type="text">
</div>

<div class="govuk-form-group">
  <label class="govuk-label" for="one-third">
    One-third width
  </label>
  <input class="govuk-input govuk-!-width-one-third" id="one-third" name="one-third" type="text">
</div>

<div class="govuk-form-group">
  <label class="govuk-label" for="one-quarter">
    One-quarter width
  </label>
  <input class="govuk-input govuk-!-width-one-quarter" id="one-quarter" name="one-quarter" type="text">
</div>

Help improve this page

If you spot a problem with this guidance you can propose a change.

If you're not sure how to do this, read guidance on how to propose changes in GitHub.

Need help?

If you’ve got a question about the GOV.UK Design System, contact the team.