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.


<code> Contents... </code>

Example 1:

int main() {
    printf("Hello Geeks");


Example 2:

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"); 



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

You Might Also Like

leave a comment



load comments

Subscribe to Our Newsletter