The code Tag

The `<code>` tag in HTML is designed to display computer code snippets with fixed formatting for optimal readability. It renders the code in a monospace font, preserving the original spacing and layout. The `<code>` tag also supports both global attributes and event attributes, allowing for flexible styling and interaction.

Syntax:

<code> Computer code contents... </code>

Note: The program that is written inside the <code> tag has some different font sizes and font types to the basic heading tag and paragraph tag.

Example: The <code> tag displays a C program within a <pre> tag, preserving whitespace and formatting. The C program includes the stdio.h library and a main function that prints “Hello Geeks”.

html
<!DOCTYPE html>
<html>

<body>
    <pre>
        <code> 
            #include &lt;stdio.h&gt; 
            int main() { 
                printf("Hello Geeks"); 
            } 
        </code> 
    </pre>
</body>

</html>

Output: 

HTML Computer Code Elements

The computer has a unique formatting and text style for displaying the messages related to codes. There are several elements available to mark up computer code elements using HTML which are as follows:

Table of Content

  • The code Tag
  • The kbd Tag
  • The pre Tag
  • The samp Tag
  • The var Tag
  • HTML Computer Code Elements
  • Supported Browsers

Similar Reads

The code Tag

The `` tag in HTML is designed to display computer code snippets with fixed formatting for optimal readability. It renders the code in a monospace font, preserving the original spacing and layout. The `` tag also supports both global attributes and event attributes, allowing for flexible styling and interaction....

The kbd Tag

The `` tag is used to define keyboard input. The text between the `` tags represents text that should be typed on a keyboard. This text is typically displayed in the browser’s default monospace font, though a richer effect can be achieved with CSS. The `` tag has no specific attributes....

The pre Tag

The `

` tag in HTML defines a block of preformatted text, preserving spaces, line breaks, tabs, and other formatting characters that browsers usually ignore. Text within the `
` element is displayed in a fixed-width font, but this can be changed using CSS. The `
` tag requires both opening and closing tags....
													

The samp Tag

The `` tag is used to define sample output from a computer program. It encloses inline text representing a sample or quoted output from a program....

The var Tag

The `` tag is used to specify a variable in a mathematical equation or a computer program. In most browsers, the content of this tag is displayed in italic format....

HTML Computer Code Elements

The table below shows the HTML Computer Code Tags with their description:...

Supported Browsers

Google ChromeMicrosoft EdgeFirefoxOperaSafari...

Contact Us