# @guardian/src-foundations

> The Guardian's foundations are the atoms from which all our visual design is built. They are intended for use with a CSS-in-JS library such as Emotion.

Latest version **3.13.0** (published 2022-01-18) · Apache-2.0 license · 2.6K weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install @guardian/src-foundations
pnpm add @guardian/src-foundations
yarn add @guardian/src-foundations
bun add @guardian/src-foundations
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 3.13.0 |
| Published | 2022-01-18 |
| First published | 2019-08-07 |
| Weekly downloads | 2.6K |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 291.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 98 |
| Maintainers | unmesh_malvankar, zekehg, rtyley, dlawes, ghaberis, jsherbert, david.furey.gu, tonymccraeguardian, jlieb10, guardian-developers, simonadcock-gu, maxspencer, akash1810, reetta, ajwl, tomrf1, mchv, itsibitzi, justinpinner, jranks123, nicl, philmcmahon, tjmw, thaliasilver, sndrs, sam.hession, jfsoul, 0x101, frankie_hammond, aoifemcl15, ioanna0, mxdvl, rhysmills, jamie-lynch, amyhughes-gu, oliverlloyd, jacobwinch, dskamiotis, marjank, annabeddow, fweddi, michaelclapham_gnm, olly.namey.guardian |

## Links

- npm: https://www.npmjs.com/package/@guardian/src-foundations
- Repository: https://github.com/guardian/source
- Homepage: https://github.com/guardian/source#readme
- Issues: https://github.com/guardian/source/issues
- npm.io page: https://npm.io/package/@guardian/src-foundations

## Recent versions

- 3.13.0 (latest) — 2022-01-18
- 3.2.1-rc.5 (next) — 2021-02-22
- 3.12.0 — 2021-11-08
- 3.11.0 — 2021-11-05
- 3.10.3 — 2021-11-03
- 3.10.2-alpha.1 — 2021-10-18
- 3.10.2-alpha.0 — 2021-10-18
- 3.10.1 — 2021-10-14
- 3.10.0 — 2021-10-14
- 3.9.1 — 2021-10-07
- 3.9.1-rc.1 — 2021-10-07
- 3.9.1-rc.0 — 2021-10-07
- 3.9.0 — 2021-08-26
- 3.9.0-rc.1 — 2021-08-26
- 3.9.0-rc.0 — 2021-08-26
- … 153 more at https://npm.io/package/@guardian/src-foundations/versions

## README

# Foundations

The Guardian's foundations are the atoms from which all our visual design is built. They are intended for use with a CSS-in-JS library such as Emotion.

## Install

```sh
$ yarn add @guardian/src-foundations
```

## Use

### [Palette](https://www.theguardian.design/2a1e5182b/p/28d868-overview)

```ts
import { background } from '@guardian/src-foundations/palette';

const backgroundColor = css`
    background-color: ${background.primary};
`;
```

### [Typography](https://www.theguardian.design/2a1e5182b/p/930d69-typography/b/78d0d9)

```ts
import { headline, body, textSans } from '@guardian/src-foundations/typography';

const h1 = css`
    ${headline.large({ fontWeight: 'bold' })};
`;

const p = css`
    ${body.main()};
`;

const copyright = css`
    ${textSans.xsmall()};
`;
```

### Media queries

```ts
import { from, until, between } from '@guardian/src-foundations/mq';

const styles = css`
    padding: 0 10px;

    ${from.mobileLandscape} {
        padding: 0 20px;
    }

    ${between.phablet.and.desktop} {
        padding: 0 32px;
    }

    ${until.wide} {
        padding: 0 40px;
    }
`;
```

### [Size](https://www.theguardian.design/2a1e5182b/p/38d9a9-overview)

```ts
import { width, height } from '@guardian/src-foundations/size';

const checkbox = css`
    width: ${width.inputXsmall}px;
    height: ${height.inputXsmall}px;
`;
```

### [Visually Hidden](https://www.theguardian.design/2a1e5182b/p/6691bb-accessibility/t/1285a8)

For elements that should not appear to sighted users, but are useful to assistive technology users.

```ts
import { visuallyHidden } from '@guardian/src-foundations/accessibility';

const label = css`
    ${visuallyHidden};
`;
```

### [Focus Halo](https://www.theguardian.design/2a1e5182b/p/6691bb-accessibility/t/24562a)

This mixin provides a [clear focus state](https://theguardian.design/2a1e5182b/p/08dc26-interaction-states/t/314e46) for elements that may receive keyboard focus.

```ts
import { focusHalo } from '@guardian/src-foundations/accessibility';

const input = css`
    ${focusHalo};
    width: 200px;
    height: 44px;
`;
```

### [Description Id](https://theguardian.design/2a1e5182b/p/6691bb-accessibility/t/062b61)

A function that takes the ID of an element and generates a new ID. This should be set as the
ID of an element that describes the first element. The generated ID should also be passed to
the [`aria-describedby`](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques/Using_the_aria-describedby_attribute) attribute on the first element.

```tsx
import { descriptionId } from '@guardian/src-foundations/accessibility';

const Form = () => {
    const id = 'first_name';
    return (
        <form>
            <input id={id} type="text" aria-describedby={descriptionId(id)} />
            <p class="error" id={descriptionId(id)} />
        </form>
    );
};
```

---
_Source: https://npm.io/package/@guardian/src-foundations · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
