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:
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 red 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>
Attributes
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
<html>
<head>
<style
type="text/css">
h1
{color:red;}
p
{color:blue;}
</style>
</head>
<body>
<h1>Style
tag in HTML5</h1>
<p>A
paragraph.<br
/>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. </p>
</body>
</html>
Internet Explorer]
Fire Fox
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.
<style
type="text/css">
h1
{color:red}
p
{color:blue}
</style>
</head>
<body>
<h1>Header
1</h1>
<p>A
paragraph.</p>
</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.
<style type="text/css" media="screen,projection">
For Example
<html>
<head>
<style
type="text/css">
h1
{color:#FF0000;}
p
{color:#0000FF;}
body
{background-color:#FFEFD6;}
</style>
<style
type="text/css"
media="print">
h1
{color:#000000;}
p
{color:#000000;}
body
{background-color:#FFFFFF;}
</style>
</head>
<body>
<h1>Example
of media attribete</h1>
<p>A
paragraph.</p>
</body>
</html>
Internet explorer