HTML Tags

HTML <code> Tag

Topic: HTML5 Tags ReferencePrev|Next

Description

The <code> tag represents a fragment of computer code — for example, a snippet of HTML or CSS, or some other programming language code.

The following table summarizes the usages context and the version history of this tag.

Placement: Inline
Content: Inline and text
Start/End Tag: Start tag: required, End tag: required
Version: HTML 2, 3.2, 4, 4.01,5

Note: By default, most of the browsers displays the content of <code> element in a monospace (fixed-width) font, such as "Courier", but this style can be overridden using the CSS font-family property.


Syntax

The basic syntax of the <code> tag is given with:

HTML / XHTML: <code> ... </code>

The example below shows the <code> tag in action.

<p>Regular text. <code>computer code</code> Regular text.</p>

Tip: Since spacing is important when presenting the computer codes, the <pre> element is most frequently used as a container for <code> elements because it preserves whitespace and line breaks.


Tag-Specific Attributes

The <code> tag doesn't have any specific attribute.


Global Attributes

Like all other HTML tags, the <code> tag supports the global attributes in HTML5.


Event Attributes

The <code> tag also supports the event attributes in HTML5.


Browser Compatibility

The <code> tag is supported in all major modern browsers.

Browsers Icon

Basic Support—

  • Firefox 1+
  • Google Chrome 1+
  • Internet Explorer 2+
  • Apple Safari 1+
  • Opera 4+

Further Reading

See tutorial on: HTML Text Formatting.

Related tag: <pre>, <kbd>, <tt>.

Bootstrap UI Design Templates Property Marvels - A Leading Real Estate Portal for Premium Properties