WindFrame is here: Design, prototype and code
sale icon End of Summer Sale 🎁 Get Contrast PRO UI library + admin template with 5 admin dahsboards, 23 pages and 10000+ components at 60% off 🎉

How to create Tailwind CSS Components for your Website


By Emmanuel Chinonso

Technical Writer

Tailwind CSS is a growing popular Utility-first CSS framework for building custom website components. It means that it doesn’t provide pre-styled components, unlike other frameworks. It's rather a low-level utility class for styling CSS properties. Tailwind CSS is continuously growing in popularity especially with the community. We are going to walk through the process of creating Tailwind CSS components for your website. We are going to build a pricing Component using HTML and Tailwind CSS.

Table of content

  • Prerequisites
  • Creating the files
  • Installation of Tailwind CSS
  • Configuration of styles
  • Building the pricing component
  • Conclusion


To follow along with our tailwind CSS tutorial, you need to have a knowledge of the following:

  • Knowledge of HTML
  • Knowledge of basic CSS
  • Knowledge of Tailwind CSS
  • Knowledge of Npm

Our pricing component will look like the image below

Create Tailwind CSS Components

Creating the files

The first thing we can do here is to create a folder for our project by running the following on our terminal


1mkdir website-component

mkdir creates a folder and you can call your folder any name of your choice. We choose to call our folder website-component. You can go ahead and change the directory to the new folder you created by running the following command.


1cd website-component.

After this, the next you will need to do is to create package.json file inside the project by running the following command


1npm init –y.

you can now go-ahead to create an Html file with the following code inside.


2    <meta charset="UTF-8">
3    <meta name="viewport" content="width=device-width, initial-scale=1.0">
4    <title>Tailwind website Component</title>

Installation of Tailwind CSS

Tailwind CSS can be used in two different ways. These include the CDN and the package manager. When using the CDN, you can simply grab the latest configuration build via CDN and link it to the head tag of your HTML


1<link href=https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css” rel =”stylesheet”>

Using the Package manger

To Install Tailwind CSS using Yarn package manager all you need to do is to run the following command on your terminal


1yarn add tailwindcss

This command will add the latest stable version of Tailwind CSS as a dependency. if you don’t wish to use the yarn. You can proceed to create a default configuration file. This file helps to customize your tailwind CSS installation. You can do this by writing the following command on your terminal.


1npx tailwindcss init.

The command will create a tailwindcss.config.js file in the root of your project directory. The file allows you to customize your Tailwind CSS however you wish. If you want to customize your entire tailwind CSS by removing the default. You can add —full to your command.


1npx tailwindcss init –full

you can learn more about the customizing your configuration file by checking out the documentation.

Configuration of styles

At these stage, we are going to configure our styles. Before we can do that, we must first create the styles folder and set up the files. We can create the styles folder by running the following command on our terminal


1mkdir <name of the folder>.

Next, we create two styles files inside the folder. Styles.css and tailwind.css files. The tailwind.css files will contain the complied output of the styles.css file while the styles.css file is where we will be importing our

Tailwind base styles.

You should copy these code and paste on your style.css file.


1@tailwind base;
2@tailwind components;
3@tailwind utilities;

After this, you can proceed to import the tailwind.css file into your project. You can do these as a link to your HTML file.


1<link href="styles/tailwind.css" rel="stylesheet">

In our tailwind css component, we wish to configure some styles to fit with the project we are going to build. First, we create an extend object inside the theme object to configure colors and font of our styles. we can do these by writing the following code


1module.exports {
2  purge[],
3  darkModefalse// or 'media' or 'class'
4  theme{
5    extend{
6      colors{
7        primary{
8          blue'hsl(237, 63%, 64%)',
9          'very-light''hsl(240,78%, 98%)',
10          light'hsl(234, 14%,74%)',
11          normal'hsl(23, 13%, 33%)',
12          dark'hsl(232,13%,33%)'
13        }
14      },
15      width{
16        custom'31%'
17      }
18    },
19    fontfamily{
20      sans[
21        'Montserrat',
22        'sans-serif',
23      ]
24    }
25  },
26  variants{
27    extend{},
28  },
29  plugins[],

The code above is how your tailwind.config.js file should look after including all the configuration you need. We created an extend object on the theme object in order to not remove the entire Tailwind CSS color palate. We rather added our own color palate to the existing ones. We also added the fontfamily object in order to add a new font family to our Tailwind CSS component. The next thing we do is to import the Montserrat we created on our config file to the styles.css file


1@import url("https://fonts.googleapis.com/csss2?family=Montserrat:wght@400;700;900&display=swap");

We can now compile and build the styles that will be generated from your styles.css file to our tailwind.css file by using the following code on the terminal


1npx tailwindcss build styles/styles.css –o styles/tailwind.css.

This command will generate a unique set of base styles and your custom styles defined in the tailwind.config.js file. We can now proceed to build our tailwind CSS components Building the website component To build any tailwind CSS components for a website, you need to follow the following procedure.

Steps for building Tailwind CSS components

  • Install tailwind CSS
  • Configure your tailwind CSS style
  • Customize your styles (optional)
  • Set up your files
  • Build your Tailwind CSS component Today, we are going to build a pricing component for a website. We have already gone through the procedure for making a component except for the last part. We can now proceed by opening our Html file and writing the following code.


1<!DOCTYPE html>
2<html lang="en">
5    <meta charset="UTF-8">
6    <meta name="viewport" content="width=device-width, initial-scale=1.0">
7    <link href="styles/styles.css" rel="stylesheet">
8    <title>Tailwind Pricing Component</title>
11<body class="h-full py-16 antialiased bg-primary-very-light font-sans">
12    <header class="flex flex-col items-center mb-12">
13        <h2 class="text-3xl text-primary-normal font-bold">Plan and Pricing</h2>
14        <div class="pt-8 w-3/5 lg:w-1/5 flex justify-around ">
15            <p class="text-sm text-gray-500 font-bold mt-2">Monthly</p>
16            <div>
17                <label for="toggle" class="relative">
18                    <input type="checkbox" name="toggle" id="" class="hidden" />
19                    <div class="absolute w-16 h-8 rounded-full shadow-inner inset-y-0 bg-purple-500 "
20                      ></div>
21                    <div class="absolute w-6 h-6 bg-white rounded-full shadow inset-y-0 mt-1 ml-1 "></div>
22                </label>
23            </div>
24            <p class="text-sm text-gray-500 font-bold mt-2 ml-16">Annually</p>
25        </div>
26    </header>
27    <section class="flex flex-col lg:flex-row items-start items-center lg:justify-center w-full w-full lg:px-10 py-12 ">
28        <article class="bg-white w-4/5 lg:w-custom mb-10 lg:px-4 px-6 py-10 text-center text-primary-dark rounded-lg">
29            <h5 class="font-bold text-base text-2xl">Free</h5>
30            <h2 class="pb-4 flex justify-center font-bold ">
31                <span class="text-3xl mt-6 mr-1"></span><span class="text-6xl"> $0</span>
32            </h2>
33            <ul class="text-sm font-bold">
34                <li class="pt-4 pb-4 text-primary-dark">2500 templates and designs</li>
35                <li class="pt-3 pb-4 text-primary-dark">2 Users Allowed</li>
36                <li class="pt-4 pb-4 text-primary-dark">500GB Storage</li>
37            </ul>
38            <button
39                class=" uppercase text-center text-sm mt-12 xl:px-24 px-12 sm:px-16 py-2 font-bold text-primary-very-light rounded-md bg-purple-500"
40        >
41                Get Started
42            </button>
43        </article>
44        <article class="lg:w-custom w-4/5 mb-10 px-6 py-16 lg:-mt-6 text-white text-center rounded-lg bg-purple-500"
45 >
46            <h5 class="font-bold text-base text-2xl">Team</h5>
47            <h2 class="font-bold pb-4 mt-2 flex justify-center">
48                <span class="text-3xl mt-6 mr-1"></span><span class="text-6xl "> $29.99</span>
49            </h2>
50            <ul class=" text-sm font-bold">
51                <li class="pt-4 pb-4">5000 template and designs</li>
52                <li class="pt-4 pb-4">20 Users Allowed</li>
53                <li class="pt-4 pb-4 ">1 TB Storage</li>
54            </ul>
55            <button
56                class="uppercase text-center text-sm mt-10 xl:px-24 px-12 sm:px-16 py-2 rounded-md font-bold bg-primary-very-light text-primary-blue">
57                Get Started
58            </button>
59        </article>
60        <article class="bg-white w-4/5 lg:w-custom mb-10 lg:px-4 px-6 py-10 text-center text-primary-dark rounded-lg">
61            <h5 class="font-bold text-base text-2xl">Enterprise</h5>
62            <h2 class="flex justify-center pb-4 font-bold">
63                <span class="text-3xl mt-6 mr-1"></span><span class="text-6xl">$49.99</span>
64            </h2>
65            <ul class="text-sm font-bold">
66                <li class="pt-4 pb-4 ">unlimited number of template and designs</li>
67                <li class="pt-4 pb-4 ">50 Users Allowed</li>
68                <li class="pt-4 pb-4 ">2 TB Storage</li>
69            </ul>
70            <button
71                class="uppercase text-center text-sm mt-12 xl:px-24 px-12 sm:px-16 py-2 rounded-md font-bold text-primary-very-light bg-purple-500"
72   >
73                Get Started
74            </button>
75        </article>
76    </section>

When we are done styling our pricing component, our webpage should look like the image below.

Create Tailwind CSS Components


In our tailwind CSS tutorial today, we learned what Tailwind CSS is, and we proceeded to show how you can set up your project to build tailwind CSS components. We used the pricing component as an example to build a Tailwind CSS component. I hope you enjoyed the article.

Create Stunning websites and web apps

Trying to build out all user interfaces and components for your website or web app from scratch can become a very tedious task. A huge reason why we created Contrast Bootstrap to help reduce the amount of time we spend doing that, so we can focus on building some other aspects of the project. Contrast Bootstrap PRO consists of a UI Kit featuring over 10000+ component variants. Together with a template of 5 admin dashboards and 23+ additional multipurpose pages template for building almost any type of website or web app. You can view a demo and learn more about Contrast by clicking here.Try contrast pro


Contrast Bootstrap PRO was built using the most popular CSS framework Bootstrap to help build your next landing, admin SAAS, prelaunch etc project with a clean, prebuilt and well documented template and UI components.Learn more about Contrast

Related Posts