:host selector
The CSS :host pseudo-class selects the host element associated with the current shadow-tree or component style scope.
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.
Web Component Development with Modern Libraries and Tooling
A CSS pseudo-class that selects a shadow host from within that host's shadow-tree styles.
- How it is used
- Controls a custom element’s layout and host-level styling from inside a shadow-DOM component.
- How deep it goes
- Explains host targeting, display behavior, shadow-DOM boundaries, and the hidden-attribute override, without detailing selector internals.
- Examples
- Shows inline-block sizing, flex and block display rules, hidden-state styling, and a Stencil hello-world component.
- What you can do after
- Apply it via CSS to set a component’s host layout and preserve hidden-element behavior.
Read how Web Component Development with Modern Libraries and Tooling 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.
Also covered in
- Vanilla WebIn early access (MEAP)
What to know first
- CSSCSS (Cascading Style Sheets) is a stylesheet language for specifying the presentation and layout of structured documents.
- display propertyThe CSS property that specifies how an element generates boxes and participates in layout.
- CSS selectorA CSS selector is a pattern that matches elements in a document according to their names, attributes, relationships, states, or other conditions.
Related concepts
- hiddencontrasts with · A hidden element is one that is not displayed or visually rendered to the user, though it may remain in the document and affect layout.
- :host-context() selectoralternative to · The :host-context() selector is a Shadow DOM CSS selector that matches a shadow host when an ancestor satisfies a specified selector.
- CSS selectorkind of · A CSS selector is a pattern that matches elements in a document according to their names, attributes, relationships, states, or other conditions.
- Shadow DOMused by · Shadow DOM is a web platform mechanism for attaching a DOM subtree to an element while encapsulating its structure and styles from the surrounding document.
- view encapsulationused by · View encapsulation is Angular's mechanism for scoping component styles and, when applicable, rewriting their selectors to isolate them from other components.
- Web Componentsuses · Web Components are browser standards and APIs, including custom elements and shadow DOM, for creating reusable web interface elements with encapsulated structure, presentation, and behavior.
Questions about :host selector
What is :host selector?
The CSS :host pseudo-class selects the host element associated with the current shadow-tree or component style scope.
Which Manning books explain :host selector?
Web Components in Action, Web Component Development with Modern Libraries and Tooling and Pro Angular 16.
What should I know before learning :host selector?
Manning books that teach :host selector usually introduce CSS, disabled attribute, display property and CSS selector first.
What is the difference between :host selector and hidden?
The CSS :host pseudo-class selects the host element associated with the current shadow-tree or component style scope. A hidden element is one that is not displayed or visually rendered to the user, though it may remain in the document and affect layout.
What is :host selector a kind of?
:host selector is a kind of CSS selector. A CSS selector is a pattern that matches elements in a document according to their names, attributes, relationships, states, or other conditions.
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.


