Styling Svelte with Tailwind CSS
Tailwind CSS is a utility-first CSS framework. It comes with predefined classes, such as flex
, pt-4
, and text-center
, which you can use directly in your markup:
<div class="flex pt-4 text-center" />
We are going to use Vite’s Svelte template as a base to set up Tailwind CSS. If you are not familiar with setting up Vite’s Svelte template, here are the quick steps to set it up:
- Run the Vite setup tool:
npm create vite@latest my-project-name -- --template svelte
This will generate a new folder named
my-project-name
containing the basic files necessary for a Svelte project. - Step into the
my-project-name
folder and install the dependencies:cd my-project-name npm install
- Once the dependencies are installed, you can start the development server:
npm run dev
With the Svelte project up and running, let’s look at what we need to do to set up Tailwind CSS.
Setting up Tailwind CSS
Tailwind CSS has...