Open In App

HTML <code> Tag

Last Updated : 18 Jan, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

The <code> tag in HTML is used to define the piece of computer code. During the creation of web pages sometimes there is a need to display computer programming code. It could be done by any basic heading tag of HTML but HTML provides a separate tag which is <code>. 

The code tag is a specific type of text that represents computer output. HTML provides many methods for text formatting but <code> tag is displayed with fixed letter size, font, and spacing.

Some points about <code> tag: 

  • It is mainly used to display the code snippet in the web browser.
  • This tag styles its element to match the computer’s default text format.
  • The web browsers by default use a monospace font family for displaying <code> tags element content.

Syntax: 

<code> Contents... </code>

Example 1: 

HTML




<!DOCTYPE html>
<html>
 
<body>
    <pre>
<!--code Tag starts here -->
      <code>
#include<stdio.h>
int main() {
    printf("Hello Geeks");
}
<!--code Tag starts here -->
      </code>
    </pre>
</body>
 
</html>


Output:

Example 2:

HTML




<!DOCTYPE html>
<html>
 
<head>
    <title>Code Tag Example</title>
</head>
 
<body>
    <h1><code>HTML</code> is fun!</h1>
    <p>Learn to code with <code><html></code>.</p>
    <p>Explore the world of <code><Geeks></code>.</p>
</body>
 
</html>


Output:

edr

Supported Browsers: 

  • Google Chrome 1
  • Edge 12
  • Firefox 1
  • Opera 15
  • Safari 4


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads