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:
The example below shows the <code>
tag in action.
Example
Try this code »<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.
Basic Support—
|
Further Reading
See tutorial on: HTML Text Formatting.