Inline Style
Definition
The style attribute takes a list of declarations, without a selector and without braces: <p style="font-size: 14px; line-height: 1.5">. Because there is no selector, there is nothing to match — the declarations belong to that single element and nowhere else. Inline styles sit above every normal rule in a stylesheet no matter how specific that rule is, and the only normal way to override one is a declaration marked !important. They cannot express a hover state, a media query or a pseudo-element, since all three need a selector. Scripts write them constantly through the style property, which is why an element can end up with inline styles that appear nowhere in the source.
Why It Matters
Inline styles are the reason a perfectly good rule in your stylesheet does nothing. If a heading refuses to change colour and the styles panel shows the rule struck through, look at the element itself: a style attribute beats a class every time. They are also expensive to maintain — the same declaration repeated across forty elements is forty edits, and they are re-sent with the HTML on every request rather than cached as part of a stylesheet. There is one place they earn their keep: a small block of critical CSS or a value only known at runtime, such as a progress bar width being set by script.
How It Works
The parser reads the style attribute and attaches its declarations to that element as its own style block, handled by the cascade at a level above all selector-based rules. Machine-generated pages lean on this heavily — an exported document or an AI-written page often carries a style attribute on every paragraph, which is legal but leaves nothing to target from a stylesheet. When a script runs element.style.display = "none", it writes an inline style, and that is why the element stays hidden even after you fix the CSS class. The way out is usually to remove the attribute rather than fight it: delete the style attribute and let a class take over, or in a script set the property back to an empty string to hand control back to the stylesheet.
Real-World Example
An exported report goes up at field-notes-2026.99helpers.site with every paragraph carrying style="font-family: Arial; font-size: 11pt". A single rule setting a nicer typeface on body has no visible effect, because six hundred inline declarations outrank it. A find and replace stripping the style attributes, plus one rule in the stylesheet, drops the file from 310 KB to 120 KB and makes future typography changes a one-line job.
Common Mistakes
- ✕Writing a selector or braces inside the attribute — style="p { color: red }" is invalid, because the attribute takes declarations only
- ✕Trying to put a hover or a media query inline — neither works without a selector, so those belong in a stylesheet
- ✕Adding !important to a stylesheet rule to beat an inline style — it works, but the real fix is usually to remove the style attribute that should not have been there
Related Terms
CSS Specificity
Specificity is how the browser decides which rule wins when two of them set the same property on the same element. Each selector scores a weight, the higher weight wins, and only an exact tie is settled by which rule comes later in the stylesheet.
Stylesheet
A stylesheet is the set of CSS rules that tells the browser how a page should look. It is usually a separate .css file linked from the head, though it can also sit in a style element inside the HTML itself.
HTML Attribute
An HTML attribute is a name and value written inside a start tag that configures the element — where an image lives, which stylesheet rule applies, what a link points at. Attributes change behaviour and appearance without changing what the element is.
Inline CSS
CSS written inside the HTML document rather than in a separate .css file — either in a style element in the head or in a style attribute on a single element. It removes a network request and keeps everything in one file.
Generated HTML
Generated HTML is markup produced by a program or a model rather than typed by a person. From a browser's point of view it is indistinguishable from hand-written HTML, and a static host serves it the same way.
Put a file online in seconds
Drop in a document, an image, a page or a whole static website and share the link — free, with no build step and no server to set up.
Host a file free →