Tailwind CSS

Purpose

  • It is used to create a set of utility class based on your theme configurations

Installation

  • Install the dependency

# Using npm
npm install tailwindcss autoprefixer postcss postcss-cli
  • Create a CSS file and inject tailwind's bases, components and utilities on it

input.css
@tailwind base;

@tailwind components;

@tailwind utilities;
  • Generate the tailwind config, so that we can customize the style on it later

npx tailwindcss init --full
  • Set up post css configuration file

// postcss.config.js
module.exports = {
  plugins: {
    tailwindcss: {},
    autoprefixer: {},
  }
}
  • Compile into a set of utility classes on output.css based on your settings and input.css

Utility-First Fundamentals

  • Using utility classes to build custom designs without writing CSS to prevent from the growth css file

  • The reusability of style is achieved based on separation of component instead of css class

Configuration

  • The configuration is mainly include content, theme & plugins

Content

  • The content section of your tailwind.config.js file is where you configure the paths to all of your HTML templates, JavaScript components, and any other source files that contain Tailwind class names.

  • Tailwind uses a very simple approach to detecting class names in your content, and generate the your used class into output.css

Theme

  • The theme section of your tailwind.config.js file is where you define your project’s design system

  • You can extend or override the default theme

Plugin

  • Apply 3rd plugin which is a set of configuration to override or extend the theme

Directive

  • Directives are custom Tailwind-specific at-rules you can use in your CSS that offer special functionality for Tailwind CSS projects.

@tailwind

  • Base class stands for the a set of tailwind default element class

  • Component class stands for the custom class that applied tailwind utility class

  • Utilities class stands for the utility class that the content used

@layer

  • To customize the tailwind class in different levels

@apply

  • Use @apply to inline any existing utility classes into your own custom CSS.

@config

  • To specify the source tailwind config file

Functions

  • Tailwind adds a few custom functions you can use in your CSS to access Tailwind configuration values.

Component Library

Last updated

Was this helpful?