The Wayback Machine - https://web.archive.org/web/20240706071119/https://www.geeksforgeeks.org/introduction-to-tailwind-css/
Open In App

Introduction to Tailwind CSS

Last Updated : 07 Jun, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

Tailwind CSS is a utility-first CSS framework that streamlines web development by providing a set of pre-designed utility classes. These classes enable rapid styling without writing custom CSS, promoting consistency and scalability. Tailwind’s approach shifts focus from traditional CSS components to functional classes, empowering developers to efficiently build responsive and visually appealing interfaces with minimal effort.

Why Tailwind CSS?

  • The faster UI-building process.
  • It is a utility-first CSS framework which means we can use utility classes to build custom designs without writing CSS as in the traditional approach.

Advantages of Tailwind CSS

  • No more silly names for CSS classes and IDs.
  • Minimum lines of Code in CSS file.
  • We can customize the designs to make the components.
  • Makes the website responsive.
  • Makes the changes in the desired manner. 
  • CSS is global in nature and if make changes in the file the property is changed in all the HTML files linked to it. But with the help of Tailwind CSS, we can use utility classes and make local changes.

Why use Tailwind over other CSS framework?

  • Tailwind’s utility-first methodology offers granular control over styling, enabling precise customization and faster prototyping without overriding framework styles.
  • Unlike traditional frameworks, Tailwind allows extensive customization and avoids pre-built component styles, offering flexibility in design.
  • Tailwind’s utility classes eliminate the need for writing custom CSS, resulting in smaller file sizes and faster load times.
  • Tailwind simplifies responsive design with built-in classes, facilitating the creation of mobile-friendly layouts without additional media queries or complex styling.
  • With its extensive documentation and intuitive syntax, Tailwind accelerates development by streamlining the styling process and reducing iteration time.

How to Install and use Tailwind CSS in a Project?

There are two methods to use Tailwind CSS in a project: you can either install it on your server or use it through a CDN link.

Installation of Tailwind CSS via npm

  • Step 1:
npm init -y
  • Step 2:
npm install tailwindcss
  • Step 3:Use the @tailwind directive to inject Tailwind’s base, components, and utility styles into your CSS file.
@tailwind base;
@tailwind components;
@tailwind utilities;
  • Step 4: This is used to create a config file to customize the designs. It is an optional step.
npx tailwindcss init
  • Step 5:This command is used to compile style.css is the file that has to be compiled and output.css is the file on which it has to be compiled. If the file output.css is not created earlier then it will automatically be created.
npx tailwindcss build styles.css -o output.css

Method 2: Use Tailwind CSS via CDN

The simplest method to use Tailwind CSS in a project via CDN link with installing the module. Just include the following CDN link in the <head> section of your HTML file.

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

Limitation of Tailwind CSS

There are some limitations when CDN is used. Some of them are:

  • Customize Tailwind’s default theme can’t be used.
  • Directives like @apply, @variants, etc can’t be used.
  • Can’t install third-party plugins.

Example: In this example, we imports Tailwind CSS via CDN and applies margin to the body. It includes a heading styled with Tailwind utility classes and content about Tailwind CSS.

HTML
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">

    <!-- Tailwind CSS CDN link -->
    <link href=
"https://unpkg.com/tailwindcss@^2/dist/tailwind.min.css" 
        rel="stylesheet">
</head>

<body class="m-4">
    <h1 class="text-green-500 text-4xl font-bold">
        Geeksforgeeks
    </h1>

    <p><strong>Tailwind CSS Tutorial</strong></p>

    <p>
        You can use Tailwind CSS as a replacement 
        of CSS, this is a framework that increase 
        your pace to design any website.
    </p>
</body>

</html>

Output

Tailwind Sample Output


Previous Article
Next Article

Similar Reads

What is the use of the tailwind.config.js file in Tailwind CSS ?
The tailwind.config.js file in Tailwind CSS serves as a central configuration hub for customizing the framework. It allows you to define colors, fonts, breakpoints, and more, tailoring Tailwind to fit your project's specific design and functionality requirements. Syntax:/** @type {import('tailwindcss').Config} */module.exports = { content: [], them
1 min read
Storybook-tailwind. How should I add tailwind to storybook
In this article, we will guide you through the process of adding Tailwind CSS to Storybook to enhance your UI development. Storybook is an open-source UI that helps developers create reusable, organized UI components with proper documentation independently. Tailwind CSS is basically a utility-first CSS framework for building rapid custom UI. Prereq
2 min read
Which CSS framework is better Tailwind CSS or Bootstrap ?
In this article, we will see which CSS framework is better tailwind CSS or bootstrap. Both are widely used CSS frameworks for styling the front end. We will understand each one of them in detail. Both frameworks have their own pros and cons so it depends upon the type of application you are going to build and accordingly you can choose the best fra
5 min read
How to Add a @tailwind CSS Rule for CSS Checker ?
Tailwind CSS is basically a Utility first CSS framework for building rapid custom UI. It is a highly customizable, low-level CSS framework that gives you all of the building blocks that you need. Also, it is a cool way to write inline styling and achieve an awesome interface without writing a single line of your own CSS. In this article, we will ex
4 min read
How to use CSS Animations with Tailwind CSS ?
Tailwind CSS classes are used to style elements and apply animations effortlessly. Utilize Tailwind's animation utility classes to add dynamic visual effects. Combine Tailwind CSS with custom CSS animations for versatile and engaging web designs. Table of Content Tailwind CSS Animation Utility ClassesCSS Animations with Tailwind CSS and JavaScriptT
3 min read
Tailwind CSS Text Color
This class accepts lots of value in tailwind CSS in which all the properties are covered in class form. By using this class we can color any text. In CSS, we do that by using the CSS Color property. Text Color classes: text-transparent: The text color will be transparent.text-current: The text color will depend on the parent element color.text-blac
2 min read
Underline Hover Animation Effect using Tailwind CSS
The Tailwind CSS underline animation is a visual effect that can be added to any text or heading or a specific word in the web page using the Tailwind CSS utility framework. The basic function of this effect is this creates an underline animation from left to right with a smooth transition, in simpler words it created underline animation whenever w
3 min read
How to set width transition in Tailwind CSS ?
In Tailwind CSS, the transition utility is used to apply a width transition to an element. The transition utility accepts a list of properties, duration, and timing functions for the transition. Approach: To create a width transition, we can use the transition class and a duration and easing function to animate the width change. For example, we can
2 min read
How to enable dark mode in Tailwind CSS ?
In this article, we will see how to enable dark mode in Tailwind CSS. there are many ways, some of them we will see. Tailwind CSS has special features to enable dark mode on the webpage. To enable dark mode in Tailwind CSS, we can define a dark theme in our Tailwind config file section and then we have to use the dark class in our HTML to apply it
3 min read
How to Remove Arrow on Input Type Number with Tailwind CSS ?
When using the input element with the type="number" attribute, most browsers will display an arrow control (also known as a spinner) at the right side of the input field. This control allows users to increment or decrement the value using the up and down arrows. However, in some cases, you may want to remove this arrow control for styling or UX pur
2 min read
three90RightbarBannerImg