You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/01-app/01-getting-started/01-installation.mdx
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -202,7 +202,7 @@ export default function Document() {
202
202
203
203
### Create the `public` folder (optional)
204
204
205
-
Create a [`public` folder](/docs/app/building-your-application/optimizing/static-assets) at the root of your project to store static assets such as images, fonts, etc. Files inside `public` can then be referenced by your code starting from the base URL (`/`).
205
+
Create a [`public` folder](/docs/app/api-reference/file-conventions/public-folder) at the root of your project to store static assets such as images, fonts, etc. Files inside `public` can then be referenced by your code starting from the base URL (`/`).
206
206
207
207
You can then reference these assets using the root path (`/`). For example, `public/profile.png` can be referenced as `/profile.png`:
Next.js provides several ways to use CSS in your application, including:
14
14
15
15
-[CSS Modules](#css-modules)
16
16
-[Global CSS](#global-css)
17
17
-[Tailwind CSS](#tailwind-css)
18
-
-[Sass](#sass)
19
-
-[CSS-in-JS](#css-in-js)
18
+
-[Sass](/docs/app/guides/sass)
19
+
-[CSS-in-JS](/docs/app/guides/css-in-js)
20
20
-[External Stylesheets](#external-stylesheets)
21
21
22
-
This page will guide you through how to use each of these approaches.
23
-
24
22
## CSS Modules
25
23
26
24
CSS Modules locally scope CSS by generating unique class names. This allows you to use the same class in different files without worrying about naming collisions.
@@ -185,292 +183,6 @@ export default function Page() {
185
183
}
186
184
```
187
185
188
-
## Sass
189
-
190
-
Next.js integrates with [Sass](https://sass-lang.com/) using both the [`.scss`](https://sass-lang.com/documentation/syntax/#scss) and [`.sass`](https://sass-lang.com/documentation/syntax#the-indented-syntax) extensions and syntax.
191
-
192
-
You can also use component-level Sass via [CSS Modules](#css-modules) and the `.module.scss`or `.module.sass` extension.
193
-
194
-
### Installing Sass
195
-
196
-
To start using Sass, install the `sass` package:
197
-
198
-
```bash filename="Terminal"
199
-
npm install --save-dev sass
200
-
```
201
-
202
-
### Customizing Sass options
203
-
204
-
If you want to configure your Sass options, use the [`sassOptions`](/docs/app/api-reference/config/next-config-js/sassOptions) option in `next.config.js`.
205
-
206
-
```ts filename="next.config.ts" switcher
207
-
importtype { NextConfig } from'next'
208
-
209
-
const nextConfig:NextConfig= {
210
-
sassOptions: {
211
-
additionalData: `$var: red;`,
212
-
},
213
-
}
214
-
215
-
exportdefaultnextConfig
216
-
```
217
-
218
-
```js filename="next.config.mjs" switcher
219
-
/**@type{import('next').NextConfig}*/
220
-
221
-
constnextConfig= {
222
-
sassOptions: {
223
-
additionalData:`$var: red;`,
224
-
},
225
-
}
226
-
227
-
exportdefaultnextConfig
228
-
```
229
-
230
-
## CSS-in-JS
231
-
232
-
> **Warning:** CSS-in-JS libraries which require runtime JavaScript are not currently supported in React Server Components. Using CSS-in-JS with newer React features like Server Components and Streaming requires library authors to support the latest version of React.
233
-
234
-
The following libraries are supported in **Client Components** in the `app` directory (alphabetical):
If you want to style Server Components, we recommend using [CSS Modules](#css-modules) or other solutions that output CSS files, like [Tailwind CSS](#tailwind-css).
255
-
256
-
### Configuring CSS-in-JS
257
-
258
-
To configure CSS-in-JS, you need to:
259
-
260
-
1. Create a **style registry** to collect all CSS rules in a render.
261
-
2. Use the `useServerInsertedHTML` hook to inject rules before any content that might use them.
262
-
3. Create a Client Component that wraps your app with the style registry during initial server-side rendering.
263
-
264
-
#### `styled-jsx`
265
-
266
-
To configure `styled-jsx` for your application, create a new registry:
Then, wrap your [root layout](/docs/app/api-reference/file-conventions/layout#root-layouts) with the registry:
317
-
318
-
```tsx filename="app/layout.tsx" switcher
319
-
importStyledJsxRegistryfrom'./registry'
320
-
321
-
exportdefaultfunction RootLayout({
322
-
children,
323
-
}: {
324
-
children:React.ReactNode
325
-
}) {
326
-
return (
327
-
<html>
328
-
<body>
329
-
<StyledJsxRegistry>{children}</StyledJsxRegistry>
330
-
</body>
331
-
</html>
332
-
)
333
-
}
334
-
```
335
-
336
-
```jsx filename="app/layout.js" switcher
337
-
importStyledJsxRegistryfrom'./registry'
338
-
339
-
exportdefaultfunctionRootLayout({ children }) {
340
-
return (
341
-
<html>
342
-
<body>
343
-
<StyledJsxRegistry>{children}</StyledJsxRegistry>
344
-
</body>
345
-
</html>
346
-
)
347
-
}
348
-
```
349
-
350
-
#### `styled-components`
351
-
352
-
To use `styled-components`, enable it in `next.config.js`:
353
-
354
-
```ts filename="next.config.ts" switcher
355
-
importtype { NextConfig } from'next'
356
-
357
-
const nextConfig:NextConfig= {
358
-
compiler: {
359
-
styledComponents: true,
360
-
},
361
-
}
362
-
363
-
exportdefaultnextConfig
364
-
```
365
-
366
-
```js filename="next.config.mjs" switcher
367
-
/**@type{import('next').NextConfig}*/
368
-
369
-
constnextConfig= {
370
-
compiler: {
371
-
styledComponents:true,
372
-
},
373
-
}
374
-
375
-
exportdefaultnextConfig
376
-
```
377
-
378
-
Then, use the `styled-components` API to create a global registry component to collect all CSS style rules generated during a render, and a function to return those rules. Then use the `useServerInsertedHTML` hook to inject the styles collected in the registry into the `<head>` HTML tag in the root layout.
> - Examples are available in the [Vercel OG Playground](https://og-playground.vercel.app/).
305
-
> -`ImageResponse` uses [@vercel/og](https://vercel.com/docs/concepts/functions/edge-functions/og-image-generation), [Satori](https://github.com/vercel/satori), and Resvg to convert HTML and CSS into PNG.
305
+
> -`ImageResponse` uses [`@vercel/og`](https://vercel.com/docs/og-image-generation), [`satori`](https://github.com/vercel/satori), and `resvg` to convert HTML and CSS into PNG.
306
306
> - Only flexbox and a subset of CSS properties are supported. Advanced layouts (e.g. `display: grid`) will not work.
0 commit comments