Integração com Tailwind CSS
Configure e utilize o Tailwind CSS para desenvolver interfaces rapidamente com classes baseadas em utilitários.
Integração com Tailwind CSS é uma aula grátis de Next.js 15 Fullstack Web Apps no CoddyKit. Esta é a aula 2 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de Next.js 15 Fullstack Web Apps, e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de Next.js 15 Fullstack Web Apps inclui 4 aulas no total.
Partes desta aula ainda não foram traduzidas e aparecem em inglês.
Meet Tailwind CSS
Welcome to styling with Tailwind CSS! It's a popular utility-first CSS framework that helps you build custom designs quickly.
Instead of writing custom CSS for every element, you apply pre-defined utility classes directly in your HTML or JSX.
Utility-First Explained
What does 'utility-first' mean?
- Small, Single-Purpose Classes: Each class does one thing, like
text-blue-500for text color orp-4for padding. - Build Complex UIs: You combine many small utility classes to create unique designs.
- No Custom CSS Needed: Often, you won't need to write any custom CSS files, speeding up development.
Tailwind & Next.js: A Perfect Match
Tailwind CSS pairs wonderfully with Next.js:
- Component-Based: Easily apply classes directly to your React components.
- Zero Runtime: Tailwind generates static CSS at build time, meaning no extra JavaScript is shipped to the browser for styling.
- Purging: It automatically removes unused CSS, keeping your final bundle size small.
Step 1: Install Core Dependencies
First, let's add Tailwind CSS and its peer dependencies to your Next.js project. We install them as development dependencies.
tailwindcss: The core framework.postcss: A tool for transforming CSS.autoprefixer: A PostCSS plugin to add vendor prefixes to CSS rules.
npm install -D tailwindcss postcss autoprefixerStep 2: Initialize Tailwind Config
Next, generate your Tailwind configuration files. The -p flag creates both tailwind.config.js and postcss.config.js for you.
npx tailwindcss init -pStep 3: Configure Content Paths
Open tailwind.config.js. You need to tell Tailwind where to find your files (like pages, components) that will use Tailwind classes. This allows it to scan and generate only the necessary CSS.
/** @type {import('tailwindcss').Config} */
module.exports = {
content: [
'./app/**/*.{js,ts,jsx,tsx,mdx}',
'./pages/**/*.{js,ts,jsx,tsx,mdx}',
'./components/**/*.{js,ts,jsx,tsx,mdx}',
],
theme: {
extend: {},
},
plugins: [],
}Step 4: Add Tailwind Directives to CSS
Now, open your global CSS file (usually ./app/globals.css in the App Router). Add the @tailwind directives at the top. These inject Tailwind's base styles, components, and utility classes into your project.
@tailwind base;
@tailwind components;
@tailwind utilities;
/* Your custom global styles can go here */Using Utility Classes in JSX
With Tailwind set up, you can start applying classes directly to your elements. Notice how multiple classes combine to style the h1 element in this example.
// app/page.js or a component file
export default function HomePage() {
return (
<div className="min-h-screen flex items-center justify-center bg-gray-100">
<h1 className="text-4xl font-bold text-indigo-600 p-6 rounded-lg shadow-md bg-white">
Hello Tailwind!
</h1>
</div>
);
}Responsive Design Made Easy
Tailwind uses a mobile-first approach for responsive design. You can apply different styles at various breakpoints using prefixes like sm:, md:, and lg:.
p-4: Default padding (small screens).md:p-8: Padding for medium screens and up.lg:p-12: Padding for large screens and up.
// app/page.js or a component file
export default function ResponsivePage() {
return (
<div className="p-4 md:p-8 lg:p-12 bg-blue-100 md:bg-green-100 lg:bg-purple-100">
<p className="text-base md:text-lg lg:text-xl font-medium">
Watch me change on different screen sizes!
</p>
</div>
);
}Tailwind Integration Check
You've learned the essential steps to integrate Tailwind CSS into your Next.js project. Let's test your understanding!
Recap: Styling with Tailwind
Congratulations! You've successfully learned how to integrate Tailwind CSS into your Next.js application.
- Installation: Added Tailwind and PostCSS dependencies.
- Configuration: Initialized and configured
tailwind.config.jsto scan your files. - Integration: Included Tailwind's base styles in your global CSS.
- Usage: Started styling components with utility classes and understood responsive design.
Tailwind CSS empowers you to build beautiful, responsive UIs rapidly with a consistent design system.
Perguntas Frequentes
A aula “Integração com Tailwind CSS” é grátis?
Sim — o texto completo de “Integração com Tailwind CSS” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de Next.js 15 Fullstack Web Apps, atualize para CoddyKit PRO. O curso de Next.js 15 Fullstack Web Apps inclui 4 aulas no total.
O que vou aprender em “Integração com Tailwind CSS”?
Configure e utilize o Tailwind CSS para desenvolver interfaces rapidamente com classes baseadas em utilitários. Você pratica Next.js 15 Fullstack Web Apps com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.
Preciso ter experiência prévia para começar Next.js 15 Fullstack Web Apps?
Nenhuma experiência prévia é necessária. Next.js 15 Fullstack Web Apps no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 2 de 4.
Quanto tempo leva a aula “Integração com Tailwind CSS”?
A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.
Posso escrever e executar código nesta aula de Next.js 15 Fullstack Web Apps?
Sim. Cada aula de Next.js 15 Fullstack Web Apps inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.
Todas as aulas deste curso
- Módulos CSS e Estilos Globais
- Integração com Tailwind CSS
- Bibliotecas de Componentes e Temas
- Design responsivo e modo escuro