Overview
This article will show you how to setup Tailwind CSS
in a SvelteKit
project.
Steps
- Set up the project and install
taliwindcss
and its peer dependencies vis npm.
Terminalnpm init svelte@next sveltekit-democd sveltekit-demonpm install -D tailwindcss postcss autoprefixer
- Generate
tailwind.config.cjs
andpostcss.config.cjs
configuration files
Terminalnpx tailwind init tailwind.config.cjs -pmv postcss.config.js postcss.config.cjs
- Configure your template paths in
tailwind.config.cjs
./tailwind.config.cjs1module.exports = {2 content: ['./src/**/*.{html,js,svelte,ts}'],3theme: {4 extend: {}5}
- Add the Tailwind directives to your CSS
Create a
./src/app.css
file and add the@tailwind
directives for each of Tailwind's layers../src/app.css1@tailwind base;2@tailwind components;3@tailwind utilities;
- Import the CSS file
Create a layout svelte file and import the
app.css
file we've just created in the step 4../src/routes/__layout.svelte1<script>2 import "../app.css"3</script>45<slot />
- Run npm development
Terminalnpm run dev
- Try using Tailwind
Open up
index.svelte
and try this../src/routes/index.svelte1<h1 class='font-bold underline'>Hello Tailwind!!!</h1>
Comments