Tailwind

Tailwind

Tailwind is a CSS framework which contains CSS-utility classes which can be added straight to our markup (HTML).

Installation:

  1. Use the following command to install tailwind through npm
     npm install -D tailwindcss
    
  2. Create your tailwind.config.js file using :
     npx tailwindcss init
    
  3. Configure your template paths:
      /** @type {import('tailwindcss').Config} */
       module.exports = {
         content: ["./src/**/*.{html,js}"],
         theme: {
           extend: {},
         },
         plugins: [],
       }
    
  4. Add the @tailwind directives for each of Tailwind’s layers to your main CSS file :
     @tailwind base;
     @tailwind components;
     @tailwind utilities;
    
  5. Start the Tailwind CLI build process:
     npx tailwindcss -i ./src/input.css -o ./dist/output.css --watch
    
  6. Add your compiled CSS file to the and start using Tailwind’s utility classes to style your content:
     <!doctype html>
     <html>
         <head>
           <meta charset="UTF-8">
           <meta name="viewport" content="width=device-width, initial-scale=1.0">
           <link href="/dist/output.css" rel="stylesheet">
         </head>
         <body>
           <h1 class="text-3xl font-bold underline">
             Hello world!
           </h1>
         </body>
         </html>
    

Most used classes in tailwind:

  • Height:
      h-1:    height: 0.25rem;
    
  • Width:
      w-1: width: 0.25rem;
    
  • Background-color:
      bg-black: background-color: rgb(0 0 0);
    
  • Text-Color:
      text-black: color: rgb(0 0 0);
    
  • Font-Size:
      text-base: font-size: 1rem; 
    
  • Font-Weight:
      font-normal: font-weight: 400;