HTML Computer Code
HTML (Hypertext Markup Language) is not itself a programming language but
rather a markup language used for creating the structure and content of
web pages. It consists of a series of elements, that define the different
parts of a webpage.
The computer uses a special text style and formatting to show the
code-related messages. The computer code is shown on the webpage using the
tag. The <code> tag is used to display the computer code on the
website.
Sometimes, as programmers, we have to show the user the output result,
error message, or coding portion on a webpage. You can write codes to
appear on your webpage with the aid of these tags.
What Coding Is Used?
Coding generates a collection of instructions that computers may use.
These instructions can specify the actions of a computer can and cannot
perform. Coding enables programmers to create programmers like websites
and apps.
List Of Some Tags Which Are Used In HTML Computer Code Tasks
Those tags are commonly used in HTML for formatting and displaying
various types of computer code are:
- <code>
- <kbd>
- <samp>
- <var>
- <pre>
HTML <code> Element:
<code>: This tag is used to represent a piece of computer
code within text. It's typically used for inline code snippets.
Syntax:
<code>Type some contents...</code>
Example:
<!DOCTYPE html>
<html>
<body>
<pre>
<code>
#include<stdio.h>
int
main() {
printf("HTML Computercode");
}
</code>
</pre>
</body>
</html>
Output:
HTML <kbd> Element:
<kbd>: This tag is used to indicate keyboard input. It's
often used to display keystrokes or keyboard commands.
Syntax:
<kbd>Type some contents...</kbd>
Example:
<!DOCTYPE
html>
<html>
<head>
<title>kbd tag</title>
<style>
body {
text-align: center;
}
</style>
</head>
<body>
<div
class="gfg">Gocourse</div>
<kbd>HTML</kbd>
<kbd>CSS</kbd>
<kbd>JavaScript</kbd>
</body>
</html>
Output:
HTML <samp> Element:
<samp>: This tag is used to represent sample output or
example text. It's typically used to display the output of computer
programs or scripts.
Syntax:
<samp>Type some contents...</samp>
Example:
<!DOCTYPE
html>
<html>
<head>
<title>samp tag</title>
</head>
<style>
body {
text-align:
center;
}
.gfg {
font-size: 50px;
font-weight:
bold;
color: green;
}
.samp {
font-size: 25px;
font-weight: bold;
}
</style>
<body>
<div class="gfg">Gocourse</div>
<div
class="samp"><samp> Tag</div>
<samp>A computer science portal for Geeks</samp>
</body>
</html>
Output:
HTML <var> Element:
<var>: This tag is used to represent variables in computer
code. It's typically used to highlight variable names within code
snippets.
Syntax:
<var> Type some contents...</var>
Example:
<!DOCTYPE
html>
<html>
<head>
<title>var tag</title>
</head>
<style>
body
{
text-align:
center;
}
.gfg {
font-size: 50px;
font-weight: bold;
color: rgb(38, 146, 235);
}
.var {
font-size: 30px;
font-weight: bold;
}
</style>
<body>
<div
class="gfg">Gocourse</div>
<div class="var"><var> Tag</div>
<var>Gocourse Variable</var>
</body>
</html>
Output:
HTML <pre> Element:
<pre>: This tag is used to define preformatted text, which
preserves both spaces and line breaks. It's commonly used for displaying
code blocks or other types of text where whitespace and line breaks are
significant.
Syntax:
<pre> Type some contents...</pre>
Example:
<!DOCTYPE
html>
<html>
<head>
<title>pre tag</title>
</head>
<body>
<pre>
Pre Tag
It's displaying code blocks or where whitespace and line breaks
are significant.
</pre>
</body>
</html>
Output:
More topic in HTML