Style tag in HTML5


The HTML <style> tag is used for declaring style sheets within your HTML document. The <style> tag is supported in all major browsers. The required type attribute defines the content of the style element. The only possible value is "text/CSS". The style element always goes inside the head section.
let's look at an example. If you want the color of some text to look red, the style attribute would look like this:
  1. style="color:red"  
The style sheet property is "color". The value of the color is "red". Notice there is a colon in between color and red, not an equal sign and there are no extra quote marks.
Insert style into an HTML tag, such as the <DIV> tag. Place a semicolon after your first property and value, and add another. So if we want the text to be read and to be italic, we would do the following:
<DIV style="color:red; font-style:italic">This style for some red-hot italic text!</DIV>


HTML tags can contain one or more attributes. Attributes are added to a tag to provide the browser with more information about how the tag should appear or behave.
There are 3 kinds of attributes that you can add to your HTML tags: Element-specific, global, and event handler content attributes. The attributes that you can add to this tag are listed below.

Element-Specific Attributes

The following table shows the attributes that are specific to this tag/element.
Attributes Introduced by HTML5
Attributes Description             
Type type is used to specify the content type which is generally text/CSS.
Media media can be used to specify which media the styles are associated to. A value such as screen, print, projection, braille, speech or all can be used or a combination in a comma-separated list.
Scoped if the <style> tag is being used outside of the document <head>, it must have the scoped attribute.

Global Attributes

The following attributes are standard across all HTML 5 tags.
HTML5 Global Attributes
accesskey draggable style
class hidden tabindex
dir spellcheck  
contenteditable id title
contextmenu lang  

Event Handler Content Attributes

Here are the standard HTML 5 event handler content attributes.
onabort onerror* onmousewheel
onblur* onfocus* onpause
oncanplay onformchange onplay
oncanplaythrough onforminput onplaying
onchange oninput onprogress
onclick oninvalid onratechange
oncontextmenu onkeydown onreadystatechange
ondblclick onkeypress onscroll
ondrag onkeyup onseeked
ondragend onload* onseeking
ondragenter onloadeddata onselect
ondragleave onloadedmetadata onshow
ondragover onloadstart onstalled
ondragstart onmousedown onsubmit
ondrop onmousemove onsuspend
ondurationchange onmouseout ontimeupdate
onemptied onmouseover onvolumechange
onended onmouseup onwaiting
For Example
  1. <html>  
  2.     <head>  
  3.         <style type="text/css">   
  4. h1 {color:red;}  
  5. p {color:blue;}  
  6. </style>  
  7.     </head>  
  8.     <body>  
  9.         <h1>Style tag in HTML5</h1>  
  10.         <p>A paragraph.  
  11.             <br />The HTML style tag is used for declaring style sheets within your HTML document. The   
  12.             <style> tag is supported in all major browsers. The required type attribute defines the content of the style element.   
  13.             </p>  
  14.         </body>  
  15.     </html>  
Internet Explorer]

Type attribute

The type attribute identifies the content between the <style> and </style> tags. The value "text/CSS" indicates that the content is standard CSS.
  1. <style type="text/css">  
  2. h1 {color:red}  
  3. p {color:blue}  
  4. </style>undefined</head>undefined<body>  
  5. <h1>Header 1</h1>  
  6. <p>A paragraph.</p>undefined</body>  

Media Attribute

The media attribute is used to specify different styles for different media types. To define more than one media type per style element, use a comma-separated list.
  1. <style type="text/css" media="screen,projection">  
For Example
  1. <html>  
  2.     <head>  
  3.         <style type="text/css">  
  4. h1 {color:#FF0000;}  
  5. p {color:#0000FF;}  
  6. body {background-color:#FFEFD6;}  
  7. </style>  
  8.         <style type="text/css" media="print">  
  9. h1 {color:#000000;}  
  10. p {color:#000000;}  
  11. body {background-color:#FFFFFF;}  
  12. </style>  
  13.     </head>  
  14.     <body>  
  15.         <h1>Example of media attribete</h1>  
  16.         <p>A paragraph.</p>  
  17.     </body>  
  18. </html> 
Internet explorer