Logo

dev-resources.site

for different kinds of informations.

Adding Tailwind CSS to Nuxt 3 🍃 (2023)

Published at
1/1/2023
Categories
nuxt
nuxt3
tailwindcss
Author
tao
Categories
3 categories in total
nuxt
open
nuxt3
open
tailwindcss
open
Author
3 person written this
tao
open
Adding Tailwind CSS to Nuxt 3 🍃 (2023)

Introduction

In this post, we'll introduce Nuxt Tailwind, a package for the Tailwind CSS library.

Tailwind is a powerful tool for rapidly styling modern web applications.

Utility-first CSS

Utility-first CSS is a design approach that uses pre-defined classes to style HTML elements. We refer to these classes as utilities.

One of the main advantages of utility-first CSS is that it allows you to style elements quickly without coupling them to custom CSS through stylesheets. This approach can be difficult to maintain when an app grows bigger.

You may argue that this will lead to code repetition, but when combined with component-based web frameworks (e.g. React, Vue), repetition is minimised while still keeping elements decoupled from stylesheets.

Tailwind

Tailwind isn't just a fantastic way of writing CSS; it's also great to build with, due to a variety of development features:

  • Easy configuration of built-in utilities
  • Just-in-time compiler to avoid build times entirely
  • Many great plugins available (typography, forms, etc.)

Installation

Official documentation for using Tailwind with Nuxt can be found here.

Install the package:

yarn add --dev @nuxtjs/tailwindcss
Enter fullscreen mode Exit fullscreen mode

Add the module to your Nuxt configuration:

// nuxt.config.ts

export default defineNuxtConfig({
  // ...
  modules: [
    // ...
    '@nuxtjs/tailwindcss',
  ],
})
Enter fullscreen mode Exit fullscreen mode

And just like that, you can now start adding Tailwind classes to your Nuxt components!

Classes

To get started, add some of Tailwind's in-built utilities to an element's class attribute.

<template>
  <NuxtLink
    to="/"
    class="font-semibold text-gray-50 hover:text-gray-400 duration-100"
  >
    Home
  </NuxtLink>
</template>
Enter fullscreen mode Exit fullscreen mode

New to Tailwind? Your best bet is to check out the Tailwind docs.

Configuration

Create a tailwind.config.js file at the root of your project to configure the default theme.

module.exports = {
  theme: {
    screens: {
      sm: '640px',
      md: '768px',
      lg: '1024px',
      xl: '1280px',
    },
    extend: {
      colors: {
        linkedin: {
          primary: '#0A66C2',
          lighter: '#378fe9',
          darker: '#004182',
        },
      },
    },
  },
  plugins: [require('@tailwindcss/typography')],
}
Enter fullscreen mode Exit fullscreen mode

Viewer

Nuxt Tailwind exposes a /_tailwind/ route in development where your Tailwind configuration is rendered as a library.

May your web apps become colourful and flashy 😉


Hey, guys! Thank you for reading. I hope that you enjoyed this.

Keep up to date with me:

nuxt3 Article's
30 articles in total
Favicon
Renderización Dinámica de Componentes en Vue 3 y Nuxt 3: Guía Práctica y Caso Real
Favicon
Nuxt3 CSR Background Image Lazy loading
Favicon
DartsMash: a platform for darts enthusiasts
Favicon
Nuxt3 : limitation on Layers & Modules
Favicon
Using postgresql with nuxt3 by ORM(sequelize)
Favicon
Nuxt3 : API error handling
Favicon
Nuxt Icon
Favicon
Integrating Nuxt 3 with Recaptcha v3 for Token Handling 🤖🔐
Favicon
Nuxt 3 Starter
Favicon
Nuxt 3 Builder: A Tailored Editor for Developers
Favicon
Build an X clone w/ Nuxt UI
Favicon
Nuxt3 Form with Feedback
Favicon
Custom 404 Page in Nuxt
Favicon
Nuxt 3 authentication with pinia
Favicon
Nuxt 3, UnoCSS, and Preset rem to px
Favicon
Configuração e instalação do Nuxt 3
Favicon
The DevOnly component in Nuxt 3: A developer's best friend
Favicon
Storyblok Nuxt 3 news 🗞
Favicon
Implementing OpenID Connect (OIDC) Authentication with Nuxt 3
Favicon
Authentication in Nuxt 3
Favicon
Adding ESLint and Prettier to Nuxt 3 ✨ (2024)
Favicon
API Management in Nuxt 3 with TypeScript
Favicon
Docker and Nuxt 3
Favicon
Pinia and Nuxt 3
Favicon
Adding Pinia to Nuxt 3 🍍 (2023)
Favicon
Adding Vitest to Nuxt 3 ⚡ (2023)
Favicon
Adding Tailwind CSS to Nuxt 3 🍃 (2023)
Favicon
How I set up eslint in my projects
Favicon
How to create and minify Vuetify 3 Nuxt 3 project bundle
Favicon
Build an Intercom clone in Nuxt.js - Part Two

Featured ones: