
Css Support in NextJS
🎨 CSS Support in Next.js
Next.js provides multiple ways to style applications, from global styles to component-level styles. You can use CSS Modules, Styled Components, Tailwind CSS, or Sass for styling.
📌 1. Global CSS (styles.css)
Next.js allows global styles using standard CSS files.
🔹 Example: Adding Global CSS
1️⃣ Create a styles/global.css
file:
<button @tailwind base;@tailwind components;@tailwind utilities;
4️⃣ Use Tailwind classes in components:
export default function Home() { return <button import styled from "styled-components";const Button = styled.button` background: blue; color: white; padding: 10px 20px; border: none; cursor: pointer;`;export default function Home() { return <Button>Styled Buttonimport "../styles/global.scss";
✅ Supports variables, nesting, and mixins
📌 6. Inline Styles (JSX Style)
You can use inline styles with the style
attribute.
🔹 Example: Inline Styles
export default function Home() { return ( <div> export default function Home() { return <button className="btn btn-primary">Bootstrap Button</button>;}
✅ Pre-designed UI components
📌 8. Global vs. Scoped Styles
CSS Method | Scope | Best For |
---|---|---|
Global CSS | Entire App | Reset styles, base styles |
CSS Modules | Component Only | Preventing class conflicts |
Tailwind CSS | Utility Classes | Fast development, customization |
Styled Components | Component Only | Scoped styles, dynamic styling |
SCSS/SASS | Global & Scoped | Variables, mixins, nesting |
Inline Styles | Single Element | Quick styling |
🚀 Summary
✅ Use Global CSS for basic styles
✅ Use CSS Modules for component-specific styles
✅ Use Tailwind CSS for fast styling
✅ Use Styled Components for dynamic, component-based styles
✅ Use SCSS/SASS for advanced styling