View Encapsulation Modes
Compare Emulated, None, and ShadowDom.
View Encapsulation Modes is a free Angular Academy lesson on CoddyKit. This is lesson 2 of 4. Any 3 lessons of this learning path are free to read in full — after that, CoddyKit PRO unlocks every lesson, plus hands-on practice with a built-in code editor and a 24/7 AI tutor. It is part of the Angular Academy learning path, and your progress syncs across the web and the CoddyKit app. The Angular Academy course includes 4 lessons in total.
What Is View Encapsulation?
View encapsulation controls how a component styles are isolated from the rest of the page. Angular offers three modes via the encapsulation property.
Setting the Mode
Set the mode with the ViewEncapsulation enum in the @Component decorator.
import { Component, ViewEncapsulation } from "@angular/core";
@Component({
selector: "app-card",
encapsulation: ViewEncapsulation.Emulated
})
export class CardComponent {}Emulated (Default)
Emulated is the default. Angular simulates scoped styles by adding unique attributes to elements and selectors, without using native Shadow DOM.
@Component({
encapsulation: ViewEncapsulation.Emulated
})How Emulated Works
Emulated mode rewrites selectors with generated attributes, giving scoping that works in all browsers without Shadow DOM support requirements.
/* you write */
.title { color: blue; }
/* angular emits */
.title[_ngcontent-xyz] { color: blue; }None
None disables encapsulation entirely. The component styles become global and can affect any element on the page.
@Component({
encapsulation: ViewEncapsulation.None,
styles: [".title { color: red; }"]
})
// .title now applies app-wideWhen to Use None
Use None sparingly, for example to define shared theme rules from one component. Beware that styles can clash globally.
ShadowDom
ShadowDom uses the browser native Shadow DOM to truly isolate the component markup and styles.
@Component({
selector: "app-widget",
encapsulation: ViewEncapsulation.ShadowDom
})
export class WidgetComponent {}How ShadowDom Differs
With ShadowDom, the component renders inside a real shadow root. Global styles do not pierce in, and component styles do not leak out, giving the strongest isolation.
Style Leakage Compared
Emulated prevents leakage out but global styles can still target elements; None has no isolation; ShadowDom fully blocks both directions.
Choosing a Mode
Stick with Emulated for almost everything. Use ShadowDom for fully isolated widgets and None only for intentional global styles.
Encapsulation and Global Styles
Remember the global styles.css always applies regardless of mode, except inside a ShadowDom component, where global styles do not reach.
Quick Check
Test your understanding of view encapsulation modes.
Recap
Angular offers three encapsulation modes: Emulated (default, simulated scoping), None (global styles), and ShadowDom (native isolation). Emulated suits most cases; ShadowDom gives the strongest isolation.
Learn HTML with an AI tutor — free
Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.
- Courses
- 38
- Lessons
- 144
Frequently Asked Questions
Is the “View Encapsulation Modes” lesson free?
Yes — any 3 lessons of the Angular Academy learning path, including “View Encapsulation Modes”, are free to read in full here on the web. After that, CoddyKit PRO unlocks every lesson, plus interactive practice with a built-in code editor and a 24/7 AI tutor. The Angular Academy course includes 4 lessons in total.
What will I learn in “View Encapsulation Modes”?
Compare Emulated, None, and ShadowDom. You practise Angular Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Angular Academy?
No prior experience is required. Angular Academy on CoddyKit is structured for beginners through advanced learners, so you can start here or from the beginning and move at your own pace. This is lesson 2 of 4.
How long does the “View Encapsulation Modes” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Angular Academy lesson?
Yes. Every Angular Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Component-Scoped Styles
- View Encapsulation Modes
- Host and Host-Context Styling
- Dynamic Classes and Styles