The style attribute

style lets you set CSS rules directly on an element, without a separate stylesheet.

Applies to

global

Values

A string of CSS declarations, e.g. style="color: red; margin: 0;".

Example

<p style="color: red; font-weight: bold;">Important text</p>

Edge cases

  • Inline style has the highest specificity in normal CSS (short of !important in external styles), which makes it harder to override.
  • For repeated styling, a CSS class is easier to maintain than an inline style.

Security

  • A CSP with style-src and no unsafe-inline blocks inline style attributes — keep that in mind when choosing a CSP policy.

Related tools