Tailwind CSS Setup & Styling in Angular
Tailwind CSS is a utility-first CSS framework.
It does not give ready-made components like buttons or navbar.
It only provides predefined CSS classes.
Why use Tailwind CSS
- No default styles
- Full control using classes
- Faster UI styling
- Classes are already created, just use them
Tailwind CSS Installation (Angular)
- Open Tailwind CSS website
- Go to Docs → Installation
- Select Angular
- Follow Angular framework steps
- Skip new Angular app step (project already exists)
Run command in terminal:
npm install -D tailwindcss postcss autoprefixer
Create PostCSS config file
Create file at root level:
.postcssrc.json
Add this code:
{
"plugins": {
"tailwindcss": {},
"autoprefixer": {}
}
}
Import Tailwind in styles.css
In styles.css, add at the top:
@tailwind base;
@tailwind components;
@tailwind utilities;
Restart Angular App
Run:
ng serve
If app was already running, restart it.
How to check Tailwind is working
- Default button styles disappear
- Inputs look plain
- No borders or spacing by default
This means Tailwind is active.
Using Tailwind Classes (Example)
Heading Style
<h1 class="text-3xl text-orange-500 p-2 font-bold">
User Management
</h1>
text-3xl→ text sizetext-orange-500→ text colorp-2→ paddingfont-bold→ bold text
Button Styling Example
Delete Button
<button class="bg-red-500 text-white p-1 rounded-md m-1 cursor-pointer">
Delete
</button>
Edit Button
<button class="bg-orange-500 text-white p-1 rounded-md m-1 cursor-pointer">
Edit
</button>
Useful Tailwind Classes
bg-*→ background colortext-*→ text colorp-*→ paddingm-*→ marginrounded-*→ border radiusflex→ flex layoutcursor-pointer→ hand cursor