Table of Contents
Getting Started
What Is HTML5?Rather than being simply an extension of the HTML4 markup language, HTML5 is a collection of technologies that have been brought under a single umbrella name. There are manynew HTML tags (and many tags have also been removed), but at the same time, two new markup languages have been added to HTML: Math Markup Language and Scalable VectorGraphics; in addition, JavaScript has been extended with a raft of new functions and attributes, and there are powerful new audio, video, and graphical features.
NOTE: This guide assumes that you have a general understandingof how web servers and browsers work, arealready familiar with and comfortable using HTML4, andare able to program using basic JavaScript. This guide usessingle quotes for attribute values; double quotes are used forstrings, such as questions and commands.
The Major Web BrowsersHTML5 is new and is being implemented a part at a time bythe different browser manufacturers. In this guide, the majorbrowsers are listed alongside every feature according to thefollowing key. If a particular browser supports a feature, itskey letter will be shown in underlined boldface , butif it doesnt support that feature, its corresponding key letterwill be neither boldface nor underlined. If a browser key letteris simply underlined , then a feature is partially supportedby that browser. In all cases, it is assumed that you have thelatest version of a browser, but remember that all HTML5features should eventually reach full implementation acrossall major browsers, so it is recommended that you test anyfeatures you plan on using on the latest versions of all browsersyou are targeting. In February 2013, Opera announced it willuse the same WebKit engine as Safari and Chrome; therefore,its browser will become closely compatible with them both.
C | Chrome/Android (Google) |
F | Firefox (Mozilla) |
I | Internet Explorer/Windows Phone (Microsoft) |
O | Opera |
S | Safari/iOS (Apple) |
Creating an HTML5 Document
Declaring the Document TypeHTML5 uses this simple document type tag, which replaces all the varieties of previous HTML4 versions:.Many of the examples in this guide assume that this tag has been included at the start of the document, particularlywith Internet Explorer, which requires the tag to enable many HTML5 features.
Self-Closing TagsTo retain compatibility with XHTML documents, HTML5 supports the self-closing tag format by allowinga / character to be placed before the closing > of a tag, but it is not a requirement. This means that tags suchas
(which later became self-closing with
) can now be simply entered as
againbothformats are acceptable for compatibility with older browsers. However, if your web server serves pages using theapplication/xhtml+xml MIME type, you must use self-closing tags.If in doubt, use the self-closing tags youve learned and do not attempt to make any other tags self-closing,such as the following examples, which are all invalid and will not display in the way you may expect:
,, , and .
Choosing a Character SetTo specify a character set for an HTML5 document, use the following tag:
.You may replace
'UTF-8' with
'ISO-8859-1' or any other encoding of your choice (out of those listedat tinyurl.com/html5charsets), although not all sets are supported by all browsers.
An Example HTML5 Document
A very simple HTML5 document is likely to look like the following example, which includes the document type, the character set to use, a heading section, and the main body of the document:
EX:
Document Body
You do not need to specify the character set and language ifyou will be using plain ASCII with no accented characters. Infact, HTML5 allows you to omit the ,
, and sections and simply place tags where you like, but thisleads to code that may not be compatible with future versionsof HTML and is not recommended practice.
New Global HTML5 Elements
Over 20 new elements have been introduced into HTML5, and some of these elements do not render any differently in the browser because their objective is to provide machine-readableinformation to specialist browsers and search engines.
Self-contained content that is independentlydistributable or reusable (e.g., in syndication), such as a forum post, an article, a blog entry, etc.
[CFIOS]EX:
This is an article...
Section of a page consisting of content related tothat around the element but that could be considered separatefrom that content.
[CFIOS]EX:
This is an article...and this is an aside
Section containing audio material in a formatplayable by HTML5 without recourse to plug-ins, bymeans of the element. [CFIOS]EX:
Your browser doesn't support the audio tag.
Provides JavaScript with a bitmap canvas onwhich drawings can be made in real time.
[CFIOS]EX:
// Draw a filled square
canvas = document.getElementById('canv1')
context = canvas.getContext('2d')
context.fillStyle = '#445566'
context.fillRect(0, 0, 50, 50)
Used withinaelement, thistag defines a command theuser can invoke.
[CFIOS
]EX:
Help
Creates a clickable heading with thedefault title of Details; when clicked, the contents of theelement are toggled into and out of view; you mayreplace the default title with your own using theelement.
[C FIO
S]EX:
There are 36 species of wild catThe 36 species of the wild cat family arespread across most of the globe excluding thecontinents of Antarctica and Australia andsome island groups.
Allows embedding of external content andhas no matching closing tag; supported parameters are
quality,
src, and
type.
[CFIOS]EX:
src='flashgame.swf' quality='high'>
Used to contain illustrations, diagrams, andother figures, including an optionalelement for providing a caption.
[CFIOS