The quickest way to start using Tailwind CSS in your SvelteKit project is to use the SvelteKit Introduction Guide and Tailwind CSS with svelte-add to automatically setup your project. That's it, it is that easy to get Tailwind CSS configured in a SvelteKit project!

  1. Create your project

    Start by creating a new SvelteKit project if you don't have one set up already. The most common approach is outlined in the Getting Started with SvelteKit introduction.

    Terminal
    npm init svelte@next my-appcd my-app
  2. Install Tailwind CSS

    Use the community project Svelte Add to generate tailwindcss.config.cjs, postcss.config.cjs, and stub files for your css and layout. Then install tailwindcss and it's peer dependencies via npm.

    Terminal
    npx svelte-add@latest tailwindcssnpm install
  3. Configure your template paths

    Add the paths to all of your template files in the generated tailwind.config.cjs file.

    tailwind.config.cjs
    const config = {  content: ['./src/**/*.{html,js,svelte,ts}'],  theme: {    extend: {}  },  plugins: []};
    module.exports = config;
  4. Add the Tailwind directives to your CSS

    Add the @tailwind directives for each of Tailwind's layers to your ./src/app.css file if not.

    app.css
    @tailwind base;
    @tailwind components;
    @tailwind utilities;
  5. Start your build process

    Run your build process with npm run dev.

    Terminal
    npm run dev
  6. Start using Tailwind in your project

    Start using Tailwind’s utility classes to style your content.

    index.svelte
    <h1 class="text-3xl font-bold underline">  Hello world!</h1>