Inline CSS
The style attribute applies declarations to a single element and beats normal stylesheet rules, but cannot be reused or use selectors.
Compare a local declaration with a reusable rule and inspect how they compete.
You are testing a colour for the café's prices and want to see it right now, on one element, without opening another file. The style attribute does exactly that. It is also the quickest route to a stylesheet nobody can maintain.
The rule
Inline style: one element, one change, right there in the tag.
Inline CSS lives in an element's style attribute. Inside the quotes you write declarations, each a property, a colon, a value and a semicolon:
<p class="price" style="color: green; font-weight: bold;">₹180</p>What it gives you:
- It affects only that element (and whatever its children inherit, such as text colour).
- It beats any rule in a stylesheet that targets the element with a normal selector, whether that rule uses a class, an id or anything else.
What it costs you:
- No reuse. Twelve prices means twelve copies. Changing the green means twelve edits, and missing one leaves the menu inconsistent.
- No selectors. An inline style cannot say "when hovered" or "on narrow screens", because those need a selector or a media query, and a
styleattribute has neither. - Mixed layers. Looks leak back into the HTML, which is the very thing CSS exists to avoid.
Inline styles still have honest uses: a quick experiment, HTML emails (many email programs strip style elements and linked files), and values a script sets on the fly, such as the position of an element being dragged.