Creating DOCTYPE in HTML5

Leave a Comment

Because there are several versions of HTML, a browser requires a DOCTYPE type to tell it what version is in use and how to render it properly.

In this solution, you will learn to form a DOCTYPE for HTML5 properly.

In a traditional HTML or XHTML document, the DOCTYPE tag might look as follows:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

There are many variations of the DOCTYPE. HTML5 simplifies the DOCTYPE to:
<!DOCTYPE html>

How to build it

Open the HTML or text editor of your choice. For the examples shown in this chapter, we use Dreamweaver CS5. Do not use a word processor because that could embed extra characters not recognized by HTML.

If necessary, start a new HTML document and give it the name and location of your choice. If you use an HTML editor like Dreamweaver, you might get code that looks as follows:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
</head>
<body>
</body>
</html>
If your code looks a little different from the above, do not worry about that for now.

Change the DOCTYPE tag as : <!DOCTYPE html>

Do not leave any spaces before the DOCTYPE tag. A space could cause errors in browser rendering of the HTML5 code.

0 comments:

Post a Comment