W3Schools.com

HTML5 <style> Tag

Example

Use of the style element in an HTML document:

<html>
<head>
<style type="text/css">
h1 {color:red}
p {color:blue}
</style>
</head>

<body>
<h1>Heading</h1>
<p>A paragraph.</p>
</body>
</html>

Try it yourself »

Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The <style> tag is supported in all major browsers.


Definition and Usage

The <style> tag is used to define style information for an HTML document.

Inside the <style> element you specify how HTML elements should render in a browser.

Each HTML document can contain multiple <style> tags.


Differences Between HTML 4.01 and HTML5

The "scoped" attribute is new in HTML5, which allows to define styles for a specified section of the document. If the "scoped" attribute is present, the styles only apply to the style element's parent element and that element's child elements.


Tips and Notes

Tip: To link to an external style sheet, use the <link> tag.

Tip: To learn more about style sheets, visit our CSS Tutorial.

Note: If the "scoped" attribute is not used, each <style> tag must be located in the head section.


Attributes

New : New in HTML5.

Attribute Value Description
type text/css Specifies the MIME type of the style sheet
media media_query Specifies what media/device the media resource is optimized for. Default value: all.
scopedNew scoped Specifies that the styles only apply to this element's parent element and that element's child elements

Global Attributes

The <style> tag also supports the Global Attributes in HTML5.


Event Attributes

The <style> tag also supports the Event Attributes in HTML5.


WEB HOSTING
Best Web Hosting
PHP MySQL Hosting
Best Hosting Coupons
UK Reseller Hosting
Cloud Hosting
Top Web Hosting
$3.98 Unlimited Hosting
Premium Website Design
WEB BUILDING
Download XML Editor
FREE Website BUILDER
Best Website Templates Top CSS Templates
CREATE HTML Websites
EASY WEBSITE BUILDER
W3SCHOOLS EXAMS
Get Certified in:
HTML, CSS, JavaScript, XML, PHP, and ASP
W3SCHOOLS BOOKS
New Books:
HTML, CSS
JavaScript, and Ajax
STATISTICS
Browser Statistics
Browser OS
Browser Display
SHARE THIS PAGE