Open In App

HTML <code> Tag

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: 

Syntax: 

<code> Contents... </code>

Example 1: 




<!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:




<!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:

Supported Browsers: 


Article Tags :