DEV Community

@randydigital
@randydigital

Posted on

3 1

Set up TailWind CSS in SvelteKit project

Rapidly build modern websites using TailWind CSS inside your SvelteKit projects.

Set up a new SvelteKit project and install Tailwind and AutoPrefixer

mkdir my-app
cd my-app
npm init svelte@next
npm install -D tailwindcss autoprefixer
Enter fullscreen mode Exit fullscreen mode

Create a postcss.config.cjs file in the root directory of your project

SvelteKit is bundled by Vite which comes with postcss support out of the box.

module.exports = {
    plugins: {
        autoprefixer: {},
        tailwindcss: {},
    },
}
Enter fullscreen mode Exit fullscreen mode

TailWind Config

Create a tailwind.config.cjs in the root of your project. You can also run npx tailwind init, but be sure to rename the extension to .cjs

module.exports = {
  mode: 'jit',
  content: ['./src/**/*.svelte'],
}
Enter fullscreen mode Exit fullscreen mode

Create and import the CSS

Add these tags somewhere in your CSS that PostCSS knows where to insert the tailwind styles. A good place to import these is within __layout.svelte inside our style tag.

<style>
    ...
    @tailwind base;
    @tailwind components;
    @tailwind utilities;
</style>
Enter fullscreen mode Exit fullscreen mode

That's it! You can now use TailWind CSS classes like flex, pt-4, text-center and rotate-90 that can be composed to build any design, directly in your markup.

Image of Docusign

Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs