liveBook · Manning

Style attribute

As explained in WordPress Power Toolkit: Harness AI to build next-level websites

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

The HTML style attribute adds CSS declarations directly to one element. This is also called inline CSS. Use it when a small, local area needs a one-off visual change—for example, a word, sentence, heading, image, or paragraph—without changing the rest of a site. section 7.2.5

Make one sentence red

Place the style attribute inside an HTML tag, then give it a CSS declaration. Here, only this span is red; surrounding content keeps its existing styling. section 7.2.5

<span style="color: red;">This sentence is red</span> 

The attribute contains color: red;, while the span tags define the exact local zone that receives the change. section 7.2.5

Inline CSS sits at the local end of the cascade and can overrule browser defaults, a theme style sheet, and site administrator CSS. It can style a single character or a larger container. For related content, put the style attribute on a div so its contents share the styling. section 7.2.5 section 7.5

Use the style attribute for focused adjustments, but keep these limits in mind:

  • Use it sparingly. Repeating inline CSS can make styling harder to read and maintain. section 7.5
  • Choose a CSS class when the same look belongs on many elements. Define the rule once, then apply the class name where needed. section 7.6
  • In WordPress, add site-wide rules through Appearance > Customize > Additional CSS rather than repeating declarations element by element. section 7.2.5 section 7.6

A class keeps content and styling more separate. With a style attribute, every property must be typed again on each element. With a class attribute, one named rule can be reused and later changed in one place, updating every element that uses it. section 7.6

Add inline CSS in Gutenberg

Open Pages > All Pages, select a page, add a Classic block, select it, then choose View > Source Code. Add a style attribute to a paragraph tag and confirm the change. Using code view on a Paragraph block may trigger an invalid-content message and block recovery can delete the block. section 7.7 section 7.7

How WordPress Power Toolkit: Harness AI to build next-level websites covers it

How deep it goes
Explains attribute placement, cascade priority, scope, and Gutenberg entry steps; defers the full complexity of the modern CSS cascade.
Examples
Uses red span and paragraph text, a purple div container, repeated green headings, and a Gutenberg Classic-block editing workflow.
What it assumes
Teaches local CSS through concrete HTML tags and editor actions without assuming prior programming or WordPress expertise.
What you can do after
Apply it via WordPress editing tools to style a specific HTML element, while choosing classes for repeated styling.
How it connects
Connects inline CSS with the CSS cascade, CSS scope, div and span elements, CSS classes, and Additional CSS.

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 WordPress Power Toolkit: Harness AI to build next-level websites. The section links point to the parts of the book it draws on.