English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

HTML Reference Manual

HTML Tag Directory

HTML: <style> tag

The HTML <style> tag is used to embed CSS into the HTML document. It can be placed inside the <body> tag or the <head> tag. By default, the style information of the <style> tag is usually in CSS format. This tag is also commonly referred to as the <style> element.

Online Example

Using the <style> element in an HTML document:

!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>HTML style tag usage (Basic Tutorial Website oldtoolbag.com)</title>
</head>
<style>
   h1 { color: blue; }
   .p-style{color:red;font-weight:bold;}
</style>
</head>
<body>
   <h1>HTML5 Example</h1>
   <p class="p-style">This is a paragraph with style</p>
</body
</html>
Test and see ‹/›

Browser Compatibility

IEFirefoxOperaChromeSafari

All mainstream browsers support the <style> tag.

Tag Definition and Usage Instructions

The <style> tag defines the style information of the HTML document.

In the <style> element, you can specify how the HTML document is displayed in the browser.

Each HTML document can contain multiple <style> tags.

Tips and Notes

Tips:To link an external stylesheet, use <link> tag.

Tips:If you want to learn more about CSS, please read our CSS Tutorial.

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

HTML 4.01 with HTML5difference

The "scoped" attribute is an HTML 5 new attribute, which allows us to define styles for a specific part of the document rather than the entire document.
If the "scoped" attribute is used, the specified styles can only be applied to the parent element and its child elements of the style element.

Attribute

New: HTML5 new attribute.

AttributeValueDescription
mediamedia_querySpecify different media types for the stylesheet.
scopedHTML5scopedIf this attribute is used, the style is applied only to the parent element of the style element and its child elements.
typetext/cssSpecify the MIME type of the stylesheet.

Global Attributes

Support for <style> tag Global Attributes of HTML.

Event Attributes

Support for <style> tag HTML Event Attributes.

Related Articles

HTML Tutorial:HTML CSS

HTML DOM Reference Manual:Style Object