Skip to content

Commit dae178e

Browse files
Add color-scheme utilities (#14567)
Replaces #11271 — the merge conflicts are killing me and it's way easier to just do it again (added you as a co-author though @lukewarlow so you're still credited!) This PR adds the following new utilities for the `color-scheme` property: | Class | CSS | | ------------------- | -------------------------- | | `scheme-normal` | `color-scheme: normal` | | `scheme-dark` | `color-scheme: dark` | | `scheme-light` | `color-scheme: light` | | `scheme-light-dark` | `color-scheme: light dark` | | `scheme-only-dark` | `color-scheme: dark only` | | `scheme-only-light` | `color-scheme: light only` | Went with `scheme-*` for the utilities because there are currently no other CSS properties with the word `scheme` in them and `scheme-light-dark` is going to be a common value which is three words already even with the shortened property name. I considered setting `color-scheme: light dark` by default as part of Preflight for this PR but decided against it, at least for this PR. I think that could still be a useful default but we should think about it a bit more because if you're building a light-mode-only site it'll force you to do some extra work. --------- Co-authored-by: Adam Wathan <[email protected]> Co-authored-by: Luke Warlow <[email protected]>
1 parent 3693a71 commit dae178e

File tree

5 files changed

+80
-0
lines changed

5 files changed

+80
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212
- Add support for prefixes ([#14501](https://github.com/tailwindlabs/tailwindcss/pull/14501))
1313
- Expose timing information in debug mode ([#14553](https://github.com/tailwindlabs/tailwindcss/pull/14553))
1414
- Add support for `blocklist` in config files ([#14556](https://github.com/tailwindlabs/tailwindcss/pull/14556))
15+
- Add `color-scheme` utilities ([#14567](https://github.com/tailwindlabs/tailwindcss/pull/14567))
1516
- _Experimental_: Migrate `@import "tailwindcss/tailwind.css"` to `@import "tailwindcss"` ([#14514](https://github.com/tailwindlabs/tailwindcss/pull/14514))
1617
- _Experimental_: Add template codemods for migrating `bg-gradient-*` utilities to `bg-linear-*` ([#14537](https://github.com/tailwindlabs/tailwindcss/pull/14537]))
1718
- _Experimental_: Add template codemods for migrating prefixes ([#14557](https://github.com/tailwindlabs/tailwindcss/pull/14557]))

packages/tailwindcss/src/__snapshots__/intellisense.test.ts.snap

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3174,6 +3174,12 @@ exports[`getClassList 1`] = `
31743174
"scale-z-75",
31753175
"scale-z-90",
31763176
"scale-z-95",
3177+
"scheme-dark",
3178+
"scheme-light",
3179+
"scheme-light-dark",
3180+
"scheme-normal",
3181+
"scheme-only-dark",
3182+
"scheme-only-light",
31773183
"scroll-auto",
31783184
"scroll-m-0.5",
31793185
"scroll-m-1",

packages/tailwindcss/src/property-order.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,8 @@ export default [
281281
'caret-color',
282282
'accent-color',
283283

284+
'color-scheme',
285+
284286
'opacity',
285287

286288
'background-blend-mode',

packages/tailwindcss/src/utilities.test.ts

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5907,6 +5907,70 @@ test('appearance', async () => {
59075907
).toEqual('')
59085908
})
59095909

5910+
test('color-scheme', async () => {
5911+
expect(
5912+
await run([
5913+
'scheme-normal',
5914+
'scheme-dark',
5915+
'scheme-light',
5916+
'scheme-light-dark',
5917+
'scheme-only-dark',
5918+
'scheme-only-light',
5919+
]),
5920+
).toMatchInlineSnapshot(`
5921+
".scheme-dark {
5922+
--lightningcss-light: ;
5923+
--lightningcss-dark: initial;
5924+
color-scheme: dark;
5925+
}
5926+
5927+
.scheme-light {
5928+
--lightningcss-light: initial;
5929+
--lightningcss-dark: ;
5930+
color-scheme: light;
5931+
}
5932+
5933+
.scheme-light-dark {
5934+
--lightningcss-light: initial;
5935+
--lightningcss-dark: ;
5936+
color-scheme: light dark;
5937+
}
5938+
5939+
@media (prefers-color-scheme: dark) {
5940+
.scheme-light-dark {
5941+
--lightningcss-light: ;
5942+
--lightningcss-dark: initial;
5943+
}
5944+
}
5945+
5946+
.scheme-normal {
5947+
color-scheme: normal;
5948+
}
5949+
5950+
.scheme-only-dark {
5951+
--lightningcss-light: ;
5952+
--lightningcss-dark: initial;
5953+
color-scheme: dark only;
5954+
}
5955+
5956+
.scheme-only-light {
5957+
--lightningcss-light: initial;
5958+
--lightningcss-dark: ;
5959+
color-scheme: light only;
5960+
}"
5961+
`)
5962+
expect(
5963+
await run([
5964+
'scheme',
5965+
'-scheme-dark',
5966+
'-scheme-light',
5967+
'-scheme-light-dark',
5968+
'-scheme-dark-only',
5969+
'-scheme-light-only',
5970+
]),
5971+
).toEqual('')
5972+
})
5973+
59105974
test('columns', async () => {
59115975
expect(
59125976
await compileCss(

packages/tailwindcss/src/utilities.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1872,6 +1872,13 @@ export function createUtilities(theme: Theme) {
18721872
staticUtility('appearance-none', [['appearance', 'none']])
18731873
staticUtility('appearance-auto', [['appearance', 'auto']])
18741874

1875+
staticUtility('scheme-normal', [['color-scheme', 'normal']])
1876+
staticUtility('scheme-dark', [['color-scheme', 'dark']])
1877+
staticUtility('scheme-light', [['color-scheme', 'light']])
1878+
staticUtility('scheme-light-dark', [['color-scheme', 'light dark']])
1879+
staticUtility('scheme-only-dark', [['color-scheme', 'only dark']])
1880+
staticUtility('scheme-only-light', [['color-scheme', 'only light']])
1881+
18751882
// columns-*
18761883
staticUtility('columns-auto', [['columns', 'auto']])
18771884

0 commit comments

Comments
 (0)