import {Meta} from '@storybook/blocks';
import {Canvas} from '@storybook/addon-docs';
import * as TypographyStories from './Typography.stories';
import {Hint} from '../../../components';

<Meta title="Styles/Typhography"/>

<Hint>Styles</Hint>

# Typography

## Font

If your service is on the service.gov.uk subdomain you must use the GDS Transport font.

### When not to use the GDS Transport font

If your service is publicly available on a subdomain other than service.gov.uk, use an alternative typeface like Helvetica or Arial.

If you’re not sure whether you should use GDS Transport, do one of the following:

- [read the ‘If your service is not on GOV.UK’ section on ‘Making your service look like GOV.UK’](https://www.gov.uk/service-manual/design/making-your-service-look-like-govuk#if-your-service-isnt-on-govuk)
- [contact the Design System team](https://design-system.service.gov.uk/get-in-touch/)

## Headings

<Canvas of={TypographyStories.headings}/>

<Canvas of={TypographyStories.headingsLongFormContent}/>

## Headings with captions

Sometimes you may need to make it clear that a page is part of a larger section or group. To do this, you can use a heading with a caption above it.

<Canvas of={TypographyStories.headingsWithCaptions}/>

If the caption should be considered part of the page heading, you can also nest the caption within the heading `<Typography>` component.

<Canvas of={TypographyStories.nestedCaptions}/>

## Paragraphs

### Body

The default paragraph font size is 19px on large screens and 16px on small screens.

<Canvas of={TypographyStories.body}/>

You can also add classes to create a lead paragraph or smaller body copy to convey hierarchy in your page.

### Lead paragraph

A lead paragraph is an introductory paragraph that you can use at the top of a page to summarise the content. Lead paragraphs use 24px type on desktop and should only be used once per page if needed.

<Canvas of={TypographyStories.lead}/>

### Body small

You can use the govuk-body-s class sparingly to make your paragraph font size smaller: 16px on larger screens and 14px on smaller screens.

The majority of your body copy should use the standard 19px paragraph size.

<Canvas of={TypographyStories.bodySmall}/>

## Text alignment override classes

If you need to align text differently to how it usually displays on the page, you can use text alignment override classes.

Use:

- `govuk-!-text-align-left` to align text to the left
- `govuk-!-text-align-right` to align text to the right
- `govuk-!-text-align-centre` to align text to the centre

You should usually left-align body copy that’s read left to right. Right-aligned body copy can be hard for users to find and read when they magnify their screen.

Do not ‘justify’ blocks of body copy so that they’re aligned to both the left and right margins. Doing this creates wider spaces between words, which can make the text hard to read.

## Font override classes

You might need to set the font size or font weight of an element outside of the predefined heading and paragraph classes. For this you can use the font override classes in your HTML or reference the typography mixins in your own components.

### Font size

The full GOV.UK typography scale goes from 14px up to 80px on large screens. You can add these font size override classes to any other typographic class or element and they will change the font size.

<Canvas of={TypographyStories.fontSize}/>

### Font weight

As with the font size, you can add a font weight override class to any other typographic class or element to change the font weight to regular or bold weight.

<Canvas of={TypographyStories.fontWeight}/>

Bold text
You can use bold to emphasise particular words in a transaction. Use it to highlight critical information that users need to refer to or you’ve seen them miss.

For example, "Your reference number is **ABC12345678**. Use this to track your application. Updates will be sent to **name @example.com**"

Use bold sparingly. Overuse will make it difficult for users to know which parts of your content they need to pay the most attention to.

## Links

Links are blue and underlined by default. If your link is at the end of a sentence or paragraph, make sure that the linked text does not include the full stop.

<Canvas of={TypographyStories.links}/>

Use the `govuk-link--no-visited-state` modifier class where it is not helpful to distinguish between visited and unvisited states, for example when linking to pages with frequently-changing content such as the dashboard for an admin interface.

<Canvas of={TypographyStories.linkNoVisitedState}/>

### External links

If it’s an external link to a non-government website, make that clear in the link text. For example, ‘read advice on writing link text from [name of organisation]’. There’s no need to say explicitly that you’re linking to an external site. Do not use an external link icon.

### Opening links in a new tab

Avoid opening links in a new tab or window. It can be disorienting - and [can cause accessibility problems for people who cannot visually perceive that the new tab has opened](https://www.w3.org/TR/WCAG20-TECHS/G200.html).

If you need a link to open in a new tab - for example, to stop the user losing information they’ve entered into a form - then include the words ‘opens in new tab’ as part of the link. There’s no need to say ‘tab or window’, since opening in a new tab is the default behaviour for most browsers.

Include `rel="noreferrer noopener"` along with `target="_blank"` to reduce the risk of [reverse tabnabbing](https://owasp.org/www-community/attacks/Reverse_Tabnabbing). The following example shows how to do this in HTML.

<Canvas of={TypographyStories.linkNewTab}/>

If you’re displaying lots of links together and want to save space and avoid repetition, consider doing both of the following:

- adding a line of text before the links saying ‘The following links open in a new tab’
- including `<span class="govuk-visually-hidden">(opens in new tab)</span>` as part of the link text, so that part of the link text is visually hidden but still accessible to screen readers

### Links on dark backgrounds

Use the `govuk-link--inverse` modifier class to show white links on dark backgrounds — for example, in headers, custom components, and patterns with darker backgrounds.

Make sure all users can see the links — the white links and background colour [must have a contrast ratio of at least 4.5:1](https://www.w3.org/WAI/WCAG21/Understanding/contrast-minimum.html).

<Canvas of={TypographyStories.linksOnDarkBackgrounds} className="dark-background"/>

### Links without underlines

Use the `govuk-link--no-underline` modifier class to remove underlines from links.

Only do this if the context tells the user that the text is a link, even without the underline.

For example, links in a header or side navigation might not need underlines. Users will understand that they’re links because of where they are, at the same place, across different pages.

<Canvas of={TypographyStories.linkNoUnderline}/>

## Lists

Use lists to make blocks of text easier to read, and to break information into manageable chunks.

<Canvas of={TypographyStories.lists}/>

### Bulleted lists

Introduce bulleted lists with a lead-in line ending in a colon. Start each item with a lowercase letter, and do not use a full stop at the end.

<Canvas of={TypographyStories.bulletedLists}/>

### Numbered lists

Use numbered lists instead of bulleted lists when the order of the items is relevant.

You do not need to use a lead-in line for numbered lists. Items in a numbered list should end in a full stop because each should be a complete sentence.

<Canvas of={TypographyStories.numberedLists}/>

### Adding extra spacing between list items

If a list is hard to read because the items run across multiple lines you can add extra spacing.

<Canvas of={TypographyStories.listExtraSpacing}/>

## Section break

You can use the `govuk-section-break` classes on an `<hr>` element to create a thematic break between sections of content. `govuk-section-break` has class-based modifiers for different size margins.

By default `govuk-section-break` is only visible by its margin. You can add the `govuk-section-break--visible` class to make it visible with a separator line.

<Canvas of={TypographyStories.sectionBreak}/>
