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

Introduction to Tailwind CSS

Last Updated : 07 Oct, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

Tailwind CSS is a utility-first CSS framework that simplifies web development by providing a set of pre-designed utility classes. These utility classes enable you to build custom designs without writing any custom CSS, promoting consistency, scalability, and efficiency.

Tailwind shifts the focus from traditional CSS components to functional utility classes, empowering you to build responsive and visually appealing interfaces with ease and speed.

Why Use Tailwind CSS?

Tailwind CSS offers a faster UI-building process by allowing you to utilize utility classes directly in their HTML, eliminating the need for custom styles. Here’s why Tailwind CSS stands out:

  • Utility-first approach: Tailwind allows custom designs without writing custom CSS, making the development process more streamlined.
  • Responsive by default: Tailwind simplifies the creation of responsive designs with built-in utility classes.
  • Granular control: It offers extensive control over your design, enabling precise customization and faster prototyping.

Key Advantages of Tailwind CSS

  1. No need for complex class names: You don’t have to worry about naming conventions for CSS classes and IDs.
  2. Minimized CSS code: Tailwind reduces the need for large custom CSS files, keeping your codebase smaller and more manageable.
  3. Easy customization: Tailwind allows easy customization of designs without writing additional CSS, helping you create reusable components.
  4. Built-in responsiveness: Tailwind’s classes are optimized for responsiveness, allowing developers to create mobile-friendly layouts effortlessly.
  5. Scoped styles: Tailwind’s utility classes help in making local changes to specific elements without affecting the entire stylesheet, unlike traditional global CSS.

Why Choose Tailwind Over Other CSS Frameworks?

Tailwind CSS stands out from traditional frameworks like Bootstrap or Foundation because of its utility-first methodology, which offers:

  • Granular control over styling: Tailwind provides control at the atomic level, allowing you to customize each aspect of your design.
  • Faster prototyping: By using utility classes, developers can iterate faster without worrying about conflicting styles or overriding pre-built components.
  • Lightweight code: Tailwind generates smaller CSS files by purging unused styles, improving website performance with faster load times.
  • Simplified responsive design: Tailwind’s utility classes make responsive design effortless without the need for custom media queries.
  • Extensive documentation: Tailwind provides clear documentation and an intuitive syntax that speeds up the development process.

Installing and Using Tailwind CSS in a Project

There are two main methods to use Tailwind CSS into your project: installing it locally or using a CDN link.

Method 1: Install Tailwind CSS via npm

Follow these steps to set up Tailwind CSS in your project using npm:

  • Step 1: Initialize your project
npm init -y
  • Step 2: Install Tailwind CSS
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 quickest way to start using Tailwind CSS is by including a CDN link in the <head> section of your HTML file. Here’s an example:

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

This method allows you to use Tailwind without installing it on your server. However, there are some limitations when using the CDN version:

  • Customization: You cannot customize Tailwind’s default theme.
  • Directives: You cannot use directives like @apply and @variants.
  • Plugins: Third-party plugins cannot be installed.

Example: Using Tailwind CSS via CDN

Below is a basic example that imports Tailwind CSS via CDN and applies margin to the body. The heading is styled with Tailwind’s utility classes.

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
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
Top 10 Tailwind CSS Templates and Themes
CSS adds visual weight to our websites. It makes them look, smoother, better, and easier to use. But writing CSS can be a headache. Thankfully there are a lot of CSS frameworks out there – like Tailwind, Bootstrap, Foundation, Spectre, Bulma, etc. for creating and rendering beautiful user interfaces. Tailwind CSS is basically a utility-first CSS fr
5 min read
How to Change the Underline Color in Tailwind CSS ?
The Tailwind underline class adds an underline to the text, and the decoration-color class changes the color of the text-decoration property. Both classes can be used together to add an underline and color to the text. Syntax: The syntax for the tailwind underline and decoration-color classes is as follows. <element class="underline decoration-{
3 min read
How to change svg icon colors with Tailwind CSS ?
SVG stands for Scalable Vector Graphics and is an XML-based ( can be edited ) vector image format. SVG is commonly used for icons, animations, interactive charts, graphs, and other dynamic graphics in the browser. As it is XML-based, you can easily edit or change the SVG icon colors with Tailwind. Approach: You can simply customize the class of SVG
3 min read
Tailwind CSS Stroke Width
This class accepts lots of value in tailwind CSS in which all the properties are covered in form. This class is used to set the width of a border in an SVG shape. This property can only be applied to elements that have a shape or text content elements. In CSS, we did that by using the CSS Stroke-width property. Stroke Width classes: stroke-0: This
1 min read
Can I Create Masonry Layout using Tailwind CSS Utility Classes ?
Yes, you can create a Masonry layout using Tailwind CSS utility classes. A Masonry layout is a popular design pattern used for displaying images or other elements in a grid-like structure where each item is of varying height and width. This layout creates a visually appealing and dynamic design that helps to break the monotony of a traditional grid
3 min read
Tailwind CSS Filter
The filter class is used to set the visual effect of an element. This class is mostly used in image content. In CSS, we do that by using the CSS filter property. Tailwind CSS newly added feature filter in 2.1 version. Filter Classes: filter: This class is used to enable filters.filter-none: This class is used to remove filters. Syntax: <element
1 min read
Tailwind CSS Grayscale
The Grayscale class is used to apply a filter to the image to set the grayscale of the image. In CSS, we do that by using the CSS grayscale() Function. Tailwind CSS newly added feature brightness in 2.1 version. Grayscale: grayscale-0: This class is used to represents the original image.grayscale: This class is used to represents the linear multipl
1 min read
Tailwind CSS Mix Blend Mode
This class accepts lots of value in Tailwind CSS in which all the properties are covered in class form. This class is used to specify how an element’s content should be blended with the background. In CSS, we can do that by using the CSS mix-blend-mode property. Mix Blend Mode classes : mix-blend-normal: No blending is applied to the element.mix-bl
3 min read
Tailwind CSS Ring Offset 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 ring-offset. In CSS, we do that by using the CSS Color property. Ring Color classes: ring-offset-transparent: The ring-offset color will be transparent.ring-offset-current: The ring-offset color will depend on
2 min read
Tailwind CSS Flex Wrap
The CSS flexbox is a vital feature to develop the frontend, there are three wraps available in CSS so in tailwind CSS all the properties are covered as in class form. It is the alternative of CSS flex-wrap Property for fast development of front-end. Note: To activate the flex-wrap you have to include the flex class in your element before the flex-w
2 min read
Tailwind CSS Flex
The CSS flexbox is a vital feature to develop the frontend, there is four flex available in tailwind CSS all the properties are covered as in class form. It is the alternative of CSS flex Property for fast development of front-end. It is used to set the length of flexible items. The flex class is much responsive and mobile-friendly. It is easy to p
5 min read
Tailwind CSS Flex Grow
The CSS flexbox is a vital feature to develop the frontend, there is two flex-grow available in tailwind CSS all the properties are covered as in class form. It is the alternative of CSS flex grow Property for the fast development of the front-end. This class specifies how much the item will grow compared to other items inside that container. In ot
2 min read
Tailwind CSS Order
Order is one of the best feature of tailwind CSS by using this class we can order the flex and grid items according to our requirements. There are lots of order class. This class is used to render flex and grid items in a different order than they appear in the DOM. Order: order-1order-2order-3order-4order-5order-6order-7order-8order-9order-10order
1 min read
Tailwind CSS Grid Template Columns
This class accepts more than one value in tailwind CSS all the properties are covered as in class form. It is the alternative of CSS grid-template-columns property in CSS. It is used to set the number of columns and size of the columns of the grid, here we will do the same but for fast development of front-end. The number of columns is set by the n
2 min read
Tailwind CSS Gap
This class accepts more than one value in tailwind CSS all the properties are covered as in class form. It is the alternative to the CSS gap property. This class is used to set the spacing also caller gutter between the rows and columns. As like column-gap and row-gap using separately both so that one can use simply gap property that can given colu
3 min read
Tailwind CSS Grid Auto Flow
This class accepts more than one value in tailwind CSS all the properties are covered as in class form. It is the alternative of CSS grid-auto-flow property and it is used to specify how auto-placed items get flowed into the grid items using Tailwind CSS. Grid Auto Flow: grid-flow-rowgrid-flow-colgrid-flow-row-densegrid-flow-col-dense grid-flow-row
2 min read
Tailwind CSS List Style Position
This class accepts lots of value in tailwind CSS in which all the properties are covered as in class form. It is the alternative to the CSS list-style-position Property. This class specifies the position of the marker box with respect to the principal block box. List Style Position classes: list-inside: In this value, the marker is the first elemen
1 min read
How to use template literals in Tailwind CSS to change classes dynamically ?
Tailwind CSS is a popular utility-first CSS framework used by many web developers to build modern and responsive user interfaces. It provides a wide range of pre-defined classes that can be used to style elements, but what if we want to dynamically change classes based on some condition or user input? This is where template literals come in handy.
6 min read
Tailwind CSS Text Opacity
This class accepts lots of value in tailwind CSS in which all the properties are covered as in class form. By using this class we can set the opacity of any text. In CSS, we do that by using the CSS Opacity property. Text Opacity: text-opacity-0: Control the opacity of an element's placeholder color using the text-opacity-{amount} utilities. Note:
2 min read
Tailwind CSS Text Overflow
This class accepts more than one value in tailwind CSS. All the properties are covered in class form. It is the alternative to the CSS text-overflow property. This class is used to specify that some text has overflown and hidden from view. The whitespace class must be set to nowrap and the overflow class must be hidden. Text Overflow classes: trunc
2 min read
Tailwind CSS Text Transform
This class accepts more than one value in tailwind CSS. All the properties are covered in class form. It is the alternative to the CSS text-transform property. This class is used to control the capitalization of the text. Text Transform classes: uppercase lowercase capitalize normal-case uppercase: It is used to convert or transform all characters
2 min read
Tailwind CSS Vertical Alignment
This class accepts more than one value in tailwind CSS. All the properties are covered in class form. It is the alternative to the CSS vertical-align property. This class is used to specify the vertical alignment of the table-box or inline element. Vertical Alignment classes: align-baseline: It aligns the element baseline corresponding to the basel
2 min read
Tailwind CSS Background Image
This class accepts more than one value in tailwind CSS. All the properties are covered in class form. It is the alternative to the CSS background-image property. This class is used to set one or more background images to an element. By default, it places the image on the top left corner. To specify two or more images, separate the URLs with a comma
2 min read
Tailwind CSS Background Size
This class accepts more than one value in tailwind CSS. All the properties are covered in class form. It is the alternative to the CSS background-size property. This class is used to set the size of the background image. Background Size classes: bg-autobg-coverbg-contain bg-auto: It is used to set the background-size class to its default value. It
2 min read
three90RightbarBannerImg