<style>
HTML <style> Tag
Instance
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php中文网(php.cn)</title> <style type="text/css"> h1 {color:red;} p {color:blue;} </style> </head> <body> <h1>这是一个标题</h1> <p>这是一个段落。</p> </body> </html>
Run Example»
Click the "Run Instance" button to view the online instance
Browser support
All major browsers support< style> tag.
Tag definition and usage instructions
<style> tag defines the style information of the HTML document.
In the <style> element, you can specify how the HTML document is rendered in the browser.
Each HTML document can contain multiple <style> tags.
Tips and Notes
Tips: To link to an external style sheet, use the <link> tag.
Tip: To learn more about style sheets, read our CSS tutorial.
Note: If the "scoped" attribute is not used, each <style> tag must be located in the head header area.
Differences between HTML 4.01 and HTML5
The "scoped" attribute is a new attribute in HTML 5, which allows us to define styles for specified parts of the document, rather than the entire document .
If you use the "scoped" attribute, the specified style can only be applied to the parent element of the style element and its child elements.
Attributes
New: New attributes in HTML5.
Attributes | Value | Description |
---|---|---|
media | media_query | Specify different media types for style sheets. |
scopedNew | scoped | If this attribute is used, the style is only applied to the parent element of the style element and its child element. |
type | text/css | Specifies the MIME type of the style sheet. |
Global attributes
<style> tag supports global attributes of HTML.
Event attributes
<style> tag supports HTML event attributes.
Related Articles
HTML Tutorial: HTML CSS
HTML DOM Reference Manual: Style Object