English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
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.
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 ‹/›
IEFirefoxOperaChromeSafari
All mainstream browsers support the <style> tag.
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: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.
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.
New: HTML5 new attribute.
Attribute | Value | Description |
---|---|---|
media | media_query | Specify different media types for the stylesheet. |
scopedHTML5 | scoped | If this attribute is used, the style is applied only to the parent element of the style element and its child elements. |
type | text/css | Specify the MIME type of the stylesheet. |
Support for <style> tag Global Attributes of HTML.
Support for <style> tag HTML Event Attributes.
HTML Tutorial:HTML CSS
HTML DOM Reference Manual:Style Object