Skip to content

Commit e48c5e8

Browse files
authored
Fix weird character rendering on Windows with Japanese locale (#20318)
This PR fixes an issue where some characters are incorrectly rendered on Windows with the Japanese locale. This is arguably a bug in the font that's loaded by Windows when it encounters `system-ui`. But waiting for fixes there might ... take a while. Another option is to not change the defaults in Tailwind CSS and instead let the users that support different locales implement a fallback by overriding the `--font-sans` variable. The biggest reason for me to _not_ change it in Tailwind CSS is that it requires us to know what the (proper) fallback fonts need to be on a per OS basis. But the main reason why I did want to make the change is that MDN says this about the `system-ui` font: > Glyphs are taken from the default user interface font on a given platform. Because typographic traditions vary widely across the world, this generic is provided for typefaces that don't map cleanly into the other generics. > > **Note:** As the name implies, `system-ui` is intended to make UI elements look like native apps, and not for typesetting large paragraphs of text. It may cause the displayed typeface to be undesirable for some users—for example, the default Windows CJK font may render Latin scripts poorly, and the `lang` attribute may not affect the displayed font. Some operating systems do not allow customizing `system-ui`, while browsers generally allow customizing the `sans-serif` font family. For large paragraphs, use `sans-serif` or some other non-UI font family instead. > > — https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Properties/font-family#system-ui There are PRs in other big projects that made this kind of change as well. E.g.: - withastro/starlight#3729 - vuejs/vitepress#4988 The reasoning for getting rid of `ui-sans-serif` is twofold: 1. Because the starlight PR seems very well tested, and they got rid of it 2. In the event that the browser decided to load the broken font when it encounters `ui-sans-serif`, then we will run into the same issue again. Fixes: #19767 Fixes: #19768 ## Test plan 1. `system-ui` is not used anymore, so the bug doesn't happen 3. Everything still looks the same for the places I checked, but it's hard to know if this created _other_ issues on other OS + Locale combinations...
1 parent b03e5e7 commit e48c5e8

9 files changed

Lines changed: 376 additions & 354 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2020
- Prevent achromatic theme colors from shifting hue in `color-mix(…)` with polar color spaces like `oklch` ([#20314](https://github.com/tailwindlabs/tailwindcss/issues/20314))
2121
- Ensure `--spacing(0)` is optimized to `0px` instead of `0` so it remains a `<length>` when used in `calc(…)` ([#20319](https://github.com/tailwindlabs/tailwindcss/pull/20319))
2222
- Lazily load `@parcel/watcher` when using the `--watch` flag in `@tailwindcss/cli`, so one-off builds and `--watch --poll` work when `@parcel/watcher` can't be loaded ([#20325](https://github.com/tailwindlabs/tailwindcss/issues/20325))
23+
- Use explicit platform fonts instead of `system-ui` and `ui-sans-serif` so CJK text respects the page's `lang` attribute on Windows ([#19767](https://github.com/tailwindlabs/tailwindcss/issues/19767), [#19768](https://github.com/tailwindlabs/tailwindcss/issues/19768))
2324

2425
## [4.3.2] - 2026-06-26
2526

‎integrations/cli/index.test.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2831,8 +2831,8 @@ test(
28312831
@layer theme, base, components, utilities;
28322832
@layer theme {
28332833
:root, :host {
2834-
--font-sans: ui-sans-serif, system-ui, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol',
2835-
'Noto Color Emoji';
2834+
--font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', 'Noto Sans', Arial,
2835+
sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji';
28362836
--font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New',
28372837
monospace;
28382838
--color-red-500: oklch(63.7% 0.237 25.331);
@@ -2851,7 +2851,7 @@ test(
28512851
line-height: 1.5;
28522852
-webkit-text-size-adjust: 100%;
28532853
tab-size: 4;
2854-
font-family: var(--default-font-family, ui-sans-serif, system-ui, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji');
2854+
font-family: var(--default-font-family, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', 'Noto Sans', Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji');
28552855
font-feature-settings: var(--default-font-feature-settings, normal);
28562856
font-variation-settings: var(--default-font-variation-settings, normal);
28572857
-webkit-tap-highlight-color: transparent;

‎packages/@tailwindcss-postcss/src/__snapshots__/index.test.ts.snap‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ exports[`\`@import 'tailwindcss'\` is replaced with the generated CSS 1`] = `
1212
1313
@layer theme {
1414
:root, :host {
15-
--font-sans: ui-sans-serif, system-ui, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol",
16-
"Noto Color Emoji";
15+
--font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", "Noto Sans", Arial,
16+
sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
1717
--font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New",
1818
monospace;
1919
--color-black: #000;
@@ -44,7 +44,7 @@ exports[`\`@import 'tailwindcss'\` is replaced with the generated CSS 1`] = `
4444
-webkit-text-size-adjust: 100%;
4545
tab-size: 4;
4646
line-height: 1.5;
47-
font-family: var(--default-font-family, ui-sans-serif, system-ui, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji");
47+
font-family: var(--default-font-family, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", "Noto Sans", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji");
4848
font-feature-settings: var(--default-font-feature-settings, normal);
4949
font-variation-settings: var(--default-font-variation-settings, normal);
5050
-webkit-tap-highlight-color: transparent;

‎packages/tailwindcss/preflight.css‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,13 @@ html,
3232
tab-size: 4; /* 3 */
3333
font-family: --theme(
3434
--default-font-family,
35-
ui-sans-serif,
36-
system-ui,
35+
-apple-system,
36+
BlinkMacSystemFont,
37+
'Segoe UI',
38+
Roboto,
39+
'Helvetica Neue',
40+
'Noto Sans',
41+
Arial,
3742
sans-serif,
3843
'Apple Color Emoji',
3944
'Segoe UI Emoji',

‎packages/tailwindcss/src/__snapshots__/index.test.ts.snap‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ exports[`compiling CSS > prefix all CSS variables inside preflight 1`] = `
132132
"
133133
@layer theme {
134134
:root, :host {
135-
--tw-font-sans: ui-sans-serif, system-ui, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol",
136-
"Noto Color Emoji";
135+
--tw-font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", "Noto Sans", Arial,
136+
sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
137137
--tw-font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New",
138138
monospace;
139139
--tw-default-font-family: var(--tw-font-sans);
@@ -160,7 +160,7 @@ exports[`compiling CSS > prefix all CSS variables inside preflight 1`] = `
160160
-webkit-text-size-adjust: 100%;
161161
tab-size: 4;
162162
line-height: 1.5;
163-
font-family: var(--tw-default-font-family, ui-sans-serif, system-ui, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji");
163+
font-family: var(--tw-default-font-family, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", "Noto Sans", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji");
164164
font-feature-settings: var(--tw-default-font-feature-settings, normal);
165165
font-variation-settings: var(--tw-default-font-variation-settings, normal);
166166
-webkit-tap-highlight-color: transparent;

‎packages/tailwindcss/src/compat/default-theme.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,8 +353,13 @@ export default {
353353
},
354354
fontFamily: {
355355
sans: [
356-
'ui-sans-serif',
357-
'system-ui',
356+
'-apple-system',
357+
'BlinkMacSystemFont',
358+
'"Segoe UI"',
359+
'Roboto',
360+
'"Helvetica Neue"',
361+
'"Noto Sans"',
362+
'Arial',
358363
'sans-serif',
359364
'"Apple Color Emoji"',
360365
'"Segoe UI Emoji"',

‎packages/tailwindcss/src/css-functions.test.ts‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -912,8 +912,9 @@ describe('theme(…)', () => {
912912
await compileCss(css`
913913
@theme default reference {
914914
--font-family-sans:
915-
ui-sans-serif, system-ui, sans-serif, Apple Color Emoji, Segoe UI Emoji,
916-
Segoe UI Symbol, Noto Color Emoji;
915+
-apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Helvetica Neue, Noto Sans,
916+
Arial, sans-serif, Apple Color Emoji, Segoe UI Emoji, Segoe UI Symbol,
917+
Noto Color Emoji;
917918
}
918919
.fam {
919920
font-family: theme(fontFamily.sans);
@@ -922,7 +923,7 @@ describe('theme(…)', () => {
922923
).toMatchInlineSnapshot(`
923924
"
924925
.fam {
925-
font-family: ui-sans-serif, system-ui, sans-serif, Apple Color Emoji, Segoe UI Emoji, Segoe UI Symbol, Noto Color Emoji;
926+
font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Helvetica Neue, Noto Sans, Arial, sans-serif, Apple Color Emoji, Segoe UI Emoji, Segoe UI Symbol, Noto Color Emoji;
926927
}
927928
"
928929
`)
@@ -942,7 +943,7 @@ describe('theme(…)', () => {
942943
).toMatchInlineSnapshot(`
943944
"
944945
.fam {
945-
font-family: ui-sans-serif, system-ui, sans-serif, Apple Color Emoji, Segoe UI Emoji, Segoe UI Symbol, Noto Color Emoji;
946+
font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Helvetica Neue, Noto Sans, Arial, sans-serif, Apple Color Emoji, Segoe UI Emoji, Segoe UI Symbol, Noto Color Emoji;
946947
}
947948
"
948949
`)
@@ -1162,7 +1163,7 @@ describe('theme(…)', () => {
11621163
test.each([
11631164
[
11641165
'fontFamily.sans',
1165-
'ui-sans-serif, system-ui, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"',
1166+
'-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", "Noto Sans", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"',
11661167
],
11671168
['maxWidth.xs', '20rem'],
11681169
['transitionTimingFunction.in-out', 'cubic-bezier(.4, 0, .2, 1)'],

0 commit comments

Comments
 (0)