code

< html‎ | elements
Jump to: navigation, search

code

This article is In Progress.



Summary

The code element specifies a fragment of computer code.


Overview Table

DOM Interface HTMLElement

Content within a code element is used to indicate a selection of text that is computer programming code.


Compatibility

Do you think this data can be improved? You can ask to add by opening an issue or make a pull request.

Desktop

FeaturesChromeFirefoxInternet ExplorerOperaSafari
Basic support
1.0
Yes
1.0
Yes
?
Yes
?
Yes
?
Yes

Mobile

FeaturesAndroidFirefox MobileIE PhoneOpera MobileSafari Mobile
Basic support
?
Yes
1.0
Yes
?
Yes
?
Yes
?
Yes

Examples

This is a simple example of the code element to display a CSS snippet.

HTML

<p>Now let’s set the color to red: <code>color: #f00;</code>.</p>

This is another take on the example above, but includes a class to indicate the type of code being written.

HTML

<p>Now let’s set the color to red: 
<code class="language-css">color: #f00;</code>.</p>

Usage

The code element is a phrasing-level element used to indicate a selection of code. It must not contain block-level elements, but it may contain other phrasing-level elements.

Often, authors will use a class attribute to indicate the language being used in the code element (see Example 2).

Notes

While the code element is often visually-presented in a monospace font like the pre element, unlike pre white space (spaces, tabs, etc.) inside a code element is **not preserved**.

When representing HTML code within a code element, remember to encode the reserved characters < and > with their HTML entity equivalents (&lt; and &gt;, respectively).



See also

Related articles

HTML


































  • code

















… further results

Text








































  • code











… further results


Related pages (MSDN)

  • samp

Attribution

This article contains content originally from external sources.

Portions of this content come from the Microsoft Developer Network: [Windows Internet Explorer API reference Article]