Skip to content
Tutorials Center
My learning

Topics

Lesson 20 of 74 ยท Components in Depth

Using Tailwind, Bootstrap and Sass in Angular

Add Sass, Tailwind CSS and Bootstrap (ng-bootstrap) to an Angular project. Learn where global styles go, how encapsulation interacts with frameworks, and when to choose each, with runnable stand-ins.

Angular does not decide how your app looks. That freedom raises a practical question on day one of most projects: which styling tools do you add, and how do they fit the Angular build? This lesson covers the three most common choices: Sass (a better way to write CSS), Tailwind CSS (utility classes) and Bootstrap (ready-made components, with the Angular-native ng-bootstrap for the interactive parts).

Everything here builds on Styling and View Encapsulation: remember that component styles are scoped to their component, while global styles apply everywhere. Frameworks are global styles, so the question is always where to load them and how they interact with encapsulation.

Real versus stand-in. Installing packages and running the build is not possible on this site, so the bash, json, scss, css and typescript blocks are real configuration to read and copy. The runnable examples are small TypeScript models of what the tools do (a utility-class generator and a Sass-style breakpoint loop). Package versions and exact file names change between releases; check each tool's current Angular guide when you set up a project.

Where global styles live

A new project has src/styles.css (or .scss). The styles array in angular.json lists every global stylesheet the build includes:

JSON
"styles": ["src/styles.css"]

Add vendor CSS or an extra file by adding it to that array. Use global styles for things that should apply everywhere: a reset, fonts, CSS variables for your design tokens, and framework base styles. Everything that belongs to one component stays in that component's styles or styleUrl.

Option 1: Sass (SCSS)

Sass adds variables, nesting, mixins, loops and modules to CSS. Angular supports it out of the box: choose it when you create the project (ng new my-app --style=scss) or rename files to .scss and update the references.

SCSS
// src/styles/_tokens.scss
$brand: #2563eb;
$radius: 0.5rem;

$breakpoints: (
  'sm': 40rem,
  'md': 48rem,
  'lg': 64rem,
);

@mixin up($name) {
  @media (min-width: map-get($breakpoints, $name)) {
    @content;
  }
}
SCSS
// src/app/card/card.scss
@use '../../styles/tokens' as t;

.card {
  border-radius: t.$radius;
  border: 1px solid color-mix(in srgb, t.$brand 30%, white);
  padding: 1rem;

  @include t.up('md') {
    padding: 2rem;
  }

  &:hover {
    border-color: t.$brand;
  }
}

@use loads a Sass module with a namespace (t.), which replaced the old @import. If you want short imports such as @use 'tokens', add the folder to the build:

JSON
"stylePreprocessorOptions": { "includePaths": ["src/styles"] }

Modern CSS now does a lot of what Sass was needed for: custom properties (--brand) change at run time and can be themed, native nesting works in current browsers, and color-mix() mixes colors. Sass still wins for loops, mixins, functions and build-time maps. A good approach is Sass for build-time logic and CSS variables for values that change at run time, such as dark mode.

A breakpoint loop, modeled

This stand-in does what a Sass @each loop over a map does: it generates one media query per breakpoint, written out as plain CSS.

TypeScript What a Sass @each over a map produces

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or readFileSync(0)), it gets the next line from this box.

Option 2: Tailwind CSS

Tailwind gives you small utility classes such as flex, gap-4 and text-lg, and you compose them in the template. It scans your files, finds the class names you use and generates only that CSS, so the final stylesheet is small.

Recent Tailwind versions work with Angular through a PostCSS plugin. The setup has three steps:

Terminal
npm install tailwindcss @tailwindcss/postcss postcss
JSON
// .postcssrc.json (project root)
{
  "plugins": {
    "@tailwindcss/postcss": {}
  }
}
CSS
/* src/styles.css */
@import "tailwindcss";

Restart ng serve and use classes in any template:

TypeScript
@Component({
  selector: 'app-price-card',
  template: `
    <article class="rounded-xl border border-slate-200 p-6 shadow-sm dark:border-slate-700">
      <h2 class="text-lg font-semibold">{{ plan().name }}</h2>
      <p class="mt-2 text-3xl font-bold text-blue-600">{{ plan().price }}</p>
      <button type="button"
              class="mt-4 w-full rounded-lg bg-blue-600 px-4 py-2 text-white hover:bg-blue-700
                     focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2"
              (click)="choose.emit(plan())">
        Choose plan
      </button>
    </article>
  `,
})
export class PriceCard {
  plan = input.required<{ name: string; price: string }>();
  choose = output<{ name: string; price: string }>();
}

Because Tailwind classes are global classes, they work in any component despite emulated encapsulation. Things to know:

  • Dynamic class names are not found. Tailwind scans text, so write complete names. class="text-{{ color }}-600" generates nothing; use a lookup instead: [class]="tones[tone()]" where the map holds the full class strings.
  • Binding classes works the usual way: [class.opacity-50]="disabled()" or [ngClass] (Property and Attribute Binding).
  • @apply inside a component stylesheet needs @reference "../../styles.css"; at the top of that file, because each component stylesheet is processed alone. Most teams avoid @apply and make a small component (such as PriceCard above) when a group of classes repeats. Reuse in Angular is a component, not a CSS class.
  • Long class lists are the price. Prettier plugins can sort them for consistency.

How the generator works, modeled

Understanding why "scan, then generate" keeps CSS small makes the dynamic-name rule obvious.

TypeScript Scan templates, generate only the CSS in use

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or readFileSync(0)), it gets the next line from this box.

Option 3: Bootstrap and ng-bootstrap

Bootstrap provides a grid, typography, buttons, cards and many components. There are two parts:

  1. Bootstrap's CSS gives the look. Add it as global styles:
Terminal
npm install bootstrap
JSON
"styles": ["node_modules/bootstrap/dist/css/bootstrap.min.css", "src/styles.css"]

If you use Sass, import only the parts you need and override variables before the import:

SCSS
// src/styles.scss
$primary: #2563eb;
$enable-rounded: true;
@import 'bootstrap/scss/bootstrap';

(Bootstrap's own Sass still uses @import; check its documentation for the current recommendation.)

  1. Bootstrap's JavaScript powers modals, dropdowns and tooltips, but it manipulates the DOM itself, which does not fit Angular's rendering. Do not load bootstrap.bundle.js and call it from components. Use ng-bootstrap (or ngx-bootstrap), libraries that implement the components in Angular:
Terminal
ng add @ng-bootstrap/ng-bootstrap
TypeScript
import { Component } from '@angular/core';
import { NgbAccordionModule, NgbModal } from '@ng-bootstrap/ng-bootstrap';

@Component({
  selector: 'app-faq',
  imports: [NgbAccordionModule],
  template: `
    <div ngbAccordion>
      <div ngbAccordionItem [collapsed]="false">
        <h2 ngbAccordionHeader><button ngbAccordionButton>What is a signal?</button></h2>
        <div ngbAccordionCollapse>
          <div ngbAccordionBody>A value that notifies the things that read it.</div>
        </div>
      </div>
    </div>
  `,
})
export class Faq {}

For layout and typography, the plain CSS classes (container, row, col-md-6, btn btn-primary) work in templates without any library. Only the interactive widgets need ng-bootstrap.

Choosing

Sass Tailwind Bootstrap + ng-bootstrap Angular Material
What it is A CSS language Utility classes Component kit with CSS Component library
You write Your own CSS Classes in templates Mostly framework classes Material components
Custom look Total Very high Medium (theming) Medium (theming)
Speed to first screen Slow Fast once learned Fastest Fast
Bundle impact None Only used classes Whole CSS unless trimmed Per component

They also combine: Sass for your tokens, Tailwind for layout, and Angular Material or the CDK for complex widgets. What you should avoid is mixing two full component kits (Bootstrap and Material) in one app: their global resets and class names clash, and users see two designs.

Practical advice

  • Design tokens first. Define colors, spacing and radii once, as CSS variables (--color-brand) or Sass variables. Whatever framework you use, the tokens keep the app consistent and make dark mode a variable switch.
  • Watch the bundle. Check the build output size (Build and Deploy). Full Bootstrap CSS is around 200 KB uncompressed; Tailwind output depends on what you use.
  • Mind accessibility. Frameworks give you styles, not correct semantics: use real button and a elements, labels and sufficient contrast (Security and Accessibility).
  • Use ViewEncapsulation.None sparingly. If you must style a child library's internals, prefer CSS variables the library exposes over ::ng-deep or turning encapsulation off.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Where do you add a vendor stylesheet so the whole app uses it?

    The build includes everything in the styles array as global CSS. Component styles are scoped to one component.
  2. 2. Why does class="text-{{ color }}-600" fail with Tailwind?

    The generator reads text and finds only complete names. Use a lookup map whose values are full class strings.
  3. 3. Why use ng-bootstrap instead of Bootstrap's own JavaScript in Angular?

    Bootstrap's CSS works as-is, but its interactive components should come from an Angular implementation.
  4. 4. Which setup do you generally avoid?

    Two full kits bring conflicting resets, class names and design languages.

Summary

  • Global styles are listed in angular.json; component styles stay scoped to the component.
  • Sass adds variables, mixins, loops and modules (@use); CSS variables handle values that change at run time.
  • Tailwind generates only the classes it finds in your source, via a PostCSS plugin and @import "tailwindcss"; write complete class names and make components, not @apply, for reuse.
  • Bootstrap's CSS can be used directly; use ng-bootstrap for modals, dropdowns and other interactive widgets.
  • Pick one component approach, define design tokens first and watch bundle size and accessibility.
  • Setup commands and configuration are real and read-only here; the runnable examples are stand-ins for the generators.

Next: Directives