{{HTMLRef}}
The HTML <style>
element contains style information for a document, or part of a document. By default, the style instructions written inside that element are expected to be CSS.
Content categories | Metadata content |
---|---|
Permitted content | Text content matching the type attribute, that is text/css . |
Tag omission | Neither tag is omissible. |
Permitted parent elements | Where metadata content is expected or in a {{HTMLElement("noscript")}} element itself a child of {{HTMLElement("head")}} element. |
DOM interface | {{domxref("HTMLStyleElement")}} |
Attributes
This element includes the global attributes.
- {{htmlattrdef("type")}}
- This attribute defines the styling language as a MIME type (charset should not be specified). This attribute is optional and default to
text/css
if it's missing. - {{htmlattrdef("media")}}
- This attribute defines which media the style should apply to. It's value is a media query, which default to
all
if the attribute is missing. - {{htmlattrdef("title")}}
- Specifies alternative style sheet sets.
Examples
A simple stylesheet
<style type="text/css"> body { color:red; } </style>
Specifications
Specification | Status | Comment |
---|---|---|
{{ SpecName('HTML WHATWG', 'document-metadata.html#the-style-element', 'style') }} | {{ Spec2('HTML WHATWG') }} | |
{{ SpecName('HTML5 W3C', 'document-metadata.html#the-style-element', 'style') }} | {{ Spec2('HTML5 W3C') }} | No change from {{ SpecName('HTML4.01') }}. |
{{ SpecName('HTML4.01', 'present/styles.html#h-14.2.3', 'style') }} | {{ Spec2('HTML4.01') }} |
Browser compatibility
{{CompatibilityTable}}
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
---|---|---|---|---|---|
Basic support | {{CompatVersionUnknown}} | {{CompatGeckoDesktop(1.0)}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} |
Feature | Android | Firefox Mobile (Gecko) | IE Phone | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|
Basic support | {{CompatVersionUnknown}} | {{CompatGeckoDesktop(1.0)}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} |
See also
- The {{HTMLElement("link")}} element allowing to use external style sheets.