Skip to content

Commit ffa5278

Browse files
delbaoliveiraeps1lon
authored andcommitted
docs: Create tailwind guide (#78908)
Closes: https://linear.app/vercel/issue/DOC-4643/tailwind Redirects: vercel/front#45246
1 parent 456a8cd commit ffa5278

File tree

9 files changed

+30
-101
lines changed

9 files changed

+30
-101
lines changed

docs/01-app/01-getting-started/05-css.mdx

Lines changed: 3 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ related:
66
title: Next Steps
77
description: Learn more about the features mentioned in this page.
88
links:
9+
- app/guides/tailwind-css
910
- app/guides/sass
1011
- app/guides/css-in-js
1112
---
@@ -14,10 +15,10 @@ Next.js provides several ways to use CSS in your application, including:
1415

1516
- [CSS Modules](#css-modules)
1617
- [Global CSS](#global-css)
17-
- [Tailwind CSS](#tailwind-css)
18+
- [External Stylesheets](#external-stylesheets)
19+
- [Tailwind CSS](/docs/app/guides/tailwind-css)
1820
- [Sass](/docs/app/guides/sass)
1921
- [CSS-in-JS](/docs/app/guides/css-in-js)
20-
- [External Stylesheets](#external-stylesheets)
2122

2223
## CSS Modules
2324

@@ -93,96 +94,6 @@ export default function RootLayout({ children }) {
9394

9495
> **Good to know:** Global styles can be imported into any layout, page, or component inside the `app` directory. However, since Next.js uses React's built-in support for stylesheets to integrate with Suspense, this currently does not remove stylesheets as you navigate between routes which can lead to conflicts. We recommend using global styles for _truly_ global CSS, and [CSS Modules](#css-modules) for scoped CSS.
9596
96-
## Tailwind CSS
97-
98-
[Tailwind CSS](https://tailwindcss.com/) is a utility-first CSS framework that integrates seamlessly with Next.js.
99-
100-
### Installing Tailwind
101-
102-
To start using Tailwind, install the necessary Tailwind CSS packages:
103-
104-
```bash filename="Terminal"
105-
npm install tailwindcss @tailwindcss/postcss postcss
106-
```
107-
108-
### Configuring Tailwind
109-
110-
Create a `postcss.config.mjs` file in the root of your project and add the `@tailwindcss/postcss` plugin to your PostCSS configuration:
111-
112-
```js filename="postcss.config.mjs" highlight={4}
113-
/** @type {import('tailwindcss').Config} */
114-
export default {
115-
plugins: {
116-
'@tailwindcss/postcss': {},
117-
},
118-
}
119-
```
120-
121-
### Using Tailwind
122-
123-
Add the [Tailwind directives](https://tailwindcss.com/docs/functions-and-directives#directives) to your [Global Stylesheet](#global-css):
124-
125-
```css filename="app/globals.css"
126-
@import 'tailwindcss';
127-
```
128-
129-
Then, import the styles in the [root layout](/docs/app/api-reference/file-conventions/layout#root-layouts):
130-
131-
```tsx filename="app/layout.tsx" switcher
132-
import type { Metadata } from 'next'
133-
// These styles apply to every route in the application
134-
import './globals.css'
135-
136-
export const metadata: Metadata = {
137-
title: 'Create Next App',
138-
description: 'Generated by create next app',
139-
}
140-
141-
export default function RootLayout({
142-
children,
143-
}: {
144-
children: React.ReactNode
145-
}) {
146-
return (
147-
<html lang="en">
148-
<body>{children}</body>
149-
</html>
150-
)
151-
}
152-
```
153-
154-
```jsx filename="app/layout.js" switcher
155-
// These styles apply to every route in the application
156-
import './globals.css'
157-
158-
export const metadata = {
159-
title: 'Create Next App',
160-
description: 'Generated by create next app',
161-
}
162-
163-
export default function RootLayout({ children }) {
164-
return (
165-
<html lang="en">
166-
<body>{children}</body>
167-
</html>
168-
)
169-
}
170-
```
171-
172-
You can then start writing Tailwind's utility classes in your application.
173-
174-
```tsx filename="app/page.tsx" switcher
175-
export default function Page() {
176-
return <h1 className="text-3xl font-bold underline">Hello, Next.js!</h1>
177-
}
178-
```
179-
180-
```jsx filename="app/page.js" switcher
181-
export default function Page() {
182-
return <h1 className="text-3xl font-bold underline">Hello, Next.js!</h1>
183-
}
184-
```
185-
18697
## External stylesheets
18798

18899
Stylesheets published by external packages can be imported anywhere in the `app` directory, including colocated components:

docs/01-app/02-guides/css-in-js.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ The following are currently working on support:
3232

3333
> **Good to know**: We're testing out different CSS-in-JS libraries and we'll be adding more examples for libraries that support React 18 features and/or the `app` directory.
3434
35-
If you want to style Server Components, we recommend using [CSS Modules](/docs/app/building-your-application/styling/css) or other solutions that output CSS files, like PostCSS or [Tailwind CSS](/docs/app/building-your-application/styling/tailwind-css).
35+
If you want to style Server Components, we recommend using [CSS Modules](/docs/app/building-your-application/styling/css) or other solutions that output CSS files, like PostCSS or [Tailwind CSS](/docs/app/guides/tailwind-css).
3636

3737
## Configuring CSS-in-JS in `app`
3838

docs/01-app/02-guides/migrating/app-router-migration.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -887,7 +887,7 @@ If you are also migrating to Next.js from a Single-Page Application (SPA) at the
887887
In the `pages` directory, global stylesheets are restricted to only `pages/_app.js`. With the `app` directory, this restriction has been lifted. Global styles can be added to any layout, page, or component.
888888

889889
- [CSS Modules](/docs/app/building-your-application/styling/css#css-modules)
890-
- [Tailwind CSS](/docs/app/building-your-application/styling/tailwind-css)
890+
- [Tailwind CSS](/docs/app/guides/tailwind-css)
891891
- [Global Styles](/docs/app/building-your-application/styling/css#global-styles)
892892
- [CSS-in-JS](/docs/app/guides/css-in-js)
893893
- [External Stylesheets](/docs/app/building-your-application/styling/css#external-stylesheets)
@@ -921,7 +921,7 @@ export default function RootLayout({ children }) {
921921
}
922922
```
923923

924-
Learn more about [styling with Tailwind CSS](/docs/app/building-your-application/styling/tailwind-css)
924+
Learn more about [styling with Tailwind CSS](/docs/app/guides/tailwind-css)
925925

926926
## Using App Router together with Pages Router
927927

docs/01-app/02-guides/migrating/from-create-react-app.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ export default function RootLayout({
300300
}
301301
```
302302

303-
If you’re using Tailwind CSS, see our [installation docs](/docs/app/building-your-application/styling/tailwind-css).
303+
If you’re using Tailwind CSS, see our [installation docs](/docs/app/guides/tailwind-css).
304304

305305
### Step 6: Create the Entrypoint Page
306306

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
---
2-
title: Tailwind CSS
2+
title: How to install Tailwind CSS in your Next.js application
3+
nav_title: Tailwind CSS
34
description: Style your Next.js Application using Tailwind CSS.
45
---
56

67
{/* The content of this doc is shared between the app and pages router. You can use the `<PagesOnly>Content</PagesOnly>` component to add content that is specific to the Pages Router. Any shared content should not be wrapped in a component. */}
78

8-
[Tailwind CSS](https://tailwindcss.com/) is a utility-first CSS framework that is fully compatible with Next.js.
9+
[Tailwind CSS](https://tailwindcss.com/) is a utility-first CSS framework that is fully compatible with Next.js. This guide will walk you through how to install Tailwind CSS in your Next.js application.
910

1011
## Installing Tailwind
1112

@@ -15,6 +16,8 @@ Install the necessary Tailwind CSS packages:
1516
npm install -D tailwindcss @tailwindcss/postcss postcss
1617
```
1718

19+
> **Good to know**: If you're using the `create-next-app` CLI to create your project, Next.js will prompt if you'd like to install Tailwind and automatically configure the project.
20+
1821
## Configuring Tailwind
1922

2023
Create a `postcss.config.mjs` file in the root of your project and add the `@tailwindcss/postcss` plugin to your PostCSS configuration:

docs/01-app/03-building-your-application/05-styling/01-css.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ To maintain a predictable order, we recommend the following:
348348
- Prefer CSS Modules over global styles.
349349
- Use a consistent naming convention for your CSS modules. For example, using `<name>.module.css` over `<name>.tsx`.
350350
- Extract shared styles into a separate shared component.
351-
- If using [Tailwind](/docs/app/building-your-application/styling/tailwind-css), import the stylesheet at the top of the file, preferably in the [Root Layout](/docs/app/building-your-application/routing/layouts-and-templates#root-layout-required).
351+
- If using [Tailwind](/docs/app/guides/tailwind-css), import the stylesheet at the top of the file, preferably in the [Root Layout](/docs/app/building-your-application/routing/layouts-and-templates#root-layout-required).
352352
- Turn off any linters/formatters (e.g., ESLint's [`sort-import`](https://eslint.org/docs/latest/rules/sort-imports)) that automatically sort your imports. This can inadvertently affect your CSS since CSS import order _matters_.
353353

354354
> **Good to know:**

docs/01-app/05-api-reference/02-components/font.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,7 @@ export default function MyApp({ Component, pageProps }) {
827827

828828
</PagesOnly>
829829

830-
Finally, add the CSS variable to your [Tailwind CSS config](/docs/app/building-your-application/styling/tailwind-css#configuring-tailwind):
830+
Finally, add the CSS variable to your [Tailwind CSS config](/docs/app/guides/tailwind-css#configuring-tailwind):
831831

832832
### Tailwind CSS v4
833833

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
title: How to use CSS in your application
3+
nav_title: CSS
4+
description: Learn about the different ways to add CSS to your application, including CSS Modules, Global CSS, Tailwind CSS, and more.
5+
related:
6+
title: Next Steps
7+
description: Learn more about the features mentioned in this page.
8+
links:
9+
- pages/guides/tailwind-css
10+
- pages/guides/sass
11+
- pages/guides/css-in-js
12+
source: app/getting-started/css
13+
---
14+
15+
{/* DO NOT EDIT. The content of this doc is generated from the source above. To edit the content of this page, navigate to the source page in your editor. You can use the `<PagesOnly>Content</PagesOnly>` component to add content that is specific to the Pages Router. Any shared content should not be wrapped in a component. */}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Tailwind CSS
33
description: Style your Next.js Application using Tailwind CSS.
4-
source: app/building-your-application/styling/tailwind-css
4+
source: app/guides/tailwind-css
55
---
66

77
{/* DO NOT EDIT. The content of this doc is generated from the source above. To edit the content of this page, navigate to the source page in your editor. You can use the `<PagesOnly>Content</PagesOnly>` component to add content that is specific to the Pages Router. Any shared content should not be wrapped in a component. */}

0 commit comments

Comments
 (0)