Summary
The HTML <style> element contains style information for a document, or a part of document. The specific style information is contained inside of this element, usually in the CSS.
Attributes
This element includes the global attributes.
-
type
-
This attribute defines the styling language as a MIME type (charset should not be specified). 'text/css' is assumed if this attribute is absent.
-
media
-
Which media should this style apply to. Should be a media query, see http://dev.w3.org/csswg/css3-mediaqueries.
-
scoped
-
If this attribute is present, then the style applies only to its parent element. If absent, the style applies to the whole document.
-
title
-
Specifies alternative style sheet sets.
-
disabled
-
If set, disables (does not apply) the style rules to the
Document that are specified within the element.
Examples
A simple stylesheet
<style type="text/css">
body {
color:red;
}
</style>
A scoped stylesheet
<article>
<div>The scoped attribute allows for you to include style elements mid-document.
Inside rules only apply to the parent element.</div>
<p>This text should be black. If it is red your browser does not support the scoped attribute.</p>
<section>
<style scoped>
p { color: red; }
</style>
<p>This should be red.</p>
</section>
</article>
Live sample
Specifications
Browser compatibility
| Feature |
Chrome |
Firefox (Gecko) |
Internet Explorer |
Opera |
Safari (WebKit) |
| Basic support |
? |
21.0 (21.0) |
Not supported |
Not supported |
Not supported |
| Feature |
Android |
Firefox Mobile (Gecko) |
IE Phone |
Opera Mobile |
Safari Mobile |
| Basic suppport |
? |
21.0 (21.0) |
Not supported |
Not supported |
Not supported |
See also
- The
<link> element allowing to use external style sheets.