HTML <code> Tag
Last Updated :
18 Jan, 2024
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 >
#include< stdio.h >
int main() {
printf("Hello Geeks");
}
</ 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:
Supported Browsers:Â
- Google Chrome 1
- Edge 12
- Firefox 1
- Opera 15
- Safari 4
Share your thoughts in the comments
Please Login to comment...