The :host selector targets the custom element that contains a shadow DOM. Define it inside the component’s styles to control the host’s layout without styling its internal elements directly. section 3.8 section 4.2.5
Choose the component’s layout
A custom element is inline by default, so it behaves like a span. Set a more useful layout explicitly: :host { display: inline-block; width: 10rem; height: 5rem; } Use display: block or display: flex when the component should occupy its own line or arrange its contents with flex layout. section 3.8 section 4.2.5
Use :host rules to establish predictable component behavior:
- Set display, padding, border, margin, width, or height on the custom element. section 4.2.5
- Preserve the hidden attribute when overriding the default display value: :host([hidden]) { display: none; } section 4.2.6
- Prefer a :host rule for shadow-DOM components because outside classes and styles do not directly style their rendered internal elements. section 3.8 section 6.3
Table 3.1 CSS display property values
display value |
Effect |
|
This allows an element to render within the flow of surrounding content. The width and height of the element can’t be set. |
|
This causes an element to render on its own line. Content before and after the element appears on separate lines. The width and height of the element can be set. |
|
This is a hybrid of |
Compare inline, block, and inline-block behavior before choosing the host’s display value. section 3.8


