Skip to main content

Styling

govuk-frontend’s CSS styles every component. govuk-react has no CSS-in-JS and adds no classes you need to write yourself: every class comes from a part or a prop.

Widths and margins

Form controls take a width. Fluid widths are "full", "three-quarters", "two-thirds", "one-half", "one-third" and "one-quarter", and text inputs also take a character width:

<InputField label="Postcode" name="postcode" width={10} />
<SelectField label="Country" name="country" width="one-half">…</SelectField>

Heading, Body and List take marginBottom, from 0 to 9:

<Heading size="l" marginBottom={2}>Your details</Heading>

Override classes

For govuk-frontend’s other override classes, overrideClasses returns the govuk-!-* classes for your className:

import { Body, overrideClasses } from 'govuk-react';

<Body className={overrideClasses({ fontWeight: 'bold', marginTop: 6 })}>Bold text</Body>;

It takes spacing (margin, marginTop, padding and the rest, 0 to 9, with staticSpacing), width, fontSize, fontWeight, tabularNumbers, textAlign, breakWord, display and hideWhenPrinting.

Your own CSS

Add your own classes with className, and use govuk-frontend’s custom properties for its colours and breakpoints, such as var(--govuk-text-colour) and --govuk-breakpoint-tablet. To change govuk-frontend’s settings, such as the font, build its CSS with its Sass API.