Installation
Setting up Tailwind CSS in an Qwik project.
Start by creating a new Qwik project if you don't have one set up already. The most common approach is to use Create Qwik.
npm create qwik@latest empty my-projectcd my-project
Install @tailwindcss/vite
and its peer dependencies via npm.
npm install tailwindcss @tailwindcss/vite
Add the @tailwindcss/vite
plugin to your Vite configuration.
import { defineConfig } from 'vite'import { qwikVite } from "@builder.io/qwik/optimizer";import { qwikCity } from "@builder.io/qwik-city/vite";// …import tailwindcss from '@tailwindcss/vite'export default defineConfig(({ command, mode }): UserConfig => { return { plugins: [ tailwindcss(), qwikCity(), qwikVite(), tsconfigPaths(), ], // … }})
Add an @import
to ./src/global.css
that imports Tailwind CSS.
@import "tailwindcss";
Run your build process with npm run dev
.
npm run dev
Start using Tailwind’s utility classes to style your content.
import { component$ } from '@builder.io/qwik'export default component$(() => { return ( <h1 class="text-3xl font-bold underline"> Hello World! </h1> )})