--- title: style slug: Web/HTML/Global_attributes/style translation_of: Web/HTML/Global_attributes/style ---
{{HTMLSidebar("Global_attributes")}}

style 全局属性 包含应用到元素的 CSS 样式声明。要注意样式最好定义在单独的文件中。这个属性以及 {{HTMLElement("style")}} 元素的主要目的是快速装饰。例如用于测试目的。

用法注解:这个属性不能用于传递语义信息。即使所有样式都移除了,页面也应该保留正确语义。通常它不应用于隐藏不相关的信息;这应该使用 hidden 属性来实现。

规范

Specification Status Comment
{{SpecName('HTML WHATWG', "dom.html#the-style-attribute", "style")}} {{Spec2('HTML WHATWG')}} No change from latest snapshot, {{SpecName('HTML5.1')}}
{{SpecName('HTML5.1', "dom.html#the-style-attribute", "style")}} {{Spec2('HTML5.1')}} Snapshot of {{SpecName('HTML WHATWG')}}, no change from {{SpecName('HTML5 W3C')}}
{{SpecName('HTML5 W3C', "dom.html#the-style-attribute", "style")}} {{Spec2('HTML5 W3C')}} Snapshot of {{SpecName('HTML WHATWG')}}. From {{SpecName("HTML4.01")}}, it is now a true global attribute.
{{SpecName('HTML4.01', 'present/styles.html#h-14.2.2', 'style')}} {{Spec2('HTML4.01')}} Supported on all elements but {{HTMLElement("base")}}, {{HTMLElement("basefont")}}, {{HTMLElement("head")}}, {{HTMLElement("html")}}, {{HTMLElement("meta")}}, {{HTMLElement("param")}}, {{HTMLElement("script")}}, {{HTMLElement("style")}}, and {{HTMLElement("title")}}.
{{SpecName("CSS3 Style", "", "")}} {{Spec2("CSS3 Style")}} Defines the content of the style attribute.

浏览器兼容性

{{CompatibilityTable}}

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatVersionUnknown}}
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatVersionUnknown}}

另见