Scripting & Styles

HTML <style> Tag

The <style> tag is used to define style information (CSS) for a document.

Definition and Usage

The <style> tag is used to define style information (CSS) for a document.

Standard Syntax:<style>...</style>

Interactive ExampleRunnable

HTML <style> Example

html
Try it Yourself
Live code demonstration for the <style> tag. Click "Try it Yourself" to edit and experiment in real time.
<html>

 <head>

 <style>

  
 h1 {color:red;}

  
 p {color:blue;}

 </style>

 </head>

 <body>


 <h1>A heading</h1>

 <p>A paragraph.</p>


 </body>

 </html>

Attributes for <style>

2 Supported Attributes
AttributeValuesDefaultDescription
mediamedia_querynoneSpecifies what media/device the media resource is optimized for
typetext/cssnoneSpecifies the media type of the <style> tag
Global Attributes

The <style> tag also supports the standard global attributes in HTML, including class, id, style, title, hidden, and data-*.

HTML Global Attributes Reference →
Event Attributes

The <style> tag supports event attributes in HTML, such as onclick, onmouseover, onfocus, and more.

HTML Event Attributes Reference →

Browser Compatibility

ChromeEdgeFirefoxSafariOpera

More Tags in Scripting & Styles

View All 123Tags →