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:

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


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
  • Internet Explorer
  • Firefox
  • Opera
  • Safari


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


1


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.