# @codecademy/variance

> Constraint based CSS in JS for building scalable design systems

Latest version **1.1.0** (published 2026-08-25) · MIT license · 0 weekly downloads

## Install

```sh
npm install @codecademy/variance
pnpm add @codecademy/variance
yarn add @codecademy/variance
bun add @codecademy/variance
```

## Health

**Score 65/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; recently updated; high maintenance score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2026-08-25 |
| First published | 2021-02-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 51.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 90 |
| Author | codecaaron |
| Maintainers | codecademy-eng |
| Keywords | css, css-in-js, emotion, styles |

## Links

- npm: https://www.npmjs.com/package/@codecademy/variance
- Repository: https://github.com/Codecademy/gamut
- Homepage: https://github.com/Codecademy/gamut/variance
- Issues: https://github.com/Codecademy/gamut/issues
- npm.io page: https://npm.io/package/@codecademy/variance

## Dependencies (2)

- [lodash](https://npm.io/package/lodash.md) ^4.17.23
- [csstype](https://npm.io/package/csstype.md) ^3.0.7

## Alternatives

- [style-dictionary](https://npm.io/package/style-dictionary.md) — 2.0M weekly downloads
- [postcss-merge-idents](https://npm.io/package/postcss-merge-idents.md) — 1.7M weekly downloads
- [@fontsource/noto-sans](https://npm.io/package/@fontsource/noto-sans.md) — 93.0K weekly downloads
- [uglifycss](https://npm.io/package/uglifycss.md) — 71.6K weekly downloads
- [mat4-interpolate](https://npm.io/package/mat4-interpolate.md) — 23.3K weekly downloads

## Recent versions

- 1.1.0 (latest) — 2026-08-25
- 1.1.1-alpha.6bd45d.0 (alpha.6bd45d) — 2026-09-17
- 1.1.1-alpha.e10dec.0 (alpha.e10dec) — 2026-09-16
- 1.1.1-alpha.222356.0 (alpha.222356) — 2026-09-16
- 1.1.1-alpha.ae5bae.0 (alpha.ae5bae) — 2026-09-15
- 1.1.1-alpha.33c52b.0 (alpha.33c52b) — 2026-09-15
- 1.1.1-alpha.f92633.0 (alpha.f92633) — 2026-09-11
- 1.1.1-alpha.469ce2.0 (alpha.469ce2) — 2026-09-11
- 1.1.1-alpha.bcdb84.0 (alpha.bcdb84) — 2026-09-10
- 1.1.1-alpha.aca464.0 (alpha.aca464) — 2026-09-10
- 1.1.1-alpha.3e37cd.0 (alpha.3e37cd) — 2026-09-10
- 1.1.1-alpha.287361.0 (alpha.287361) — 2026-09-10
- 1.1.1-alpha.6db5f7.0 (alpha.6db5f7) — 2026-09-10
- 1.1.1-alpha.2ba864.0 (alpha.2ba864) — 2026-09-10
- 1.1.1-alpha.1db67e.0 (alpha.1db67e) — 2026-09-10
- … 1919 more at https://npm.io/package/@codecademy/variance/versions

## README

# `@codecademy/variance`

This is an experimental package for creating dynamic and typesafe style props.

## Usage

Configure your props with a simple configuration object. The keys of your object become your prop names and their values describe their responsibilities and valid types.

```tsx
import styled from '@emotion/styled';
import { variance } from '@codecademy/variance';

const Container = styled.div(
  variance.create({
    w: { property: 'width' },
    p: { property: 'padding', scale: 'spacing' },
  })
);

<Container w="100%" p={[16, 24]}>
  Contained!
</Container>;
```

## Composition

You can compose props that you've created seperately to create new prop functions.

```tsx
import { variance } from '@codecademy/variance';

const spacing = variance.create({
  m: { property: 'padding', scale: 'margin' },
  p: { property: 'padding', scale: 'spacing' },
});

const dimensions = variance.create({
  w: { property: 'width' },
  h: { property: 'height' },
});

const combinedProps = variance.compose(spacing, dimensions);

const Box = styled.div(combinedProps);
```

## Static CSS

```tsx
import styled from '@emotion/styled';
import { variance } from '@codecademy/variance';

const css = variance.createCss({
  m: { property: 'padding', scale: 'margin' },
  p: { property: 'padding', scale: 'spacing' },
});

const MyCoolThing = styled.div(
  css({
    width: '100%',
    height: '500px',
    p: [32, , 64],
  })
);

const variant = variance.createVariant({
  m: { property: 'padding', scale: 'margin' },
  p: { property: 'padding', scale: 'spacing' },
});

const MyCoolThing = styled.div(
  variant({
    base: { width: '100%' },
    variants: {
      big: {
        height: '500px',
        p: [32, , 64],
      },
      small: {
        height: '250px',
        p: [16, , 32],
      },
    },
  })
);
```

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