Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Revision 1081520 of <style>

  • Revision slug: Web/HTML/Element/style
  • Revision title: <style>
  • Revision id: 1081520
  • Created:
  • Creator: ExplodingCabbage
  • Is current revision? No
  • Comment Cull all reference to the `scoped` attribute since it has been removed from both HTML specs (see https://github.com/w3c/html/pull/318 and https://github.com/whatwg/html/pull/1226)

Revision Content

{{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.

Revision Source

<p id="Summary">{{HTMLRef}}</p>

<p>The <strong>HTML <code>&lt;style&gt;</code> element</strong> contains style information for a document, or part of a document. By default, the style instructions written inside that element are expected to be <a href="/en-US/docs/Web/CSS">CSS</a>.</p>

<table class="properties">
 <tbody>
  <tr>
   <th><a href="/en-US/docs/Web/HTML/Content_categories">Content categories</a></th>
   <td><a href="/en-US/docs/Web/HTML/Content_categories#Metadata_content">Metadata content</a></td>
  </tr>
  <tr>
   <th>Permitted content</th>
   <td>Text content matching the <code>type</code> attribute, that is <code>text/css</code>.</td>
  </tr>
  <tr>
   <th>Tag omission</th>
   <td>Neither tag is omissible.</td>
  </tr>
  <tr>
   <th>Permitted parent elements</th>
   <td>Where metadata content is expected or in a {{HTMLElement("noscript")}} element itself a child of {{HTMLElement("head")}} element.</td>
  </tr>
  <tr>
   <th>DOM interface</th>
   <td>{{domxref("HTMLStyleElement")}}</td>
  </tr>
 </tbody>
</table>

<h2 id="Attributes">Attributes</h2>

<p>This element includes the <a href="/en-US/docs/Web/HTML/Global_attributes">global attributes</a>.</p>

<dl>
 <dt>{{htmlattrdef("type")}}</dt>
 <dd>This attribute defines the styling language as a MIME type (charset should not be specified). This attribute is optional and default to <code>text/css</code> if it's missing.</dd>
 <dt>{{htmlattrdef("media")}}</dt>
 <dd>This attribute&nbsp;defines which media the style should apply to. It's value is a <a href="/en-US/docs/Web/Guide/CSS/Media_queries">media query</a>, which default to <code>all</code> if the attribute is missing.</dd>
 <dt>{{htmlattrdef("title")}}</dt>
 <dd>Specifies alternative style sheet sets.</dd>
</dl>

<h2 id="Examples">Examples</h2>

<h3 id="A_simple_stylesheet">A simple stylesheet</h3>

<pre class="brush:html">
&lt;style type="text/css"&gt;
body {
  color:red;
}
&lt;/style&gt; 
</pre>

<h3 id="A_scoped_stylesheet">Specifications</h3>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
  <tr>
   <td>{{ SpecName('HTML WHATWG', 'document-metadata.html#the-style-element', 'style') }}</td>
   <td>{{ Spec2('HTML WHATWG') }}</td>
   <td>&nbsp;</td>
  </tr>
  <tr>
   <td>{{ SpecName('HTML5 W3C', 'document-metadata.html#the-style-element', 'style') }}</td>
   <td>{{ Spec2('HTML5 W3C') }}</td>
   <td>No change from {{ SpecName('HTML4.01') }}.</td>
  </tr>
  <tr>
   <td>{{ SpecName('HTML4.01', 'present/styles.html#h-14.2.3', 'style') }}</td>
   <td>{{ Spec2('HTML4.01') }}</td>
   <td>&nbsp;</td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility">Browser compatibility</h2>

<div>{{CompatibilityTable}}</div>

<div id="compat-desktop">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Chrome</th>
   <th>Firefox (Gecko)</th>
   <th>Internet Explorer</th>
   <th>Opera</th>
   <th>Safari (WebKit)</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatGeckoDesktop(1.0)}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
  </tr>
 </tbody>
</table>
</div>

<div id="compat-mobile">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Android</th>
   <th>Firefox Mobile (Gecko)</th>
   <th>IE Phone</th>
   <th>Opera Mobile</th>
   <th>Safari Mobile</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatGeckoDesktop(1.0)}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
  </tr>
 </tbody>
</table>
</div>

<p>&nbsp;</p>

<h2 id="See_also">See also</h2>

<ul>
 <li>The {{HTMLElement("link")}} element allowing to use external style sheets.</li>
</ul>
Revert to this revision