CoreUI ONE — 250+ PRO components and 25+ admin templates for React, Angular, Vue, Bootstrap and Next.js, plus Data Grid, Scheduler, 4,300+ PRO icons and the Next.js boilerplate. One license. → See what you get

How to use ViewEncapsulation in Angular

Managing CSS scope in Angular components is critical for preventing style conflicts and maintaining clean component boundaries. As the creator of CoreUI, I’ve used ViewEncapsulation extensively in enterprise applications. Angular provides three ViewEncapsulation modes: Emulated (default), None, and ShadowDom, each controlling how styles are scoped to components. The ViewEncapsulation strategy determines whether component styles affect only that component or leak to the global scope.

Set ViewEncapsulation in the component decorator to control CSS scoping behavior.

import { Component, ViewEncapsulation } from '@angular/core'

@Component({
  selector: 'app-card',
  template: `
    <div class='card'>
      <h2>Card Title</h2>
      <p>Card content</p>
    </div>
  `,
  styles: [`
    .card {
      border: 2px solid blue;
      padding: 20px;
    }
  `],
  encapsulation: ViewEncapsulation.Emulated
})
export class CardComponent {}

Best Practice Note

ViewEncapsulation.Emulated is the default and recommended mode—it adds unique attributes to elements and scopes styles to the component without using Shadow DOM. ViewEncapsulation.None makes component styles global, useful for overriding third-party library styles. ViewEncapsulation.ShadowDom uses native Shadow DOM for true encapsulation but has limited browser support and CSS framework compatibility. This is the same pattern we use in CoreUI for Angular components to ensure styles remain isolated while allowing theme customization through CSS variables.


Speed up your responsive apps and websites with fully-featured, ready-to-use open-source admin panel templates—free to use and built for efficiency.


About the Author

Subscribe to our newsletter
Get early information about new products, product updates and blog posts.
How to Detect a Click Outside of a React Component
How to Detect a Click Outside of a React Component

CSS Selector for Parent Element
CSS Selector for Parent Element

How to Convert a Map to an Array in JavaScript
How to Convert a Map to an Array in JavaScript

How to Center a Button in CSS
How to Center a Button in CSS