liveBook · Manning

:host selector

The CSS :host pseudo-class selects the host element associated with the current shadow-tree or component style scope.

How 2 Manning books explain it

Web Components in Action

The :host CSS pseudo-class selector matches the shadow host from within its shadow tree.

How it is used
Styles a custom element’s shadow host from its shadow-tree CSS, including layout and class-dependent appearances.
How deep it goes
Works through basic and class-qualified rules, inherited-style nuance, and a non-Shadow-DOM selector fallback.
Examples
Uses a stepper’s flex layout, exercise-card classes, library and plan views, and a slider template.
What you can do after
Operate/configure it in Shadow DOM CSS to style hosts and switch host styles using classes.

Read how Web Components in Action explains :host selector →

Pro Angular 16

The :host selector is a CSS selector that targets the host element of an Angular component.

How it is used
Targets an Angular component host so component styles can react to host attributes under view encapsulation.
How deep it goes
Explains the selector through one disabled-button rule and stops short of broader selector mechanics.
Examples
Uses a customButton component whose host and internal button receive disabled-state theme colors.
What you can do after
Apply the selector to style component internals when an attribute such as disabled is placed on the host element.

Read how Pro Angular 16 explains :host selector →

Related concepts

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.