HTML Tags For Computer Code

The HTML computer code element displays codes within the HTML body. There are five HTML Tags For Computer Code elements used to display code outputs on a webpage. One thing to note about these elements is that, by default, they all appear in monospace font. Its good to know other HTML inputs elements, here they are

HTML Tags For Computer Code
  • <code>
  • <kbd>
  • <samp>
  • <var>
  • <pre>

Code, <code> TAG

The code tag is used to display programming code on a webpage. See what ANCHOR tags look like here

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Computer code</title>
</head>
<body>
   <code>
       <p>× = 4; <br></p>
       <p>y = 6; <br></p>
       <p> z = x + y; <br></p>
   </code> 
</body>
</html>

Code, <kbd> TAG

The kbd tag is used to display keyboard inputs on a screen. Basic HTML Tags

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Computer code</title>
</head>
<body>
   <kbd>
By default, this will appear in monospace font.
          </kbd> 
</body>
</html>

Code, <samp> TAG

The same tag displays output programs from a computer.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Computer code</title>
</head>
<body>
  <p>Error message: </p>
<p> <samp> File not found. </samp></p>
</body>
</html>

HTML Tags For Computer Code, <var> TAG

Var represents variables. A variable could be used to express a mathematical function or a programming context.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Computer code</title>
</head>
<body>
<p>The area of a triangle is: 1/2 x <var>b</var> x <var>h</var>, where <var>b</var> is the base, and <var>h</var> is the vertical height.</p>
   </body>
</html>

HTML Tags for computer

Pre represents preformatted text. It displays text in a fixed width.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Computer code</title>
</head>
<body>
   <pre>
       This       is     a  sentence with   lots of     space and it's     fixed.
   </pre>
</body>
</html>