Signup/Sign In
LAST UPDATED: JUNE 2, 2020

HTML code Tag

The HTML <code> tag is used to enclose the programming related terms to show them differently in an HTML document. When we create webpages with programming-related or computer-related content, then to show some specific coding terms like some function name, or any variable name, etc, we can use the <code> tag.

In this tutorial too, you will see that wherever we have specified the <code> tag, the styling for it is different, that is because it is enclosed within the <code> tag.

  • The <code> tag is used to display enclosed text in a monospaced font, such as courier.

  • If you want to display the programming code in multiple lines, then you can place the <code> tag inside the <pre> tag, or simply use the <pre> tag.

  • Also, this is an inline element.

HTML <code> Tag - Syntax and Usage

The <code> tag requires the start(opening) tag and end(closing) tag.

Required syntax for the same is given below:

<code>
    some text
</code>

HTML <code> Tag Basic Example

Below we have a basic example of the <code> tag:

In the code example above, we have provided some styling too for the <code> tag to highlight the test enclosed in it.

HTML <code> Tag Attributes

This element does not have any specific attributes although this element supports Global attributes and Event attributes.

Attributes Description
class indicates a class name for the <code> tag
id indicates a unique id for the <code> tag
style indicates an inline style for the <code> tag
title indicates a title for the <code> tag

Default CSS style for HTML <code> tag

Most of the Browsers use these default CSS Settings:

code {
    font-family: monospace;
}

Browser Support For HTML <code> tag

Following browsers support this attribute:

  • Firefox 1+

  • Google Chrome 1+

  • Internet Explorer 2+

  • Apple Safari 1+

  • Opera 4+



About the author:
Aspiring Software developer working as a content writer. I like computer related subjects like Computer Networks, Operating system, CAO, Database, and I am also learning Python.