Tutorialspoint.dev

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 separated tag which is <code>.
The code tag is a specific type of text which represent computer output. HTML provides many methods for text-formatting but <code> tag is displayed with fixed letter size, font, and spacing.

Syntax:

<code> Contents... </code>

Example 1:

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

Output

Example 2:



<pre>
<code>
class GFG 
    // Program begins with a call to main()
    // Print "Hello, World" to the terminal window 
    public static void main(String args[]) 
    
        System.out.println("Hello, World"); 
    
</code>
</pre>                    

Output

The program which is written inside the <code> tag has some different font size and font type to the basic heading tag and paragraph tag. <pre> tag is used to display code snippet because it always keeps the text formatting as it.

Some points about <code> tag:

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

Supported Browsers: The browser supported by <code> tag are listed below:

  • Google Chrome
  • Firefox
  • Opera
  • Internet Explorer
  • Safari


This article is attributed to GeeksforGeeks.org

leave a comment

code

0 Comments

load comments

Subscribe to Our Newsletter