The following describes the most basic tags needed for a legal HTML5 document. All of
the tags will work in pre-HTML5 browsers, even very old browsers. Click on
the "details" link for an explanation of each element. Please send corrections and suggested improvements to
hall@coreservlets.com.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<link href="css/some-stylesheet.css"
rel="stylesheet"/>
<script src="scripts/some-script.js">
</script>
</head>
<body>
...
</body>
</html>
|
Required (details)
Required (details)
Required
Treat as required (details)
Optional (details)
Optional (details)
Required
Many new elements (details)
|
The DOCTYPE line is required, and must be the first
line in the document. This simple DOCTYPE will invoke
Standards Mode in all major browsers, even old ones
that were around long before HTML5. Omitting the DOCTYPE or
having anything before it (even a blank line!) will result
in Quirks Mode in many browsers.
More info:
The root element of your document must be "html". Since there is no official language default in HTML5, you should
always specify a language explicitly. This works in all major browsers, including old, pre-HTML5 versions.
More info:
Although it is not technically required to define the character set,
failing to do so can open your app to cross-site scripting attacks in older IE versions. Note that
even old browsers will treat
<meta charset="utf-8"/>
identically to
<meta http-equiv="Content-Type"
content="text/html; charset=utf-8">
More info:
The "type" attribute is not needed in HTML5, and even old browsers will use text/css as the default type for style sheets.
So, either way, you can omit the "type" attribute altogether and use
<link href="file.css" rel="stylesheet"/>
instead of
<link href="file.css" rel="stylesheet"
type="text/css"/>
More info:
The "type" attribute is not needed in HTML5, and even old browsers will use text/javascript as the default type for scripts.
So, either way, you can omit the "type" attribute altogether and use
<script src="file.js"></script>
instead of
<script src="file.js" type="text/javascript"></script>
However, you must use a separate </script> tag:
Internet Explorer will not honor <script .../>.
More info:
HTML5 defines many new elements. The elements that are easiest to use (with easy fallback for non-HTML5-browsers)
are the new input elements.
More info: