CSS Portal

HTML <code> Tag

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
<code>
HTML TagThis tag is supported by all modern browsers.
Updated 26th December 2025

Description

The <code> element in HTML is used to represent a fragment of computer code. It is intended for displaying programming or markup code inline within a paragraph or other textual content. Unlike other textual elements, <code> emphasizes that the content is to be interpreted as literal code rather than normal prose.

Visually, browsers typically render <code> text in a monospace (fixed-width) font to distinguish it from surrounding content, which helps improve readability for developers and users referencing code snippets. It is important to note that <code> does not automatically format the text as a block or preserve whitespace; it is primarily an inline element. For multi-line code blocks, <pre> is often used in combination with <code> to preserve indentation and line breaks.

The <code> tag is semantically meaningful and aids accessibility. Screen readers and other assistive technologies may announce it as code, helping users understand the context of the content. It is commonly used in documentation, tutorials, technical articles, and anywhere specific code needs to be highlighted within descriptive text.

Example usage (inline):

<p>To display text in bold, use the <code>strong</code> tag.</p>

Example usage (with <pre> for blocks):

<pre><code>
function greet(name) {
    console.log("Hello, " + name + "!");
}
</code></pre>

Properties

Permitted Parents
Any element that accepts phrasing content
Content
Inline and text
Start/End Tags
Start tag: required, End tag: required

Example

To create a new array, type the following: <code>var faq = new Array(3)</code>
Open in editor

Attributes

None

Global Attributes

The <code> tag also supports the Global Attributes in HTML5

Event Attributes

The <code> tag also supports the Event Attributes in HTML5

Browser Support

The following information will show you the current browser support for the HTML <code> tag. Hover over a browser icon to see the version that first introduced support for this HTML tag.

This tag is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee