Style Binding
You can set inline styles with a style binding.
Style binding syntax resembles property binding. Instead of an element property between brackets, start with the prefix style, followed by a dot (.) and the name of a CSS style property: [style.style-property].
Some style binding styles have a unit extension. The following example conditionally sets the font size in “em” and “%” units .
While this is a fine way to set a single style, the NgStyle directive is generally preferred when setting several inline styles at the same time.
Note that a style property name can be written in either dash-case, as shown above, or camelCase, such as fontSize.
Last updated
Was this helpful?