tailwindcss/packages
Robin Malfait 8d03db8178
Implement --spacing(…), --alpha(…) and --theme(…) CSS functions (#15572)
This PR implements new CSS functions that you can use in your CSS (or
even in arbitrary value position).

For starters, we renamed the `theme(…)` function to `--theme(…)`. The
legacy `theme(…)` function is still available for backwards
compatibility reasons, but this allows us to be future proof since
`--foo(…)` is the syntax the CSS spec recommends. See:
https://drafts.csswg.org/css-mixins/

In addition, this PR implements a new `--spacing(…)` function, this
allows you to write:

```css
@import "tailwindcss";

@theme {
  --spacing: 0.25rem;
}

.foo {
  margin: --spacing(4):
}
```

This is syntax sugar over:
```css
@import "tailwindcss";

@theme {
  --spacing: 0.25rem;
}

.foo {
  margin: calc(var(--spacing) * 4);
}
```

If your `@theme` uses the `inline` keyword, we will also make sure to
inline the value:

```css
@import "tailwindcss";

@theme inline {
  --spacing: 0.25rem;
}

.foo {
  margin: --spacing(4):
}
```

Boils down to:
```css
@import "tailwindcss";

@theme {
  --spacing: 0.25rem;
}

.foo {
  margin: calc(0.25rem * 4); /* And will be optimised to just 1rem */
}
```

---

Another new function function we added is the `--alpha(…)` function that
requires a value, and a number / percentage value. This allows you to
apply an alpha value to any color, but with a much shorter syntax:

```css
@import "tailwindcss";

.foo {
  color: --alpha(var(--color-red-500), 0.5);
}
```

This is syntax sugar over:
```css
@import "tailwindcss";

.foo {
  color: color-mix(in oklab, var(--color-red-500) 50%, transparent);
}
```

---------

Co-authored-by: Philipp Spiess <hello@philippspiess.com>
Co-authored-by: Jordan Pittman <jordan@cryptica.me>
Co-authored-by: Jonathan Reinink <jonathan@reinink.ca>
2025-01-08 20:16:08 +00:00
..
@tailwindcss-browser Add @tailwindcss/browser package (#15558) 2025-01-07 09:57:34 -05:00
@tailwindcss-cli Prepare v4.0.0-beta.8 release (#15418) 2024-12-17 13:31:28 +01:00
@tailwindcss-node Update jiti 2.4.0 → 2.4.2 (patch) (#15491) 2025-01-06 11:42:53 +01:00
@tailwindcss-postcss Move --container-prose to --max-width-prose (#15439) 2024-12-18 20:15:37 -05:00
@tailwindcss-standalone Update bun 1.1.40 → 1.1.42 (patch) (#15551) 2025-01-06 12:45:16 +01:00
@tailwindcss-upgrade Upgrade: Do not extract class names from functions (#15566) 2025-01-07 15:31:48 +01:00
@tailwindcss-vite Prepare v4.0.0-beta.8 release (#15418) 2024-12-17 13:31:28 +01:00
internal-example-plugin Prefix internal modules with internal-* (#14074) 2024-07-29 10:58:07 -04:00
tailwindcss Implement --spacing(…), --alpha(…) and --theme(…) CSS functions (#15572) 2025-01-08 20:16:08 +00:00
tsconfig.base.json Improve debug logs (#15303) 2024-12-11 15:27:20 +01:00