You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
**Always prefer using the `host` property over `@HostBinding` and `@HostListener`.** These
103
+
<docs-calloutcriticaltitle="Prefer using the `host` property over the decorators">
104
+
**Always prefer using the `host` property over `@HostBinding` and `@HostListener`.** These
102
105
decorators exist exclusively for backwards compatibility.
106
+
</docs-callout>
103
107
104
108
## Binding collisions
105
109
@@ -126,3 +130,36 @@ In cases like this, the following rules determine which value wins:
126
130
- If both values are static, the instance binding wins.
127
131
- If one value is static and the other dynamic, the dynamic value wins.
128
132
- If both values are dynamic, the component's host binding wins.
133
+
134
+
## Styling with CSS custom properties
135
+
136
+
Developers often rely on [CSS Custom Properties](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_cascading_variables/Using_CSS_custom_properties) to enable a flexible configuration of their component's styles.
137
+
You can set such custom properties on a host element with a [style binding][style binding](guide/templates/binding#css-style-properties).
138
+
139
+
```angular-ts
140
+
@Component({
141
+
/* ... */
142
+
host: {
143
+
'[style.--my-background]': 'color()',
144
+
}
145
+
})
146
+
export class MyComponent {
147
+
color = signal('lightgreen');
148
+
}
149
+
```
150
+
151
+
In this example, the `--my-background` CSS custom property is bound to the `color` signal. The value of the custom property will automatically update whenever the `color` signal changes. This will affect the current component and all its children that rely on this custom property.
152
+
153
+
### Setting custom properties on children compoents
154
+
155
+
Alternatively, it is also possible to set css custom properties on the host element of children components with a [style binding](guide/templates/binding#css-style-properties).
0 commit comments