Nuxt offers flexible styling options. You can write your own styles, use CSS preprocessors, integrate UI frameworks, or leverage modern CSS-in-JS solutions.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/nuxt/nuxt/llms.txt
Use this file to discover all available pages before exploring further.
Local Stylesheets
Place your local stylesheets in theapp/assets/ directory for optimal organization and build tool processing.
Importing in Components
You can import stylesheets directly in your pages, layouts, and components using JavaScript imports or CSS@import statements.
Global CSS with the CSS Property
Use thecss property in your Nuxt configuration to include stylesheets across all pages of your application.
- Inlined in the HTML rendered by Nuxt
- Injected globally
- Present on all pages
Working with Fonts
Place local font files in yourpublic/ directory (e.g., public/fonts/) and reference them in stylesheets using url().
NPM Stylesheets
You can reference stylesheets distributed through npm. Here’s an example using theanimate.css library:
External Stylesheets
Include external stylesheets by adding a link element in the head section using theapp.head property:
Dynamic Stylesheets
Use theuseHead composable to dynamically add stylesheets in your code:
CSS Preprocessors
Install your preferred preprocessor to use Sass, SCSS, Less, or Stylus:lang attribute in your component styles or import files in your configuration:
Preprocessor Options
Inject code into preprocessed files (like Sass partials) using Vite’s preprocessor options:Single File Component Styling
Vue SFCs provide excellent built-in styling capabilities without requiring CSS-in-JS solutions.Dynamic Styles with v-bind
Reference JavaScript variables in your style blocks using thev-bind function:
Scoped Styles
Use thescoped attribute to style components in isolation:
CSS Modules
Access CSS Modules with themodule attribute and the injected $style variable:
PostCSS
Nuxt comes with PostCSS built-in. Configure it in yournuxt.config file:
- postcss-import: Improves the
@importrule - postcss-url: Transforms
url()statements - autoprefixer: Automatically adds vendor prefixes
- cssnano: Minification and purge
CSS Frameworks and Libraries
Nuxt supports popular styling libraries through dedicated modules:- UnoCSS: Instant on-demand atomic CSS engine
- Tailwind CSS: Utility-first CSS framework
- Nuxt UI: A UI Library for Modern Web Apps
- Panda CSS: CSS-in-JS engine with build-time atomic CSS
Loading Web Fonts
Use the Nuxt Google Fonts module to easily load Google Fonts, or leverage UnoCSS’s web fonts preset for broader provider support.Performance Optimization
LCP Optimizations
Speed up global CSS file downloads:- Use a CDN for files physically closer to users
- Compress assets with Brotli
- Use HTTP2/HTTP3 for delivery
- Host assets on the same domain