How to define a piece of computer code in HTML5?

In this article, we define a piece of code by using the code Element. It 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 which represents 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:

Example:

filter_none

edit
close

play_arrow

link
brightness_4
code

<html>
    <head>
        <title>
            How to define a piece of code in HTML
        </title>
    </head>
    <body>
        <h2>GeeksForGeeks</h2>
        <h2>How to define a piece of code in HTML</h2>
<pre
<code
#include<stdio.h
int main() { 
    printf("Hello Geeks"); 
</code
</pre
  
    </body>
</html>

chevron_right


Output:



Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<html>
    <head>
        <title>
            How to define a piece of code in HTML
        </title>
    </head>
    <body>
        <h2>GeeksForGeeks</h2>
        <h2>How to define a piece of code in HTML</h2>
<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>
    </body>
</html>

chevron_right


Output:

Supported Browsers are listed below:

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

full-stack-img




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 :


Be the First to upvote.


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