liveBook · Manning

Style attribute

As explained in Web Design Playground, Second Edition

The HTML style attribute contains CSS declarations applied directly to an element.

The style attribute places CSS declarations directly inside the HTML element you want to change. It is the quickest way to test a property, but its effect stays limited to that one element. section 7.2 section 2.3

Build the value from property–value pairs:

  • Wrap the declarations in quotation marks: <element style="property: value;">. section 7.2
  • Separate multiple declarations with semicolons, and add a space after each colon to keep the code readable. section 7.1 section 7.2
  • Use single quotation marks inside the attribute when a CSS value itself needs quotation marks. section 7.2

A paragraph and a list with inline styles

<p style="font-size: 1.5em">A larger paragraph</p> <ul style="color: darkgreen; font-size: 1.25em;"> <li>One item</li> <li>Another item</li> </ul> The paragraph and list receive different styles because each style attribute affects only its own element. section 7.2

Inline styles become awkward when many elements need the same design: every element needs its own attribute, and later changes must be repeated. Class selectors, internal style sheets, and external style sheets scale better. In the cascade, inline styles outrank internal and external author style sheets when rules conflict. section 7.2 section 19.13 section 7.7

How Web Design Playground, Second Edition covers it

How deep it goes
Explains syntax, multiple declarations, quotation marks, scope, maintenance limits, and cascade precedence without deeper CSS internals.
Examples
Demonstrates styled paragraph and list elements, nested quotation marks, and a blue inline rule overriding a red internal rule.
What it assumes
Assumes basic HTML elements and CSS property-value pairs while introducing inline styling from its simplest syntax.
What you can do after
Apply CSS declarations to individual HTML elements and recognize when broader style mechanisms are more convenient.
How it connects
Connects the style attribute with CSS declarations, internal style sheets, external style sheets, class selectors, inheritance, and the cascade.

Also explained in

Compare how 7 books explain style attribute →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Web Design Playground, Second Edition. The section links point to the parts of the book it draws on.