HTML: <!DOCTYPE> tag
This HTML article explains to you how to use an HTML element called the <!DOCTYPE> tag with proper syntax and examples.
Description
The HTML <!DOCTYPE> tag is the starting line in the HTML code. <!DOCTYPE> tag tells the browsers what version of HTML the script is written and what to expect from this HTML code. This <!DOCTYPE> tag is also commonly referred to as the <!DOCTYPE> element.
Syntax of <!DOCTYPE>
The syntax for the <!DOCTYPE> tag changes between on the version of XHTML or HTML you are using. Now check out the most common usages of <!DOCTYPE>
The syntax in HTML5 is:
<!doctype html>
The syntax in HTML 4.01 is:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
The syntax in XHTML 1.0 is:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
The syntax in XHTML 1.0 is:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
The syntax in XHTML 1.1 is:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
Tips and Notes
Tip: The <!DOCTYPE>
declaration is NOT case sensitive.
Browser Compatibility of <!DOCTYPE>
The <!DOCTYPE> tag has basic support with all these following browsers:
- Chrome
- Android
- Firefox (Gecko)
- Firefox Mobile (Gecko)
- Internet Explorer (IE)
- Edge Mobile
- Opera
- Opera Mobile
- Safari (WebKit)
- Safari Mobile
Example of <!DOCTYPE> Declaration
In the examples below we will discuss all the examples how to use HTML tags in HTML5, HTML 4.01 Transitional, , XHTML 1.1, XHTML 1.0 Transitional and XHTML 1.0 Strict.
HTML 4.01 Transitional Document
HTML 4.01 Transitional document, the <!DOCTYPE> tag code might looks like this as shown below:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>HTML 4.01 Transitional Example by www.home4cloud.com</title>
</head>
<body>
<h1>Biggest Heading comes under this tag</h1>
<p>This line is written inside the paragraph tag.</p>
</body>
</html>
In this above HTML 4.01 Transitional document, the <!DOCTYPE> tag code is on the first line which is not inside <html> tag.
XHTML 1.0 Transitional Document
XHTML 1.0 Transitional document, the <!DOCTYPE> tag code might looks like this as shown below:
<!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>XHTML 1.0 Transitional Example in www.home4cloud.com</title>
</head>
<body>
<h1>Biggest Heading comes under this tag</h1>
<p>This line is written inside the paragraph tag.</p>
</body>
</html>
In this above XHTML 1.0 Transitional document, the <!DOCTYPE> tag code is on the first line which is not inside <html> tag.
XHTML 1.0 Strict Document
XHTML 1.0 Strict document, the <!DOCTYPE> tag code might looks like this as shown below:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>XHTML 1.0 Strict Example in www.home4cloud.com</title>
</head>
<body>
<h1>Biggest Heading comes under this tag</h1>
<p>This line is written inside the paragraph tag.</p>
</body> </html>
In this above XHTML 1.0 Strict document, the <!DOCTYPE> tag code is on the first line which is not inside <html> tag.
XHTML 1.1 Document
XHTML 1.1 document, the <!DOCTYPE> tag code might looks like this as shown below:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>XHTML 1.1 Example in www.home4cloud.com</title>
</head>
<body>
<h1>Biggest Heading comes under this tag</h1>
<p>This line is written inside the paragraph tag.</p>
</body>
</html>
In this above XHTML 1.1 document, the <!DOCTYPE> tag code is on the first line which is not inside <html> tag.