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 978041 of <content>

  • Revision slug: Web/HTML/Element/content
  • Revision title: <content>
  • Revision id: 978041
  • Created:
  • Creator: teoli
  • Is current revision? No
  • Comment

Revision Content

{{Deprecated_header}}

The HTML <content> element is used inside of Shadow DOM as an {{glossary("insertion point")}}. It is not intended to be used in ordinary HTML. It is used with Web Components.

Note: Though present in early draft of the specifications and implemented in several browsers, this element has been removed in later versions of the spec.

Content categories Transparent content.
Permitted content Flow content.
Tag omission {{no_tag_omission}}
Permitted parent elements Any element that accepts flow content.
DOM interface {{domxref("HTMLContentElement")}}

Attributes

This element includes the global attributes.

select
A comma-separated list of selectors. These have the same syntax as CSS selectors. They select the content to insert in place of the <content> element.

Example

Here is a simple example of using the <content> element. It is an HTML file with everything needed in it.

Note: For this code to work, the browser you display it in must support Web Components. See Enabling Web Components in Firefox.

<html>
  <head></head>
  <body>
  <!-- The original content accessed by <content> -->
  <div>
    <h4>My Content Heading</h4>
    <p>My content text</p>
  </div>

  <script>
  // Get the <div> above.
  var myContent = document.querySelector('div');
  // Create a shadow DOM on the <div>
  var shadowroot = myContent.createShadowRoot();
  // Insert into the shadow DOM a new heading and 
  // part of the original content: the <p> tag.
  shadowroot.innerHTML =
   '<h2>Inserted Heading</h2> <content select="p"></content>';
  </script>

  </body>
</html>

If you display this in a web browser it should look like the following.

content example

Specifications

Specification Status Comment
{{SpecName('Shadow DOM', "#the-content-element", "content")}} {{Spec2('Shadow DOM')}}  

Browser compatibility

{{CompatibilityTable}}

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support 35 {{CompatGeckoDesktop("28")}} [1] {{CompatNo}} 26 {{CompatNo}}
Feature Android Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
Basic support 37 {{CompatGeckoMobile("28")}} [1] {{CompatNo}} {{CompatUnknown}} {{CompatUnknown}}

[1] If Shadow DOM is not enabled in Firefox, <content> elements will behave like {{domxref("HTMLUnknownElement")}}. Shadow DOM was first implemented in Firefox 33 and is behind a preference, dom.webcomponents.enabled, which is disabled by default.

See also

  • Web Components
  • {{HTMLElement("shadow")}}, {{HTMLElement("template")}}, {{HTMLElement("element")}}
{{HTMLRef}}

Revision Source

<p name="Summary">{{Deprecated_header}}</p>

<p>The <strong><a href="/en-US/docs/Web/HTML">HTML</a>&nbsp;<code>&lt;content&gt;</code></strong>&nbsp;element is used inside of <a href="/en-US/docs/Web/Web_Components/Shadow_DOM">Shadow DOM</a> as an {{glossary("insertion point")}}. It is not intended to be used in ordinary HTML. It is used with <a href="/en-US/docs/Web/Web_Components">Web Components</a>.</p>

<div class="note">
<p><strong>Note: </strong>Though present in early draft of the specifications and implemented in several browsers, this element has been removed in later versions of the spec.</p>
</div>

<table class="properties">
 <tbody>
  <tr>
   <th scope="row"><a href="/en-US/docs/Web/HTML/Content_categories" title="HTML/Content_categories">Content categories</a></th>
   <td><a href="/en-US/docs/Web/HTML/Content_categories#Transparent_content_model" title="HTML/Content_categories#Transparent_content_model">Transparent content</a>.</td>
  </tr>
  <tr>
   <th scope="row">Permitted content</th>
   <td><a href="/en-US/docs/Web/HTML/Content_categories#Flow_content">Flow content</a>.</td>
  </tr>
  <tr>
   <th scope="row">Tag omission</th>
   <td>{{no_tag_omission}}</td>
  </tr>
  <tr>
   <th scope="row">Permitted parent elements</th>
   <td>Any element that accepts flow content.</td>
  </tr>
  <tr>
   <th scope="row">DOM interface</th>
   <td>{{domxref("HTMLContentElement")}}</td>
  </tr>
 </tbody>
</table>

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

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

<dl>
 <dt>select</dt>
 <dd>A comma-separated list of selectors. These have the same syntax as CSS selectors. They select the content to insert in place of the <code>&lt;content&gt;</code> element.</dd>
</dl>

<h2 id="Example">Example</h2>

<p>Here is a simple example of using the <code>&lt;content&gt;</code> element. It is an HTML file with everything needed in it.</p>

<div class="note">
<p><strong>Note:</strong> For this code to work, the browser you display it in must support Web Components. See&nbsp;<a href="/en-US/docs/Web/Web_Components#Enabling_Web_Components_in_Firefox">Enabling Web Components in Firefox</a>.</p>
</div>

<pre class="brush: html">
&lt;html&gt;
  &lt;head&gt;&lt;/head&gt;
  &lt;body&gt;
&nbsp; &lt;!-- The original content accessed by &lt;content&gt; --&gt;
&nbsp; &lt;div&gt;
&nbsp; &nbsp; &lt;h4&gt;My Content Heading&lt;/h4&gt;
&nbsp; &nbsp; &lt;p&gt;My content text&lt;/p&gt;
&nbsp; &lt;/div&gt;

&nbsp; &lt;script&gt;
&nbsp; // Get the &lt;div&gt; above.
&nbsp; var myContent = document.querySelector('div');
&nbsp; // Create a shadow DOM on the &lt;div&gt;
&nbsp; var shadowroot = myContent.createShadowRoot();
&nbsp; // Insert into the shadow DOM a new heading and 
&nbsp; // part of the original content: the &lt;p&gt; tag.
&nbsp; shadowroot.innerHTML =
&nbsp;  '&lt;h2&gt;Inserted Heading&lt;/h2&gt; &lt;content select="p"&gt;&lt;/content&gt;';
&nbsp; &lt;/script&gt;

  &lt;/body&gt;
&lt;/html&gt;
</pre>

<p>If you display this in a web browser it should look like the following.</p>

<p><img alt="content example" src="https://mdn.mozillademos.org/files/10077/content-example.png" style="height:383px; width:716px" /></p>

<h2 id="Specifications">Specifications</h2>

<table class="spec-table standard-table">
 <tbody>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
  <tr>
   <td>{{SpecName('Shadow DOM', "#the-content-element", "content")}}</td>
   <td>{{Spec2('Shadow DOM')}}</td>
   <td>&nbsp;</td>
  </tr>
 </tbody>
</table>

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

<p>{{CompatibilityTable}}</p>

<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>35</td>
   <td><span style="font-size:12px; line-height:18px">{{CompatGeckoDesktop("28")}}</span>&nbsp;[1]</td>
   <td>{{CompatNo}}</td>
   <td>26</td>
   <td><span style="font-size:12px; line-height:18px">{{CompatNo}}</span></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>37</td>
   <td>{{CompatGeckoMobile("28")}} [1]</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
  </tr>
 </tbody>
</table>
</div>

<p>[1]&nbsp;If Shadow DOM is not enabled in Firefox, <code>&lt;content&gt;</code> elements will behave like {{domxref("HTMLUnknownElement")}}. Shadow DOM was first implemented in Firefox 33 and is behind a preference, <code>dom.webcomponents.enabled</code>, which is disabled by default.</p>

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

<ul>
 <li><a href="/en-US/docs/Web/Web_Components">Web Components</a></li>
 <li>{{HTMLElement("shadow")}}, {{HTMLElement("template")}},&nbsp;{{HTMLElement("element")}}</li>
</ul>

<div>{{HTMLRef}}</div>
Revert to this revision