HTMLs Tutorial

HTML Tutorial HTML Tags HTML Basic Tags HTML Attributes HTML Elements HTML Formatting HTML Text Format HTML body tag HTML samp tag HTML script Tag HTML section tag HTML select tag HTML source tag HTML span tag HTML strike tag HTML strong tag HTML style tag HTML sub tag HTML summary tag HTML sup Tag HTML svg tag HTML table tag HTML u tag HTML Headings HTML Paragraphs HTML wbr tag HTML Anchor HTML Image HTML Lists HTML Ordered List HTML Unordered List HTML Form HTML Form input HTML with CSS HTML Layouts HTML References HTML Frames HTML Links Fieldset Tag in HTML Basic HTML Tags Br Tag in HTML Free HTML Templates How to Create a Table in HTML HTML Calendar HTML Card HTML Cellspacing HTML Center Image HTML Checkbox Read-only HTML Cleaner HTML Code for a Tab HTML Comment HTML Compiler HTML Nested Forms HTML Overlay Text on the Image HTML Select Option Default HTML Snake Game HTML Subheader HTML Tab Character dd Tag in HTML How Many HTML Tags are There HTML Align Tag HTML Responsive HTML Tab Code HTML Table Alternate Row Color HTML Table Fix Column Width Contact HTML DL Tag in HTML How to Insert Image in HTML HTML Background Color HTML Dark Mode How to Convert HTML to PNG HTML Data Toggle HTML Email Template HTML Font Color HTML Font Family ID and Class in HTML HTML Tab Space HTML Tab Tag HTML Itemprop HTML Itemscope HTML Form Design HTML Input Only Numbers HTML Textarea HTML to JPG HTML to Markdown Python li Tag in HTML MDN HTML What is the Correct HTML for Making a Hyperlink? What is the Root Element of an HTML Document How to Make a Box in HTML How to Save HTML Files in Notepad How to Align Text in HTML How to Change Font Color in HTML? How to Change Font Size in HTML How to Change Image Size in HTML How to Create a HTML Page How to Create a Link in HTML File? How to Create an HTML File? HR Tag in HTML HTML Base Tag HTML Default Attribute HTML Hyperlink HTML Indent HTML Injection Payloads HTML Input Numbers Only HTML Roadmap HTML Row Height HTML Schedule HTML Space HTML Tab HTML vs HTTP HTML5 API HTML5 Video HTML Collection to Array Text Area in HTML

HTML5 Advance

HTML5 Tutorial HTML5 Tags HTML Button Tag HTML canvas Tag HTML caption Tag HTML City tag HTML Tag HTML5 SVG HTML Event Attribute HTML5 Audio HTML5 Youtube HTML5 Button Tag HTML5 Tags

Misc

How to add JavaScript to HTML How to change font in HTML How to change text color in HTML HTML Date HTML Hide Element HTML Nested Table HTML Reset Button What does HTML stand for? HTML Background Image HTML Tag Div Tag in HTML How to insert Image in HTML How to create a link with no underline in HTML How to insert spacestabs in text using HTMLCSS HTML tag HTML Code HTML Tag HTML Canvas Design a tribute page using HTML and CSS What is a Container tag Font tag in HTML Difference between HTML and DHTML Empty Tag in HTML HTML Button Link Html Line Break Img src HTML Nested List in HTML Placeholder in HTML TD in HTML HTML Space Code HTML Target Attribute HTML Tag Markup Meaning in HTML Border-Collapse in HTML HTML Onclick Online HTML Compiler Convert HTML to PDF HTML Formatter HTML5 - Web Storage HTTP – Responses Container Tag in HTML DL Tag in HTML Horizontal Rule HTML HTML Tab Text Html Table Cell Background Color HTML Table Cell Color HTML Col Width How Many HTML Tags are There Convert String to Unicode Characters in Python HTML Runner HTML Style Attribute HTML Superscript Attribute HTML tabindex Marquee Tag in HTML HTML Dynamic Form HTML side Tag HTML Pattern Attribute HTML q Tag HTML Readonly Base 64 Encoding in HTML Documents Enhancing Data Portability and Security Evo Cam Web Cam HTML Free code camp HTML CSS How to Add a JS File in HTML? How to Add Picture in HTML How to Add the Logo in HTML? How to Add Video in HTML HTML Class Attribute HTML Entities HTML Form Elements HTML Form Templates HTML Marquee Tag HTML Radio Buttons HTML Text box HTML to JSX HTML Tooltip Basic HTML Codes How to Align Image Center in HTML HTML Header Tag HTML Image Tag HTML Next Line

HTML Code Tag

The code tag in HTML is a phrase tag used to insert a piece of computer programming code. In HTML there is a separate tag named as <code> tag. Sometimes, there is a place in webpages where you want to format the text in such a way that your website, which is related to coding or Information Technology field, then you can display code in your website. That’s why we use the code tag. When we need to show computer code on web pages, we use the code tag.

The code is displayed in the monospace font, a default browser font. Primarily we use code tag when we want to show a single line in the webpage. For showing multi-line, we prefer to use the <pre> tag.

HTML <code> tag supports the Global attributes, which can be used to any HTML element.

HTML <code> tag also supports the Event attributes on which the browser takes action.

Syntax of HTML Code Tag

<code>Computer code</code>

Examples of HTML Code Tag

Example 1: This example has only a single line of code.

<html>  
   <head>  
      <title>code</title>
      </head>  
      <body>  
         <p>This is a code.</p> 
            <code>var a=6; </code>
         </p>
      </body>  
</html>  

Output: You can see the code with the monospace font, as shown in the image below.

HTML Code Tag

Example 2: We have used multi-lines of Java programming code in this example.

<html>
   <head> 
      <title>code</title>
      </head> 
      <body> 
         <p>This is a Java Programming code.</p> 
            <code>import java.util.Scanner;
                public class AddTwoNumbers {
                
                    public static void main(String[] args) {
                        
                        int number1, number2, sum;
                        Scanner sc = new Scanner(System.in);
                        System.out.println("Enter First Number: ");
                        num1 = sc.nextInt();
                        
                        System.out.println("Enter Second Number: ");
                        num2 = sc.nextInt();
                        
                        sc.close();
                        sum = number1 + number2;
                        System.out.println("Sum of two numbers: "+sum);
                    }
                }
            </code>
         </p>
      </body>  
</html>  

Output: Although it is a multi-line code, we can see that it displays in a single line because we are using code tags for single-line code display.

HTML Code Tag

Example 3: Use of <pre> tag.

<html>  
   <head>  
      <title>code</title>
      </head>  
      <body>  
         <p>This is a Java Programming Code.</p> 
            <pre>import java.util.Scanner;
                public class AddTwoNumbers {
                
                    public static void main(String[] args) {
                        
                        int number1, number2, sum;
                        Scanner sc = new Scanner(System.in);
                        System.out.println("Enter First Number: ");
                        num1 = sc.nextInt();
                        
                        System.out.println("Enter Second Number: ");
                        num2 = sc.nextInt();
                        
                        sc.close();
                        sum = number1 + number2;
                        System.out.println("Sum of two numbers: "+sum);
                    }
                }
            </pre>
         </p>
      </body>  
</html>  

Output: You can see code displays in multi-lines because we have used the <pre> tag in this example.

HTML Code Tag

Example 4: We can also used CSS to highlight the code.

<!DOCTYPE html>
<html>
  <head>
    <title>Code</title>
    <style>
      .style {
        font-size: 20px;
        line-height: 28px;
        background-color: rgb(177, 228, 245);
        color: #f9e3e3;
      }
    </style>
  </head>
  <body>
    <p>This is a code.</p>
    <code class="style">The code goes here.</code>
    <p>Happy coding!</p>
  </body>
</html>

Output: As you can see in the given image, the code looks attractive with the use of CSS.

HTML Code Tag

Browser Supported

  1. Google Chrome
  2. Internet Explorer
  3. Microsoft Edge
  4. Mozilla Firefox
  5. Opera
  6. Safari