Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Introduction to Tailwind CSS

Introduction to Tailwind CSS

Tailwind CSS is a utility-first CSS framework. Unlike traditional frameworks (such as Bootstrap and Foundation), it has no predefined components; instead, it provides a series of atomic CSS classes that let you apply styles directly in HTML.

Tailwind CSS is a utility-first framework, meaning it provides a large number of predefined classes rather than preset components. This allows developers to build almost any design without writing CSS.

Tailwind CSS is suitable for developers who like to control styles directly with classes in HTML; it makes rapid prototyping and developing custom designs simple and fast. However, this "no-presets" approach also means more class names to memorize and a potentially steep learning curve.

Core Features:

The following is a simple Tailwind CSS example:

The element is displayed as a box with a blue background, white text, medium padding, and large rounded corners, with the content "Hello, Tailwind CSS!".

Tailwind CSS Example

<div class=">

bg-blue-500 text-white p-4 rounded-lg

"

Hello, Tailwind CSS!

div

Try it »

Explanation:

  • bg-blue-500: Set the background color to blue, specifically level 500 in the blue palette.
  • text-white: Set the text color to white.
  • p-4: Set the padding to a medium size (16px).
  • rounded-lg: Set the border radius to a large size (8px).

Unlike traditional frameworks (such as Bootstrap and Foundation), Tailwind CSS has no predefined components; instead, it provides a series of atomic CSS classes that let you apply styles directly in HTML.

Feature Tailwind CSS Bootstrap
Styling Approach Atomic Class Names Component-based Structure
Customization Powerful and flexible Relies on variables; extension is more complex
Learning Cost Relatively low; just understand the class names Need to be familiar with components and the grid system
Community Ecosystem Growing rapidly, with rich plugins Mature but somewhat traditional
Size Optimization Supports PurgeCSS to remove unused styles Requires manual optimization

Core Philosophy of Tailwind CSS

Utility Classes First

  • Each class performs only one specific task, such as text-center for centering,mt-4 for adding a top margin.
  • Class names are simple and intuitive, with almost no need to memorize complex CSS properties.

No Component Restrictions

  • No ready-made components such as buttons or navigation bars are provided. All styles are achieved through combinations of class names.
  • It provides great freedom and suits custom design needs.

Rapid Development

  • Write styles directly in HTML without frequently switching to CSS files.
  • Reduce problems of style overrides and redundant CSS.

Applicable Scenarios of Tailwind CSS

  • Rapid prototyping


Quickly design and adjust pages without worrying about style refactoring.

-

Team collaboration
Use configuration files uniformly to avoid style conflicts and keep maintenance costs low.

-

Responsive Layout
Built-in responsive design support for easy multi-device compatibility.

-

Medium and Large Projects
Combined with tools (such as PurgeCSS) to optimize the output CSS file, meeting the needs of complex projects.