The styleglobal attribute holds CSS declarations applied to that one element — for example color: navy; or padding: 1rem;. This is often called inline CSS.
MDN recommends putting real site styles in a separate CSS file (or a <style> block). Use the attribute mainly for quick tests, tiny one-offs, or styles set from script. Prefer class for reusable look-and-feel. See also how to add CSS to HTML.
Baseline · Widely available.
Not deprecated and not experimental. A standard global attribute on every HTML element since early browsers (Baseline since about July 2015).
Not for meaning or hiding.
Per MDN: do not use style to convey semantics. Do not hide irrelevant content with display:none in style — use hidden instead. The page should stay correct if all styling is removed.
Syntax
HTML Syntax
syntax.html
<element style="declarations">
declarations are CSS property/value pairs separated by semicolons (same idea as inside a CSS rule). Equivalent JS: el.style.color = "navy".
Values
Attribute Values
The value is a CSS declaration list. Common patterns:
Both look alike here; class scales better across many elements.
How It Works
Inline style ties CSS to one element in the markup.
class + CSS rule can style many elements with one change.
Maintainability — editing a stylesheet is easier than hunting attributes.
Use both wisely — inline for rare exceptions; classes for the design system.
Edge Cases & Pitfalls
Most problems come from overusing inline CSS or using it to hide or imply meaning.
semantics
Not semantic
Color or bold in style does not mark importance. Use proper HTML (<strong>, headings) for meaning.
hide
Prefer hidden to hide
MDN: do not use style alone to mark content as irrelevant. Use hidden.
!important
Hard to override
Inline styles beat most stylesheet rules unless you use !important (messy). Prefer classes when you need easy overrides.
csp
Content Security Policy
Some sites block inline styles via CSP (style-src). External CSS + classes are safer in locked-down apps.
quotes
Quotes in values
If a CSS value needs quotes (fonts, URLs), use the other quote style inside the attribute, or escape carefully.
Compatibility
Browser Support
style is an HTML global attribute for inline CSS in the browser. It is not a Node.js, Deno, or Bun API.
✓ Widely available
style
Supported in all modern browsers on every HTML element. Prefer stylesheets for maintainable design.
98%Global support (approx.)
Google ChromeAll modern
Full support
Mozilla FirefoxAll modern
Full support
Apple SafariAll modern
Full support
Microsoft EdgeAll modern
Full support
OperaAll modern
Full support
Samsung InternetModern
Full support
Internet ExplorerAll
Supported
styleWidely supported
Bottom line: Safe to use for quick tests and one-offs. For site-wide design, use CSS files and class names.
Remember
Key Takeaways
Role: CSS declarations on one element (inline CSS).
Prefer stylesheets + class for real sites (MDN).
Not for semantics or for hiding content — use proper HTML / hidden.
Global: allowed on any HTML element.
One line:style is inline CSS for one element — great for demos; use CSS files and class for design.
Frequently Asked Questions
It is a global attribute that holds CSS declarations applied to that one element, for example color: red; or margin: 1rem;. This is often called inline CSS.
No. MDN recommends defining styles in separate CSS files (or a style element) for real sites. The style attribute is mainly for quick tests, tiny one-off tweaks, or dynamically set styles.
class names reusable rules in a stylesheet. style puts CSS on a single element and is harder to reuse or override cleanly. Prefer class for shared look-and-feel.
The style attribute styles one element. The style element in the document head (or a linked stylesheet) can style many elements with selectors.
Technically yes, but MDN says do not use style to convey that content is irrelevant. Prefer the hidden attribute for content that should not be presented.
No. It is a standard global attribute and Baseline widely available. The caution is about overuse and misusing it for meaning, not deprecation.