Course Content
HTML Introduction
0/1
HTML Editors
0/1
HTML Basic Tags
0/1
HTML Elements
0/1
HTML Attributes
0/1
HTML Headings
0/1
HTML Paragraph
0/1
HTML Text Formatting
0/1
HTML Meta Tags
0/1
HTML Quotations
0/1
HTML Comments
0/1
HTML Images
0/1
HTML Background
0/1
HTML Colors
0/1
HTML Lists
0/1
HTML Tables
0/1
HTML Forms
0/1
HTML Spell Check
0/1
HTML Media
0/1
HTML Marquees
0/1
HTML CSS
0/1
HTML Links
0/1
HTML Block & Inline
0/1
HTML Classes
0/1
HTML Id
0/1
HTML I frames
0/1
HTML Java script
0/1
HTML File paths
0/1
HTML Layout
0/1
HTML Responsive
0/1
HTML Computer Code
0/1
HTML Tutorial
About Lesson

HTML Computer Code

In this tutorial, we will learn to write programming code in HTML with the help of examples.


Computer Code

HTML provides different types of elements to display programming examples on the websites.
HTML contains different tags for defining user input and computer code.

 

List of some tags which are used in HTML for computer code :

  • <code> Tag
  • <kbd> Tag
  • <samp> Tag
  • <var> Tag
  • <pre> Tag

<code> Element

The HTML <code> tag is used to define a piece of computer code on the web page. The text written inside the <code> element will be displayed in the browser’s default monospace font.

Note : The <code> tag does not preserve extra whitespace and line-breaks, to solve this problem we use <code> element inside the <pre> element.

Example :

<!DOCTYPE html>
<html>
  <head>
    <title>Computer Code</title>
  </head>
  <body>
    <h2>HTML Element</h2>
    <p>This is computer Programming Code.</p>
    <code>
      x = 4;<br>
      y = 8;<br>
      z = x + y;
    </code>
  </body>
</html>

Output

HTML Element

This is computer Programming Code.

x = 4;
y = 8;
z = x + y;

<kbd> Element

The HTML <kbd> element is used to define the Keyboard input on the web page.
The text written inside the <kbd> element will be represents the browser’s default monospace font.

Example :

<!DOCTYPE html>
<html>
  <head>
    <title>Computer Code</title>
  </head>
  <body>
    <kbd>The text written inside the kbd element looks like.</kbd>
  </body>
</html>

Output

The text written inside the kbd element looks like.


<samp> Element

The HTML <samp> element is used to define an output from a computer program.
The text written inside the <samp> element will be displayed in the browser’s default monospace font.

Example :

<!DOCTYPE html>
<html>
  <head>
    <title>Computer Code</title>
  </head>
  <body>
    <h2>HTML Element</h2>
    <samp>The text written inside the samp element look like.</samp>
  </body>
</html>

Output

HTML Element

The text written inside the samp element look like.

<var> Element

The HTML <var> element is used to define a variable in a programming language or a mathematical expression.
The text written inside the <var> tag is typically displayed in italic style.

Example :

<!DOCTYPE html>
<html>
  <head>
    <title>Computer Code</title>
  </head>
  <body>
    <h2>HTML Element</h2>
    <var>The text written inside the var element looks like.</var>
  </body>
</html>

Output

HTML Element

The text written inside the var element looks like.

<pre> Element

HTML <pre> tag defines preformatted text.
The <pre> tag display text as written in HTML document.
The <pre> tag break all the limitations (like-spaces, line break, etc) of the paragraph tag.
It displays text within a fixed width-height and preserves the extra lines and whitespaces.

Example :

<!DOCTYPE html>
<html>
  <head>
    <title>Computer Code</title>
  </head>
  <body>
    <pre>This is
First
paragraph.</pre>
    <pre>This is Second paragraph.</pre>
  </body>
</html>

Output

This is
First
paragraph.

This is Second paragraph.

error: Content is protected !!