size

The use-design-tokens rule checks that CSS size-related property declarations use design token variables instead of hardcoded values. This ensures consistent sizing across the application and makes it easier to maintain design system consistency.

Size in the checked properties lists the properties it applies to.

Note that the following properties accept both space and size tokens:

  • inset and all of its longhand properties

  • Positioning attributes: left, right, top, and bottom

Use size tokens when these properties represent element dimensions, and space tokens when they represent spacing/positioning offsets.

Examples of incorrect code for this rule

.card {
  min-width: 48px;
}
.button {
  height: 0.75rem;
}
.icon {
  width: 20px;
}
.icon {
  width: calc(2 * 16px);
}
:root {
  --local-size: 24px;
}

.button {
  min-height: var(--local-size);
}

Examples of correct token usage for this rule

.card {
  min-width: var(--size-item-large);
}
.button {
  height: var(--size-item-xsmall);
}
.icon {
  width: var(--icon-size-medium);
}
.icon {
  width: var(--icon-size-medium, 28px);
}
.icon {
  width: calc(2 * var(--icon-size-medium));
}
.icon {
  width: calc(2 * var(--icon-size-medium, 28px));
}
:root {
  --local-size: var(--size-item-small);
}

.button {
  min-height: var(--local-size);
}
.positioned-element {
  inset: var(--size-item-large);
}
.positioned-element {
  top: var(--size-item-medium);
  left: var(--size-item-small);
}

The rule also allows the non-token values listed for Size in the checked properties.

Autofix functionality

This rule can automatically fix some violations by replacing raw size values with appropriate size tokens. Size in the checked properties lists every value it fixes. For example:

/* Before */
.a {
  height: 0.75rem;
}

/* After autofix */
.a {
  height: var(--size-item-xsmall);
}
/* Before */
.a {
  width: 1rem;
}

/* After autofix */
.a {
  width: var(--size-item-small);
}
/* Before */
.a {
  max-inline-size: calc(16px + 32px);
}

/* After autofix */
.a {
  max-inline-size: calc(var(--size-item-small) + var(--size-item-large));
}