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:
- 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 Beginner"); } <!--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 >< Beginner ></ code >.</ p > </ body > </ html > |
Output:
Supported Browsers:
- Google Chrome 1
- Edge 12
- Firefox 1
- Opera 15
- Safari 4