liveBook · Manning

Style attribute

As explained in Web Design Playground

An HTML attribute that lets CSS declarations be written directly on an individual element.

The style attribute is a small CSS workspace tucked directly inside an HTML tag. It creates an inline style: declarations written there affect that one element, rather than every similar element on the page. section 7.2 section 7.12

<h1 style="font-size: 36px; text-align: center">

Place style after the element name, then put CSS property-value pairs inside its quotation marks. section 1.21

Build an inline style in small pieces:

  • Start with the HTML element you want to change. section 7.2
  • Add style="..." to that element. section 1.21
  • Write a property, a colon, and its value, such as font-size: 36px. section 1.21
  • Separate multiple property-value pairs with semicolons. Use single quotes inside the value when it needs quotation marks. section 7.2

A heading with its own instructions

<h1 style="font-size: 36px; text-align: center">How New Words Are Created</h1> Here, font-size changes the heading’s size and text-align centers its text. Those instructions belong only to this h1. section 1.21

Inline styles are handy for a quick CSS test or for a specific one-off element. They become tiresome when many elements need the same look: each tag needs its own copy, and later changes must be repeated. Internal or external style sheets, often with class selectors, are better suited to shared styling. section 7.2 section 7.3 section 7.8

Inline styles also carry strong weight in the CSS cascade. When an internal style sheet says a div is red but that div’s style attribute says blue, the inline declaration wins. section 19.26

How Web Design Playground covers it

How deep it goes
Defines syntax, multiple declarations, quoting, scope, maintenance tradeoffs, and cascade weight without detailing every CSS property.
Examples
Uses styled headings, a paragraph, a list, and a conflicting div rule to demonstrate inline declarations.
What it assumes
Assumes HTML elements and CSS property-value pairs while introducing direct declaration placement from scratch.
What you can do after
Apply it via HTML and CSS to test properties or make a one-element styling exception.
How it connects
Connects inline styles with CSS declarations, internal and 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. The section links point to the parts of the book it draws on.