By using this site you agree to the use of cookies by Brugbart and our partners.

Learn more

The HTML Style Attribute

Reference on how to use the style attribute, and some useful styling tips.

Edited: 2013-07-18 14:04

The HTML style attribute is used to apply CSS styling rules directly on element, also known as inline styling. Its generally recommended to apply styles in external files, since it will allow browsers to make use of caching, speeding up the page load, and lowering the bandwidth usage for both the visitor and the host.

The style element can be used on all styleable elements. I.e.

<p style="color:black;margin: 1em 0 2em;">Test paragraph</p>

If you are using multiple CSS properties, you should separate each property with a semicolon ";".

The style attribute will override styling globally. I.e. Styles set in external StyleSheets, and from style elements in the page.

When to use the Style Attribute

The HTML style attribute can be used when you don't have access to the CSS files, and still want to change the appearance of the elements on a page – It should however be said, that taking the time to use external StyleSheets, usually will be the better option.

It can also be useful to quickly test something directly on your site, especially if you don't have access to the CSS files, or just don't want to open up your editor.

See also

  1. List of HTML Attributes