Open In App

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:




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

Output:



Example 2:




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

Output:

Supported Browsers are listed below:


Article Tags :