HTML style attribute
- closing tag
- n/a — attribute
- void element
- n/a
- lives inside
- any tag
- typically holds
- CSS declarations, separated by semicolons
Where it goes
On a single tag, in its opening brackets, as a last resort. A quick experiment, a value that comes from data (a chart bar's width), or an email where stylesheets get removed. Everything else belongs in a <style> block or a .css file.
Example
<p style="color: crimson; font-weight: bold;">Sold out</p>
<!-- same thing, the reusable way -->
<p class="warning">Sold out</p>Open this example in the editor →
Common mistakes
- Writing it like an HTML attribute, style="color=red". Inside the quotes it is CSS: property, colon, value, semicolon.
- Using it to fix one tag, then wondering why the rule in your .css file stops working. An inline style beats class and id rules. Only !important beats it.
- Trying to put :hover or @media inside it. They cannot live on a tag. The moment you need them, move the rule to a stylesheet.