Qwik
To use Fontsource with a Qwik City project, it is suggested to use the /routes/layout.tsx
file.
1. Installation
Once you install the Fontsource package of your choice, you can import the chosen font variant into routes/layout.tsx
:
⬤⬤
tsx
Note: Alternatively, you can import the font in index.tsx or any other component file and it should have the same effect.
2. Usage
You can now use the imported fonts in your Qwik City project. Here’s an example of the Open Sans Variable font being applied to an h1
selector.
⬤⬤
css
Scoped Component Fonts
To use Qwik’s scoped CSS functionality, you can use the font declaration in the useStylesScoped$()
hook from Qwik.
⬤⬤
tsx
You can opt out of this scoped behavior by using Qwik’s :global()
selector.
3. Extensibility
By default, Qwik works well with Fontsource out of the box. This even includes lazy-loadable references to component styles with useStyles$()
.