Skip to content
  • About
  • Computer Languages
  • Design & Illustration
  • Donate
  • Downloads
  • My Documents
  • Office
  • References
  • School Management System
  • Technology Basics
  • Utilities
  • Welcome to the official site of DW Faisalabad
Search for:
DW Faisalabad

DW Faisalabad

Skip to content
  • Languages
    • CSS
    • HTML
    • JavaScript
  • Office
    • Adobe Acrobat
    • Microsoft Office 2016
    • SPSS
    • Shortcut Keys
  • Design & Illustration
    • Adobe Illustrator
    • Adobe Photoshop
    • CorelDRAW
  • Technology
    • Computer
    • Microsoft Windows
    • Online Safety
  • School Management System
  • Utilities
  • Blog
  • YouTube
09 OCT

HTML5 Migration

Migration from HTML4 to HTML5

This chapter is entirely about how to migrate from HTML4 to HTML5.

This chapter demonstrates how to convert an HTML4 page into an HTML5 page, without destroying anything of the original content or structure.

You can migrate from XHTML to HTML5, using the same recipe.

 

Typical HTML4 Typical HTML5
<div id=”header”> <header>
<div id=”menu”> <nav>
<div id=”content”> <section>
<div class=”article”> <article>
<div id=”footer”> <footer>

A Typical HTML4 Page

Example

<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN” “http://www.w3.org/TR/html4/loose.dtd”>
<html lang=”en”>
<head>
<meta http-equiv=”Content-Type” content=”text/html;charset=utf-8″>
<title>HTML4</title>
<style>
body {
font-family: Verdana,sans-serif;
font-size: 0.9em;
}div#header, div#footer {
padding: 10px;
color: white;
background-color: black;
}div#content {
margin: 5px;
padding: 10px;
background-color: lightgrey;
}

div.article {
margin: 5px;
padding: 10px;
background-color: white;
}

div#menu ul {
padding: 0;
}

div#menu ul li {
display: inline;
margin: 5px;
}
</style>
</head>
<body>

<div id=”header”>
<h1>Monday Times</h1>
</div>

<div id=”menu”>
<ul>
<li>News</li>
<li>Sports</li>
<li>Weather</li>
</ul>
</div>

<div id=”content”>
<h2>News Section</h2>
<div class=”article”>
<h2>News Article</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque in porta lorem. Morbi condimentum est nibh, et consectetur tortor feugiat at.</p>
</div>
<div class=”article”>
<h2>News Article</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque in porta lorem. Morbi condimentum est nibh, et consectetur tortor feugiat at.</p>
</div>
</div>

<div id=”footer”>
<p>&amp;copy; 2016 Monday Times. All rights reserved.</p>
</div>

</body>
</html>

Try it Yourself »


Change to HTML5 Doctype

Change the doctype:

<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN” “http://www.w3.org/TR/html4/loose.dtd”>

to the HTML5 doctype:

Example

<!DOCTYPE html>

Try it Yourself »


Change to HTML5 Encoding

Change the encoding information:

<meta http-equiv=”Content-Type” content=”text/html;charset=utf-8″>

to HTML5 encoding:

Example

<meta charset=”utf-8″>

Try it Yourself »


Add The HTML5Shiv

The new HTML5 semantic elements are supported in all modern browsers. In addition, you can “teach” older browsers how to handle “unknown elements”.

However, IE8 and earlier, does not allow styling of unknown elements. So, the HTML5Shiv is a JavaScript workaround to enable styling of HTML5 elements in versions of Internet Explorer prior to version 9.

Add the HTML5Shiv:

Example

<!–[if lt IE 9]>
<script src=”https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js”></script>
<![endif]–>

Try it Yourself »

Read more about the HTML5Shiv in HTML5 Browser Support.


Change to HTML5 Semantic Elements

The existing CSS contains id’s and classes for styling the elements:

body {
font-family: Verdana,sans-serif;
font-size: 0.9em;
}div#header, div#footer {
padding: 10px;
color: white;
background-color: black;
}div#content {
margin: 5px;
padding: 10px;
background-color: lightgrey;
}

div.article {
margin: 5px;
padding: 10px;
background-color: white;
}

div#menu ul {
padding: 0;
}

div#menu ul li {
display: inline;
margin: 5px;
}

Replace with equal CSS styles for HTML5 semantic elements:

body {
font-family: Verdana,sans-serif;
font-size: 0.9em;
}header, footer {
padding: 10px;
color: white;
background-color: black;
}section {
margin: 5px;
padding: 10px;
background-color: lightgrey;
}

article {
margin: 5px;
padding: 10px;
background-color: white;
}

nav ul {
padding: 0;
}

nav ul li {
display: inline;
margin: 5px;
}

Finally, change the elements to HTML5 semantic elements:

Example

<body>

<header>
<h1>Monday Times</h1>
</header>

<nav>
<ul>
<li>News</li>
<li>Sports</li>
<li>Weather</li>
</ul>
</nav>

<section>
<h2>News Section</h2>
<article>
<h2>News Article</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque in porta lorem. Morbi condimentum est nibh, et consectetur tortor feugiat at.</p>
</article>
<article>
<h2>News Article</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque in porta lorem. Morbi condimentum est nibh, et consectetur tortor feugiat at.</p>
</article>
</section>

<footer>
<p>&copy; 2014 Monday Times. All rights reserved.</p>
</footer>

</body>

Try it Yourself »


The Difference Between <article> <section> and <div>

There is a confusing (lack of) difference in the HTML5 standard, between <article> <section> and <div>.

In the HTML5 standard, the <section> element is defined as a block of related elements.

The <article> element is defined as a complete, self-contained block of related elements.

The <div> element is defined as a block of children elements.

How to interpret that?

In the example above, we have used <section> as a container for related <articles>.

But, we could have used <article> as a container for articles as well.

Here are some different examples:

<article> in <article>:

<article>

<h2>Famous Cities</h2>

<article>
<h2>London</h2>
<p>London is the capital city of England. It is the most populous city in the United Kingdom,
with a metropolitan area of over 13 million inhabitants.</p>
</article>

<article>
<h2>Paris</h2>
<p>Paris is the capital and most populous city of France.</p>
</article>

<article>
<h2>Tokyo</h2>
<p>Tokyo is the capital of Japan, the center of the Greater Tokyo Area,
and the most populous metropolitan area in the world.</p>
</article>

</article>

Try it Yourself »

<div> in <article>:

<article>

<h2>Famous Cities</h2>

<div class=”city”>
<h2>London</h2>
<p>London is the capital city of England. It is the most populous city in the United Kingdom,
with a metropolitan area of over 13 million inhabitants.</p>
</div>

<div class=”city”>
<h2>Paris</h2>
<p>Paris is the capital and most populous city of France.</p>
</div>

<div class=”city”>
<h2>Tokyo</h2>
<p>Tokyo is the capital of Japan, the center of the Greater Tokyo Area,
and the most populous metropolitan area in the world.</p>
</div>

</article>

Try it Yourself »

<div> in <section> in <article>:

<article>

<section>
<h2>Famous Cities</h2>

<div class=”city”>
<h2>London</h2>
<p>London is the capital city of England. It is the most populous city in the United Kingdom,
with a metropolitan area of over 13 million inhabitants.</p>
</div>

<div class=”city”>
<h2>Paris</h2>
<p>Paris is the capital and most populous city of France.</p>
</div>

<div class=”city”>
<h2>Tokyo</h2>
<p>Tokyo is the capital of Japan, the center of the Greater Tokyo Area,
and the most populous metropolitan area in the world.</p>
</div>
</section>

<section>
<h2>Famous Countries</h2>

<div class=”country”>
<h2>England</h2>
<p>London is the capital city of England. It is the most populous city in the United Kingdom,
with a metropolitan area of over 13 million inhabitants.</p>
</div>

<div class=”country”>
<h2>France</h2>
<p>Paris is the capital and most populous city of France.</p>
</div>

<div class=”country”>
<h2>Japan</h2>
<p>Tokyo is the capital of Japan, the center of the Greater Tokyo Area,
and the most populous metropolitan area in the world.</p>
</div>
</section>

</article>

Try it Yourself »

Categories: HTML5 / by Zahid Farid 9 October 2018

Post Author: Zahid Farid

Related Posts '

09 OCT

HTML5 Semantic Elements

Semantics is the study of the meanings of words and phrases in a language. Semantic elements = elements with a meaning. What are...

HTML5 Read More
09 OCT

HTML5 New Elements

New Elements in HTML5 Below is a list of the new HTML5 elements, and a description of what they are used for. New...

HTML5 Read More
09 OCT

HTML5 Browser Support

You can teach older browsers to handle HTML5 correctly. HTML5 Browser Support HTML5 is supported in all modern browsers. In...

HTML5 Read More
09 OCT

HTML5 Introduction

What is New in HTML5? The DOCTYPE declaration for HTML5 is very simple: <!DOCTYPE html> The character encoding (charset)...

HTML5 Read More
24 JUN

HTML5 Style

Style Guide and Coding Conventions HTML Coding Conventions Web developers are often uncertain about the coding style and syntax to use in...

HTML5 Read More
Search for:

Related Posts

  • HTML5 Semantic Elements
  • HTML5 New Elements
  • HTML5 Migration
  • HTML5 Browser Support
  • HTML5 Introduction
Go to mobile version