articles » current » html » tutorial » page-6

Hyper-text Markup Language: Tutorial

A tutorial of HTML5 - Page 6 - How Important are the New HTML5 Tags?, Special HTML5 Tag: CANVAS, .

How Important Are These New Tags

There is no real reason to use new elements like <footer>, <header>, <main>, <article>, <summary>, <section>, <aside>, <nav> and <figure>. It does not make web pages show any better to Google's search engines. It is okay to continue to use the <div> tag and not have any problems with the search engines.

Here is the previous example document using some new HTML5 tags. It does appear to be cleaner than using id and class attributes on <div> tags:

<!DOCTYPE html>
<html lang="en">
		<meta charset="utf-8" />
		<title>Hello, World</title>
			<img alt="company logo" width=200 height=50 src="companylogo.gif" />
				<h1>Document Headline</h1>
				<p><cite>Hello, World!!!</cite></p>
				<p>This is inline <code>programming code</code>.
					This is a <a href="">link to Google</a>.
	this is a block of programming code
	int x = 3 + 2 * 4; <span style="color:green;">// comment</span></pre>
					<li>bullet 1</li>
					<li>bullet 2</li>
					<li>bullet 3</li>
					this is a block quote
			<small>Copyright 2007 (this is small text)</small>

Special HTML5 Tag: CANVAS

The <canvas> tag is the only one that requires the use of JavaScript. Here is a basic paint program example using the new <canvas> tag and some CSS.

<!DOCTYPE html>
<title>Drawing with the Canvas</title>
<style type="text/css">
	body {
		background-color: #fff;
	.selected {
		margin: 5px;
		float: left;
		border: 3px solid #888;
	.notselected {
		margin: 5px;
		float: left;
		cursor: pointer;
		border: 3px solid #fff;
	.paintChoices {
		float: left;
		border: 1px solid #aaa;
		width: 200px;
		clear: both;
	#paintCanvas {
		border: 1px solid black;
		clear: both;
		float: left;
	#imgCanvas {
		border: 1px solid black;
		clear: both;
		float: left;
<script type="text/javascript">
	var canvas;
	var context;
	var drawing = false;
	var prevColorElement;
	var prevThicknessElement;
	function changeColor(color, element) {
		if (prevColorElement != element) {
			context.strokeStyle = color;
			element.className = "selected";
			if (prevColorElement != null) {
				prevColorElement.className = "notselected";
			prevColorElement = element;
	function changeThickness(thickness, element) {
		if (prevThicknessElement != element) {
			context.lineWidth = thickness;
			element.className = "selected";
			if (prevThicknessElement != null) {
				prevThicknessElement.className = "notselected";
			prevThicknessElement = element;
	function start(e) {
		drawing = true;
		var x = e.pageX - canvas.offsetLeft;
		var y = e.pageY - canvas.offsetTop;
		context.moveTo(x, y);
	function stop() {
		drawing = false;
		document.getElementById("imgCanvas").src = canvas.toDataURL();
	function draw(e) {
		if (drawing == true) {
			var x = e.pageX - canvas.offsetLeft;
			var y = e.pageY - canvas.offsetTop;
			context.lineTo(x, y);
	window.onload = function () {
		canvas = document.getElementById("paintCanvas");
		context = canvas.getContext("2d");
		canvas.onmousedown = start;
		canvas.onmouseup = stop;
		canvas.onmouseout = stop;
		canvas.onmousemove = draw;
	<div class="paintChoices">DRAWING COLOR<br />
		<div class="notselected" onclick="changeColor('rgb(255,0,0)', this);"
		<div class="notselected" onclick="changeColor('rgb(0,224,0)', this);"
		<div class="notselected" onclick="changeColor('rgb(0,0,255)', this);"
		<div class="notselected" onclick="changeColor('rgb(0,0,0)', this);"
	<div class="paintChoices">BRUSH THICKNESS<br />
		<div class="notselected" onclick="changeThickness(3, this);"
		<div class="notselected" onclick="changeThickness(6, this);"
		<div class="notselected" onclick="changeThickness(12, this);"
	<canvas id="paintCanvas" width="600" height="400">
		The canvas is not supported by your browser.
	<p style="float:left;clear:both;">Right click this image to save it to your computer:</p>
	<img id="imgCanvas" src="" width="600" height="400" />
<<<[Page 6 of 8]>>>

This site uses cookies. Cookies are simple text files stored on the user's computer. They are used for adding features and security to this site. Read the privacy policy.