Back to all posts
TechnologyTailwind CSS with custom theme

Setting up Tailwind CSS with a Custom Theme

1. What you'll need

2 min readUpdated May 27, 2026AI-assisted

TechSilo

AI-assisted and human-curated

1. **What you'll need**

To set up Tailwind CSS with a custom theme, you'll need Node.js (version 16.14.2 or higher) and npm (version 8.5.5 or higher). You'll also need a code editor and a terminal.

2. **Step 1: Create a new project and install Tailwind CSS**

Create a new project folder and navigate into it using cd myproject. Then, run npm init -y to create a package.json file. Install Tailwind CSS using npm install -D tailwindcss@3.1.8 postcss@8.4.14 autoprefixer@10.4.13.

3. **Step 2: Initialize Tailwind CSS configuration**

Run npx tailwindcss init -p to create a tailwind.config.js file and a postcss.config.js file. This will set up the basic configuration for Tailwind CSS.

4. **Step 3: Configure the custom theme**

Edit the tailwind.config.js file to include your custom theme. For example:

javascript
module.exports = {
  content: ['./src/**/*.{html,js}'],
  theme: {
    extend: {
      colors: {
        'custom-blue': '#3498db',
      },
    },
  },
  plugins: [],
}

This adds a custom color called custom-blue to the theme.

5. **Step 4: Create a CSS file and add Tailwind CSS classes**

Create a new file called styles.css and add the following code:

css
@tailwind base;
@tailwind components;
@tailwind utilities;

This imports the Tailwind CSS classes into your CSS file.

6. **Step 5: Compile the CSS**

Add a script to your package.json file to compile the CSS:

json
"scripts": {
  "build": "tailwindcss -i ./styles.css -o ./public/styles.css"
}

Then, run npm run build to compile the CSS.

7. **Verify it works**

Create an HTML file and add a class that uses your custom theme, for example:

html
<div class="bg-custom-blue p-4 text-white">Hello World!</div>

Open the HTML file in a browser to see the custom theme in action.

8. **Common errors**

* Error: tailwindcss is not recognized as an internal or external command: Make sure you have installed Tailwind CSS using npm install -D tailwindcss.

* Error: postcss is not recognized as an internal or external command: Make sure you have installed PostCSS using npm install -D postcss.

9. **Next steps**

Now that you have set up Tailwind CSS with a custom theme, you can start building your project. You can add more custom classes and configurations to the tailwind.config.js file as needed. You can also use other Tailwind CSS features, such as responsive design and dark mode.

Want to put this into practice?

Explore TechSilo's free developer tools for practical utilities you can use directly in your browser.

Try these free tools

Related blog posts