<code>

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

Revision Content

Summary

The HTML <code> Element represents a fragment of computer code. By default, it is displayed in the browser's default monospace font.

Attributes

This element has no other attributes than the global attributes, common to all elements.

Example

<p>Regular text. <code>This is code.</code> Regular text.</p>

Result

Regular text. This is code. Regular text.

Note

A CSS rule can be defined for the code selector to override the browser's default font face. Preferences set by the user might take precedence over the specified CSS.

Specifications

Specification Status Comment
{{ SpecName('HTML WHATWG', 'text-level-semantics.html#the-code-element', '<code>') }} {{ Spec2('HTML WHATWG') }}  
{{ SpecName('HTML5 W3C', 'the-code-element.html#the-b-element', '<code>') }} {{ Spec2('HTML5 W3C') }}  
{{ SpecName('HTML4.01', 'struct/text.html#h-9.2.1', '<code>') }} {{ Spec2('HTML4.01') }}  

Browser compatibility

{{ CompatibilityTable() }}

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support 1.0 {{ CompatVersionDesktop("1.0") }} {{ CompatVersionUnknown() }} {{ CompatVersionUnknown() }} {{ CompatVersionUnknown() }}
Feature Android Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
Basic support {{ CompatVersionUnknown() }} {{ CompatVersionMobile("1.0") }} {{ CompatVersionUnknown() }} {{ CompatVersionUnknown() }} {{ CompatVersionUnknown() }}

See also

  • {{ HTMLElement("blockquote") }} element
  • {{ HTMLElement("q") }} element
{{ HTML:Element_Navigation() }}

Revision Source

<h2 id="Summary">Summary</h2>
<p>The <strong>HTML <span style="font-family: Courier New;">&lt;code&gt;</span> Element</strong> represents a fragment of computer code. By default, it is displayed in the browser's default monospace font.</p>
<ul class="htmlelt">
  <li><dfn><a href="/en-US/docs/HTML/Content_categories" title="/en-US/docs/HTML/Content_categories">Content categories</a></dfn> <a href="/en-US/docs/HTML/Content_categories#flow_content" title="HTML/Content categories#flow content">Flow content</a>, <a href="/en-US/docs/HTML/Content_categories#phrasing_content" title="HTML/Content categories#phrasing content">phrasing content</a>, palpape content.</li>
  <li><dfn>Permitted content</dfn> <a href="/en-US/docs/HTML/Content_categories#Phrasing_content" title="en-US/docs/HTML/Content_categories#Phrasing_content">Phrasing content</a>.</li>
  <li><dfn>Tag omission</dfn> {{ no_tag_omission() }}</li>
  <li><dfn>Permitted parent elements</dfn> Any element that accepts <a href="/en-US/docs/HTML/Content_categories#Phrasing_content" title="en-US/docs/HTML/Content_categories#Phrasing_content">phrasing content</a>.</li>
  <li><dfn>DOM interface</dfn> {{ domxref("HTMLElement")}} Up to Gecko 1.9.2 (Firefox 4) inclusive, Firefox implements the <a href="/en-US/docs/DOM/span" title="DOM/span"><span style="font-family: Courier New;">HTMLSpanElement</span></a> interface for this element.</li>
</ul>
<h2 id="Attributes">Attributes</h2>
<p>This element has no other attributes than the <a href="/en/HTML/Global_attributes" rel="internal">global attributes</a>, common to all elements.</p>
<h2 id="Example">Example</h2>
<pre class="brush: html">
&lt;p&gt;Regular text. &lt;code&gt;This is code.&lt;/code&gt; Regular text.&lt;/p&gt;
</pre>
<h3 id="Result" name="Result">Result</h3>
<p>Regular text. <code>This is code.</code> Regular text.</p>
<h2 id="Note">Note</h2>
<p>A CSS rule can be defined for the <code>code</code> selector to override the browser's default font face. Preferences set by the user might take precedence over the specified CSS.</p>
<h2 id="Specifications" name="Specifications">Specifications</h2>
<table class="standard-table">
  <thead>
    <tr>
      <th scope="col">Specification</th>
      <th scope="col">Status</th>
      <th scope="col">Comment</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>{{ SpecName('HTML WHATWG', 'text-level-semantics.html#the-code-element', '&lt;code&gt;') }}</td>
      <td>{{ Spec2('HTML WHATWG') }}</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>{{ SpecName('HTML5 W3C', 'the-code-element.html#the-b-element', '&lt;code&gt;') }}</td>
      <td>{{ Spec2('HTML5 W3C') }}</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>{{ SpecName('HTML4.01', 'struct/text.html#h-9.2.1', '&lt;code&gt;') }}</td>
      <td>{{ Spec2('HTML4.01') }}</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>1.0</td>
        <td>{{ CompatVersionDesktop("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&nbsp;Phone</th>
        <th>Opera Mobile</th>
        <th>Safari Mobile</th>
      </tr>
      <tr>
        <td>Basic support</td>
        <td>{{ CompatVersionUnknown() }}</td>
        <td>{{ CompatVersionMobile("1.0") }}</td>
        <td>{{ CompatVersionUnknown() }}</td>
        <td>{{ CompatVersionUnknown() }}</td>
        <td>{{ CompatVersionUnknown() }}</td>
      </tr>
    </tbody>
  </table>
</div>
<h2 id="See_also" name="See_also">See also</h2>
<ul>
  <li>{{ HTMLElement("blockquote") }} element</li>
  <li>{{ HTMLElement("q") }} element</li>
</ul>
<div>
  {{ HTML:Element_Navigation() }}</div>
Revert to this revision