HTML - Style (Element|Embedded Style) - Attribute


Style in HTML is:

that permit to declare a style.



The style element 1) allows style information to be embedded in documents.

.green {
     color: green; 
.blue {
     color: blue; 
<p>My sweat suit is <span class="green">green</span> 
and my eyes are <span class="blue">blue</span>.</p>

Style Location

An style element should be inside metadata element and is usually part of the head.

Style in Body


The style content attribute is a global CSS styling attribute.

Example: the words that refer to colors are marked up using the span element and the style attribute.

  • Html example:
<p>My sweat suit is <span style="color: green; background:transparent">green</span> 
and my eyes are <span style="color: blue;background: transparent">blue</span></p>
<p>My sweat style was <span>this color</span>
  • Javascript
let firstSpan = document.getElementsByTagName("span")[0];
console.log("The color of the first span is ";

// Inline color copy
let thirdSpan = document.getElementsByTagName("span")[2]; =;

Using the style attribute to hide and show content, or to convey meaning that is otherwise not included in the document, is non-conforming. (To hide and show content, use the hidden attribute.)

Documentation / Reference

Powered by ComboStrap