|
1 | 1 | ---
|
2 | 2 | title: "Custom Fonts"
|
3 |
| -description: "Learn how to use custom fonts in your document templates, including Google Fonts and local fonts" |
4 | 3 | icon: "font"
|
5 | 4 | ---
|
6 | 5 |
|
7 |
| -# Custom Fonts |
8 |
| - |
9 |
| -You can enhance your document templates with custom fonts, either from Google Fonts or by using local font files. This guide covers both approaches. |
10 |
| - |
11 | 6 | ## Using Google Fonts
|
12 | 7 |
|
13 |
| -To use Google Fonts in your documents, import them in your document's `<Head>` component: |
| 8 | +To use [Google Fonts](https://fonts.google.com/) in your documents, import them in your document's `<Head>` component: |
14 | 9 |
|
15 | 10 | ```tsx
|
16 | 11 | import { Document, Head } from "@htmldocs/react"
|
@@ -67,62 +62,3 @@ function MyDocument() {
|
67 | 62 | )
|
68 | 63 | }
|
69 | 64 | ```
|
70 |
| - |
71 |
| -## Best Practices |
72 |
| - |
73 |
| -1. **Font Loading Performance** |
74 |
| - - For Google Fonts, use the `&display=swap` parameter to prevent font rendering blocking |
75 |
| - - For local fonts, use `font-display: swap` in your `@font-face` declaration |
76 |
| - - Include only the font weights you need to minimize loading time |
77 |
| - |
78 |
| -2. **File Formats** |
79 |
| - - For maximum browser compatibility, provide both WOFF2 and WOFF formats |
80 |
| - - WOFF2 offers better compression and should be listed first in the `src` property |
81 |
| - |
82 |
| -3. **Font Fallbacks** |
83 |
| - - Always include fallback fonts in your `fontFamily` style |
84 |
| - - Example: `fontFamily: 'CustomFont, system-ui, sans-serif'` |
85 |
| - |
86 |
| -## Example with Multiple Font Weights |
87 |
| - |
88 |
| -Here's an example using a custom font with multiple weights: |
89 |
| - |
90 |
| -```tsx |
91 |
| -import { Document, Head } from "@htmldocs/react" |
92 |
| - |
93 |
| -function MyDocument() { |
94 |
| - return ( |
95 |
| - <Document> |
96 |
| - <Head> |
97 |
| - <style> |
98 |
| - {` |
99 |
| - @font-face { |
100 |
| - font-family: 'CustomFont'; |
101 |
| - src: url('/static/fonts/CustomFont-Regular.woff2') format('woff2'); |
102 |
| - font-weight: 400; |
103 |
| - font-style: normal; |
104 |
| - font-display: swap; |
105 |
| - } |
106 |
| - |
107 |
| - @font-face { |
108 |
| - font-family: 'CustomFont'; |
109 |
| - src: url('/static/fonts/CustomFont-Bold.woff2') format('woff2'); |
110 |
| - font-weight: 700; |
111 |
| - font-style: normal; |
112 |
| - font-display: swap; |
113 |
| - } |
114 |
| - `} |
115 |
| - </style> |
116 |
| - </Head> |
117 |
| - <div> |
118 |
| - <p style={{ fontFamily: 'CustomFont', fontWeight: 400 }}> |
119 |
| - Regular text using custom font |
120 |
| - </p> |
121 |
| - <p style={{ fontFamily: 'CustomFont', fontWeight: 700 }}> |
122 |
| - Bold text using custom font |
123 |
| - </p> |
124 |
| - </div> |
125 |
| - </Document> |
126 |
| - ) |
127 |
| -} |
128 |
| -``` |
0 commit comments