src/content/docs/linter/rules/use-google-font-display.mdx
import { Tabs, TabItem } from '@astrojs/starlight/components';
<Tabs> <TabItem label="JSX and TSX" icon="seti:javascript"> ## Summary - Rule available since: `v1.9.4` - Diagnostic Category: [`lint/suspicious/useGoogleFontDisplay`](/reference/diagnostics#diagnostic-category) - This rule is **recommended**, meaning it is enabled by default. - This rule doesn't have a fix. - The default severity of this rule is [**warning**](/reference/diagnostics#warning). - Sources: - Same as [`@next/next/google-font-display`](https://nextjs.org/docs/messages/google-font-display){
"linter": {
"rules": {
"suspicious": {
"useGoogleFontDisplay": "error"
}
}
}
}
Enforces the use of a recommended display strategy with Google Fonts.
The display property controls how a font is displayed while it is loading. When using Google Fonts,
it's important to specify an appropriate value for this property to ensure good user experience and prevent layout shifts.
This rule flags the absence of the display parameter, or the usage of less optimal values such as auto, block, or fallback.
Using &display=optional is generally recommended as it minimizes the risk of invisible text or layout shifts.
In cases where swapping to the custom font after it has loaded is important, consider using &display=swap.
<link href="https://fonts.googleapis.com/css2?family=Krona+One" />
<link href="https://fonts.googleapis.com/css2?family=Krona+One&display=auto" />
<link href="https://fonts.googleapis.com/css2?family=Krona+One&display=block" />
<link href="https://fonts.googleapis.com/css2?family=Krona+One&display=fallback" />
<link href="https://fonts.googleapis.com/css2?family=Krona+One&display=optional" rel="stylesheet" />
<link href="https://fonts.googleapis.com/css2?display=unknown" rel="stylesheet" />
<link rel="stylesheet" />