style

<style>

HTML的<style>元素包含了文档的样式化信息或者文档的一部分。指定的样式化星系包含的该元素内,通常是CSS的格式。

内容类别 Metadata content , 如果指定了scoped属性 : flow content.
允许的内容与类型属性匹配的文本内容,即text / css。
标记遗漏这两个标签都不能省略。
允许的父级任何接受 Metadata content 内容的元素。
允许ARIA角色没有
DOM接口HTMLStyleElement

属性

该元素包含所有全局属性

type该属性以MIME类型(不应该指定字符集)定义样式语言。如果该属性未指定,则默认为‘text/css'。

例子

一个简单的样式表

<style type="text/css"> body { color:red; } </style>

规范

SpecificationStatusComment
HTML Living StandardThe definition of 'style' in that specification.Living Standard
HTML5The definition of 'style' in that specification.RecommendationNo change from HTML 4.01 Specification.
HTML 4.01 SpecificationThe definition of 'style' in that specification.Recommendation

浏览器兼容性

FeatureChromeEdgeFirefoxInternet ExplorerOperaSafari
Basic Support1.0(Yes)1.03.03.51.0
type1.0(Yes)1.03.03.51.0
media1.0(Yes)1.03.03.51.0
title1.0(Yes)1.03.03.51.0
scoped19.0 — 35.02No21.0NoNoNo

FeatureAndroidChrome for AndroidEdge mobileFirefox for AndroidIE mobileOpera AndroidiOS Safari
Basic Support1.01.0(Yes)1.09.016.01.0
type1.01.0(Yes)1.09.016.01.0
media1.01.0(Yes)1.09.016.01.0
title1.01.0(Yes)1.09.016.01.0
scopedNoNoNo21.0NoNoNo