HTML or Hyper Text Markup Language is a web development programming language that uses tag for defining, declaring, and performing operations on any web page element. Tags are defined using the symbols < and >, and a closing tag should have ‘/’ in front of it. A code tag is a type of tag that allows the programmer to write their chunk of code in between, like …….
, as every tag in HTML must have a close tag.
Syntax with Explanation:
The basic syntax is shown below, where the element comes with a pair and the fragments of code are written between these tags. Tag omission is not performed here as both the starting and closing tag is mandatory by default.
<pre class="brush:php;toolbar:false"> <code> …. …. </code>
By default, the content of the tag font is displayed using monospace, which means all the characters in a given content of the same width. It is specified in both HTML 5 and HTML4 standards.
HTML uses various text sizes and more properties with fonts and indent. There comes a scenario where it is necessary to display some content in the browser with both text and code of snippets, and then we shall make use of this tag. The code tag is paired together with the preformatted tag
, which preserves the exact format of the text written in the source document.</p>
<p>To begin the text in the exact same line, this tag has been used, which literally removes the white space. To represent the code in a font style, it is preferred to use a code selector in the CSS style and to give a visual weight. To pick a font, it is beautiful to have CSS with already been set font-family to monospace. Coming to browser compatibility, it is supported in chrome, edge, opera, safari, Firefox. Even this element supports both the event and global attributes. Code tags make use of class attribute for a predefined language and also <id>, <style>, <title>.</p>
<p>This code tag makes use of some elements while implementation.</p>
<ul>
<li>
<strong><Code>:</strong> Defines code fragment</li>
<li>
<strong><var>:</strong> Explains variables</li>
<li>
<strong><samp></strong>: Throws computer Output</li>
<li>
<strong><kbd></strong>: Helps to display keyboard input</li>
</ul>
<h3>Examples to Implement HTML Code Tag</h3>
<p>Here is an example with different styles on the code tag.</p>
<h4>Example #1</h4>
<p>Here the first example program is to display the code, which forms a basic inline concept.</p>
<p><strong>Code:</strong></p>
<div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:php;toolbar:false"><!DOCTYPE html>
<html>
<body>
<em># Display the sum</em><br>
<strong>program adds two numbers</strong><br>
<pre class="brush:php;toolbar:false">
<code>
nu1 = 2.5
nu2 = 5.3
sum = float(nu1) + float(nu2)
print('The sum of two num {0} and {1} is {2}'.format(nu1, nu2, sum))</code>
output from a program
input
Variable declaration