BBM Tutor
BBM Tutor

HTML5 Tag - <code>

Definition & Uses of HTML5 <code>

The HTML5 <code> tag is not newly introduced tag and not redefined. It is same as its prior versions.

Syntax of HTML5 <code> Tag

<code>code to be mark up</code>

What is HTML5 <code> ?

  • The <code> tag is one of the phrase tag.
  • The code tag defines a piece of computer code.
  • The code tag surrounds the programming code being marked up.
  • The code being marked up could represent an XML element name, a filename, a computer program, or any other string that a computer would recognize.
  • Text surrounded by <code> tags displayed in a monospaced font (also called a fixed-width or non-proportional font) such as Courier Font
  • It should be closed with proper </code> end tag

Where to use HTML5 <code> Tag?

  • It can be useful to show functions, programming code or variables.

Tips & Notes

  • Content of the <code> tag would represented in a fixed-width font, such as Courier, but this style can be overridden using CSS.
  • Multiple lines of programming code can be marked up by surrounding the <code> tags with <pre> tags.

Simple HTML5 Example #1

<!DOCTYPE HTML>
<html>
<head>
<title> HTML5 <code> - HTML5 Tags Tutor </title>
</head>
<body>
<article>
<p>
Canvas Element in HTML5
The <canvas> tag is used to draw graphics, on the fly, via scripting (usually JavaScript).
The below javascript function would draws rectangle inside the canvas element.
<pre><code>

				  
function draw()
{
	var canvas = document.getElementById("mycanvas");
	if( canvas.getContext ) 
	{
		var context = document.canvas.getContext("2d");
		context.fillStyle = "rgb(150,50,110)";
		context.fillRect(5,5,91,91);
	}
	else 
	{
		// put code for browsers that don't support canvas here
	}
}
						
</code></pre>
</p>
</article>
</body>
</html>

Output Screen

Canvas Element in HTML5
The <canvas> tag is used to draw graphics, on the fly, via scripting (usually JavaScript).
The below javascript function would draws rectangle inside the canvas element.

  
function draw()
{
	var canvas = document.getElementById("mycanvas");
	if( canvas.getContext ) 
	{
		var context = document.canvas.getContext("2d");
		context.fillStyle = "rgb(150,50,110)";
		context.fillRect(5,5,91,91);
	}
	else 
	{
		// put code for browsers that don't support canvas here
	}
}
					

Attributes

  • Attributes are the features added to a tag to provide the browser with more information about how the tag should appear or behave.
  • There are 3 type attributes a tag can have. They are Global Attributes, Event Attributes and Element-Specific Attributes.
  • The <code> tag is also capable of supporting the Global Attributes and Event Attributes in HTML5.

Element-Specific Attributes

Attributes

Description

BBM Invoice
 
Disclaimer: Use of this website signifies your agreement to the Terms of Use and Online Privacy Policy.