SlideShare a Scribd company logo
HTML5
9
HTML5 is the next major revision of the HTML standard superseding HTML 4.01, XHTML
1.0, and XHTML 1.1. HTML5 is a standard for structuring and presenting content on the
World Wide Web.
HTML5 is a cooperation between the World Wide Web Consortium (W3C) and the Web
Hypertext Application Technology Working Group (WHATWG).
The new standard incorporates features like video playback and drag-and-drop that have
been previously dependent on third-party browser plug-ins such as Adobe Flash, Microsoft
Silverlight, and Google Gears.
BrowserSupport
The latest versions of Apple Safari, Google Chrome, Mozilla Firefox, and Opera all support
many HTML5 features and Internet Explorer 9.0 will also have support for some HTML5
functionality.
The mobile web browsers that come pre-installed on iPhones, iPads, and Android phones
all have excellent support for HTML5.
NewFeatures
HTML5 introduces a number of new elements and attributes that can help you in building
modern websites. Here is a set of some of the most prominent features introduced in
HTML5.
 New Semantic Elements: These are like <header>, <footer>, and <section>.
 Forms 2.0: Improvements to HTML web forms where new attributes have been
introduced for <input> tag.
 Persistent Local Storage: To achieve without resorting to third-party plugins.
 WebSocket : A next-generation bidirectional communication technology for web
applications.
 Server-Sent Events: HTML5 introduces events which flow from web server to the
web browsers and they are called Server-Sent Events (SSE).
 Canvas: This supports a two-dimensional drawing surface that you can program
with JavaScript.
 Audio & Video: You can embed audio or video on your webpages without resorting
to third-party plugins.
 Geolocation: Now visitors can choose to share their physical location with your
web application.
1. HTML5 − Overview
HTML5
10
 Microdata: This lets you create your own vocabularies beyond HTML5 and extend
your web pages with custom semantics.
 Drag and drop: Drag and drop the items from one location to another location on
the same webpage.
BackwardCompatibility
HTML5 is designed, as much as possible, to be backward compatible with existing web
browsers. Its new features have been built on existing features and allow you to provide
fallback content for older browsers.
It is suggested to detect support for individual HTML5 features using a few lines of
JavaScript.
If you are not familiar with any previous version of HTML, I would recommend that you go
through our HTML Tutorial before exploring the features of HTML5.
HTML5
11
The HTML 5 language has a "custom" HTML syntax that is compatible with HTML 4 and
XHTML1 documents published on the Web, but is not compatible with the more esoteric
SGML features of HTML 4.
HTML 5 does not have the same syntax rules as XHTML where we needed lower case tag
names, quoting our attributes, an attribute had to have a value and to close all empty
elements.
HTML5 comes with a lot of flexibility and it supports the following features −
 Uppercase tag names.
 Quotes are optional for attributes.
 Attribute values are optional.
 Closing empty elements are optional.
TheDOCTYPE
DOCTYPEs in older versions of HTML were longer because the HTML language was SGML
based and therefore required a reference to a DTD.
HTML 5 authors would use simple syntax to specify DOCTYPE as follows:
<!DOCTYPE html>
The above syntax is case-insensitive.
CharacterEncoding
HTML 5 authors can use simple syntax to specify Character Encoding as follows −
<meta charset="UTF-8">
The above syntax is case-insensitive.
The<script>tag
It's common practice to add a type attribute with a value of "text/javascript" to script
elements as follows −
<script type="text/javascript" src="scriptfile.js"></script>
HTML 5 removes extra information required and you can use simply following syntax −
<script src="scriptfile.js"></script>
2. HTML5 − Syntax
HTML5
12
The<link>tag
So far you were writing <link> as follows −
<link rel="stylesheet" type="text/css" href="stylefile.css">
HTML 5 removes extra information required and you can simply use the following syntax
−
<link rel="stylesheet" href="stylefile.css">
HTML5Elements
HTML5 elements are marked up using start tags and end tags. Tags are delimited using
angle brackets with the tag name in between.
The difference between start tags and end tags is that the latter includes a slash before
the tag name.
Following is the example of an HTML5 element −
<p>...</p>
HTML5 tag names are case insensitive and may be written in all uppercase or mixed case,
although the most common convention is to stick with lowercase.
Most of the elements contain some content like <p>...</p> contains a paragraph. Some
elements, however, are forbidden from containing any content at all and these are known
as void elements. For example, br, hr, link, meta, etc.
Here is a complete list of HTML5 Elements.
HTML5Attributes
Elements may contain attributes that are used to set various properties of an element.
Some attributes are defined globally and can be used on any element, while others are
defined for specific elements only. All attributes have a name and a value and look like as
shown below in the example.
Following is the example of an HTML5 attribute which illustrates how to mark up a div
element with an attribute named class using a value of "example" −
<div class="example">...</div>
Attributes may only be specified within start tags and must never be used in end tags.
HTML5 attributes are case insensitive and may be written in all uppercase or mixed case,
although the most common convention is to stick with lowercase.
Here is a complete list of HTML5 Attributes.
HTML5
13
HTML5Document
The following tags have been introduced for better structure −
 section: This tag represents a generic document or application section. It can be
used together with h1-h6 to indicate the document structure.
 article: This tag represents an independent piece of content of a document, such
as a blog entry or newspaper article.
 aside: This tag represents a piece of content that is only slightly related to the rest
of the page.
 header: This tag represents the header of a section.
 footer: This tag represents a footer for a section and can contain information about
the author, copyright information, et cetera.
 nav: This tag represents a section of the document intended for navigation.
 dialog: This tag can be used to mark up a conversation.
 figure: This tag can be used to associate a caption together with some embedded
content, such as a graphic or video.
The markup for an HTML 5 document would look like the following −
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>...</title>
</head>
<body>
<header>...</header>
<nav>...</nav>
<article>
<section>
...
</section>
</article>
HTML5
14
<aside>...</aside>
<footer>...</footer>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>...</title>
</head>
<body>
<header role="banner">
<h1>HTML5 Document Structure Example</h1>
<p>This page should be tried in safari, chrome or Mozila.</p>
</header>
<nav>
<ul>
<li><a href="http://www.tutorialspoint.com/html">HTML
Tutorial</a></li>
<li><a href="http://www.tutorialspoint.com/css">CSS
Tutorial</a></li>
<li><a href="http://www.tutorialspoint.com/javascript">JavaScript
Tutorial</a></li>
</ul>
</nav>
<article>
<section>
<p>Once article can have multiple sections</p>
HTML5
15
</section>
</article>
<aside>
<p>This is aside part of the web page</p>
</aside>
<footer>
<p>Created by <a href="http://tutorialspoint.com/">Tutorials
Point</a></p>
</footer>
</body>
</html>
HTML5
16
As explained in the previous chapter, elements may contain attributes that are used to set
various properties of an element.
Some attributes are defined globally and can be used on any element, while others are
defined for specific elements only. All attributes have a name and a value and look like as
shown below in the example.
Following is the example of an HTML5 attributes which illustrates how to mark up a div
element with an attribute named class using a value of "example" −
<div class="example">...</div>
Attributes may only be specified within start tags and must never be used in end tags.
HTML5 attributes are case insensitive and may be written in all uppercase or mixed case,
although the most common convention is to stick with lowercase.
StandardAttributes
The attributes listed below are supported by almost all the HTML 5 tags.
Attribute Options Function
accesskey User Defined
Specifies a keyboard shortcut to access an
element.
align right, left, center Horizontally aligns tags
background URL
Places an background image behind an
element
bgcolor
numeric,
hexidecimal, RGB
values
Places a background color behind an element
class User Defined
Classifies an element for use with Cascading
Style Sheets.
contenteditable true, false
Specifies if the user can edit the element's
content or not.
contextmenu Menu id Specifies the context menu for an element.
data-XXXX User Defined
Custom attributes. Authors of a HTML
document can define their own attributes. Must
start with "data-".
draggable true,false, auto
Specifies whether or not a user is allowed to
drag an element.
3. HTML5 − Attributes
HTML5
17
height Numeric Value
Specifies the height of tables, images, or table
cells.
hidden hidden
Specifies whether element should be visible or
not.
id User Defined
Names an element for use with Cascading
Style Sheets.
item List of elements Used to group elements.
itemprop List of items Used to group items.
spellcheck true, false
Specifies if the element must have it's spelling
or grammar checked.
style CSS Style sheet Specifies an inline style for an element.
subject User define id Specifies the element's corresponding item.
tabindex Tab number Specifies the tab order of an element.
title User Defined "Pop-up" title for your elements.
valign top, middle, bottom Vertically aligns tags within an HTML element.
width Numeric Value
Specifies the width of tables, images, or table
cells.
For a complete list of HTML5 Tags and related attributes, please check our reference
to HTML5 Tags.
CustomAttributes
A new feature being introduced in HTML 5 is the addition of custom data attributes.
A custom data attribute starts with data- and would be named based on your requirement.
Here is a simple example –
<div class="example" data-subject="physics" data-level="complex">
...
</div>
The above code will be perfectly valid HTML5 with two custom attributes called data-
subject and data-level. You would be able to get the values of these attributes using
JavaScript APIs or CSS in similar way as you get for standard attributes.
HTML5
21
Web Forms 2.0 is an extension to the forms features found in HTML4. Form elements and
attributes in HTML5 provide a greater degree of semantic mark-up than HTML4 and free
us from a great deal of tedious scripting and styling that was required in HTML4.
The<input>elementinHTML4
HTML4 input elements use the type attribute to specify the data type.HTML4 provides
following types −
Type Description
text A free-form text field, nominally free of line breaks.
password
A free-form text field for sensitive information, nominally free of line
breaks.
checkbox A set of zero or more values from a predefined list.
radio An enumerated value.
submit A free form of button initiates form submission.
file An arbitrary file with a MIME type and optionally a file name.
image
A coordinate, relative to a particular image's size, with the extra semantic
that it must be the last value selected and initiates form submission.
hidden An arbitrary string that is not normally displayed to the user.
select An enumerated value, much like the radio type.
textarea A free-form text field, nominally with no line break restrictions.
button A free form of button which can initiates any event related to button.
Following is the simple example of using labels, radio buttons, and submit buttons −
...
<form action="http://example.com/cgiscript.pl" method="post">
<p>
<label for="firstname">first name: </label>
<input type="text" id="firstname"><br />
<label for="lastname">last name: </label>
5. HTML5 − Web Forms 2.0
HTML5
22
<input type="text" id="lastname"><br />
<label for="email">email: </label>
<input type="text" id="email"><br>
<input type="radio" name="sex" value="male"> Male<br>
<input type="radio" name="sex" value="female"> Female<br>
<input type="submit" value="send"> <input type="reset">
</p>
</form>
...
The<input>elementinHTML5
Apart from the above-mentioned attributes, HTML5 input elements introduced several new
values for the type attribute. These are listed below.
NOTE: Try all the following example using latest version of Opera browser.
Type Description
datetime
A date and time (year, month, day, hour, minute, second, fractions of a
second) encoded according to ISO 8601 with the time zone set to UTC.
datetime-
local
A date and time (year, month, day, hour, minute, second, fractions of a
second) encoded according to ISO 8601, with no time zone information.
date A date (year, month, day) encoded according to ISO 8601.
month A date consisting of a year and a month encoded according to ISO 8601.
week
A date consisting of a year and a week number encoded according to ISO
8601.
time
A time (hour, minute, seconds, fractional seconds) encoded according to
ISO 8601.
number
It accepts only numerical value. The step attribute specifies the precision,
defaulting to 1.
range
The range type is used for input fields that should contain a value from a
range of numbers.
email
It accepts only email value. This type is used for input fields that should
contain an e-mail address. If you try to submit a simple text, it forces to
enter only email address in email@example.com format.
url It accepts only URL value. This type is used for input fields that should
contain a URL address. If you try to submit a simple text, it forces to enter
HTML5
23
only URL address either in http://www.example.com format or in
http://example.com format.
HTML5-datetime
A date and time (year, month, day, hour, minute, second, fractions of a second) encoded
according to ISO 8601 with the time zone set to UTC.
Example
<!DOCTYPE HTML>
<html>
<body>
<form action = "/cgi-bin/html5.cgi" method = "get">
Date and Time : <input type = "datetime" name = "newinput" />
<input type = "submit" value = "submit" />
</form>
</body>
</html>
Output
HTML5
24
HTML5-datetimelocal
A date and time (year, month, day, hour, minute, second, fractions of a second) encoded
according to ISO 8601, with no time zone information.
Example
<!DOCTYPE HTML>
<html>
<body>
<form action = "/cgi-bin/html5.cgi" method = "get">
Local Date and Time : <input type = "datetime-local" name = "newinput" />
<input type = "submit" value = "submit" />
</form>
</body>
</html>
Output
HTML5–date
A date (year, month, day) encoded according to ISO 8601.
Example
<!DOCTYPE HTML>
<html>
<body>
<form action = "/cgi-bin/html5.cgi" method = "get">
HTML5
25
Date : <input type = "date" name = "newinput" />
<input type = "submit" value = "submit" />
</form>
</body>
</html>
Output
HTML5–month
A date consisting of a year and a month encoded according to ISO 8601.
Example
<!DOCTYPE HTML>
<html>
<body>
<form action = "/cgi-bin/html5.cgi" method = "get">
Month : <input type = "month" name = "newinput" />
<input type = "submit" value = "submit" />
</form>
</body>
</html>
HTML5
26
Output
HTML5-week
A date consisting of a year and a week number encoded according to ISO 8601.
Example
<!DOCTYPE HTML>
<html>
<body>
<form action = "/cgi-bin/html5.cgi" method = "get">
Week : <input type = "week" name = "newinput" />
<input type = "submit" value = "submit" />
</form>
</body>
</html>
Output
HTML5
27
HTML5–time
A time (hour, minute, seconds, fractional seconds) encoded according to ISO 8601.
Example
<!DOCTYPE HTML>
<html>
<body>
<form action = "/cgi-bin/html5.cgi" method = "get">
Time : <input type = "time" name = "newinput" />
<input type = "submit" value = "submit" />
</form>
</body>
</html>
Output
HTML5–number
It accepts only numerical value. The step attribute specifies the precision, defaulting to 1.
Example
<!DOCTYPE HTML>
<html>
<body>
<form action = "/cgi-bin/html5.cgi" method = "get">
HTML5
28
Select Number : <input type = "number" min = "0" max = "10" step "1"
value = "5" name = "newinput" />
<input type = "submit" value = "submit" />
</form>
</body>
</html>
Output
HTML5–range
The range type is used for input fields that should contain a value from a range of numbers.
Example
<!DOCTYPE HTML>
<html>
<body>
<form action = "/cgi-bin/html5.cgi" method = "get">
Select Range : <input type = "range" min = "0" max = "10" step "1"
value = "5" name = "newinput" />
<input type = "submit" value = "submit" />
</form>
</body>
</html>
HTML5
29
Output
HTML5-email
It accepts only email value. This type is used for input fields that should contain an e-mail
address. If you try to submit a simple text, it forces to enter only email address in
email@example.com format.
Example
<!DOCTYPE HTML>
<html>
<body>
<form action = "/cgi-bin/html5.cgi" method = "get">
Enter email : <input type = "email" name = "newinput" />
<input type = "submit" value = "submit" />
</form>
</body>
</html>
Output
HTML5
30
HTML5–URL
It accepts only URL value. This type is used for input fields that should contain a URL
address. If you try to submit a simple text, it forces to enter only URL address either
in http://www.example.com format or in http://example.com format.
Example
<!DOCTYPE HTML>
<html>
<body>
<form action = "/cgi-bin/html5.cgi" method = "get">
Enter URL : <input type = "url" name = "newinput" />
<input type = "submit" value = "submit" />
</form>
</body>
</html>
Output
The<output>element
HTML5 introduced a new element <output> which is used to represent the result of
different types of output, such as output written by a script.
You can use the for attribute to specify a relationship between the output element and
other elements in the document that affected the calculation (for example, as inputs or
parameters). The value of the for attribute is a space-separated list of IDs of other
elements.
<!DOCTYPE HTML>
HTML5
31
<html>
<script type="text/javascript">
function showResult()
{
x = document.forms["myform"]["newinput"].value;
document.forms["myform"]["result"].value=x;
}
</script>
<body>
<form action="/cgi-bin/html5.cgi" method="get" name="myform">
Enter a value : <input type="text" name="newinput" />
<input type="button" value="Result" onclick="showResult();" />
<output name="result"/>
</form>
</body>
</html>
It will produce the following result −
Theplaceholderattribute
HTML5 introduced a new attribute called placeholder. This attribute on <input> and
<textarea> elements provide a hint to the user of what can be entered in the field. The
placeholder text must not contain carriage returns or line-feeds.
HTML5
32
Here is the simple syntax for placeholder attribute −
<input type="text" name="search" placeholder="search the web"/>
This attribute is supported by latest versions of Mozilla, Safari and Crome browsers only.
<!DOCTYPE HTML>
<html>
<body>
<form action="/cgi-bin/html5.cgi" method="get">
Enter email : <input type="email" name="newinput"
placeholder="email@example.com"/>
<input type="submit" value="submit" />
</form>
</body>
</html>
This will produce the following result −
Theautofocusattribute
This is a simple one-step pattern, easily programmed in JavaScript at the time of document
load, automatically focus one particular form field.
HTML5 introduced a new attribute called autofocus which would be used as follows −
<input type="text" name="search" autofocus/>
This attribute is supported by latest versions of Mozilla, Safari and Chrome browsers only.
HTML5
33
<!DOCTYPE HTML>
<html>
<body>
<form action="/cgi-bin/html5.cgi" method="get">
Enter email : <input type="text" name="newinput" autofocus/>
<p>Try to submit using Submit button</p>
<input type="submit" value="submit" />
</form>
</body>
</html>
Therequiredattribute
Now you do not need to have JavaScript for client-side validations like empty text box
would never be submitted because HTML5 introduced a new attribute
called required which would be used as follows and would insist to have a value −
<input type="text" name="search" required/>
This attribute is supported by latest versions of Mozilla, Safari and Chrome browsers only.
<!DOCTYPE HTML>
<html>
<body>
<form action="/cgi-bin/html5.cgi" method="get">
Enter email : <input type="text" name="newinput" required/>
<p>Try to submit using Submit button</p>
<input type="submit" value="submit" />
</form>
</body>
</html>
It will produce the following result –
HTML5
34
HTML5
35
SVG stands for Scalable Vector Graphics and it is a language for describing 2D-graphics
and graphical applications in XML and the XML is then rendered by an SVG viewer.
SVG is mostly useful for vector type diagrams like Pie charts, Two-dimensional graphs in
an X,Y coordinate system etc.
SVG became a W3C Recommendation 14. January 2003 and you can check latest version
of SVG specification at SVG Specification.
ViewingSVGFiles
Most of the web browsers can display SVG just like they can display PNG, GIF, and JPG.
Internet Explorer users may have to install the Adobe SVG Viewer to be able to view
SVG in the browser.
EmbeddingSVGinHTML5
HTML5 allows embedding SVG directly using <svg>...</svg> tag which has following
simple syntax −
<svg xmlns="http://www.w3.org/2000/svg">
...
</svg>
Firefox 3.7 has also introduced a configuration option ("about:config") where you can
enable HTML5 using the following steps −
 Type about:config in your Firefox address bar.
 Click the "I'll be careful, I promise!" button on the warning message that appears
(and make sure you adhere to it!).
 Type html5.enable into the filter bar at the top of the page.
 Currently it would be disabled, so click it to toggle the value to true.
Now your Firefox HTML5 parser should be enabled and you should be able to experiment
with the following examples.
6. HTML5 − SVG
HTML5
36
HTML5−SVGCircle
Following is the HTML5 version of an SVG example which would draw a circle using
<circle> tag −
<!DOCTYPE html>
<html>
<head>
<title>SVG</title>
<meta charset="utf-8" />
</head>
<body>
<h2>HTML5 SVG Circle</h2>
<svg id="svgelem" height="200" xmlns="http://www.w3.org/2000/svg">
<circle id="redcircle" cx="50" cy="50" r="50" fill="red" />
</svg>
</body>
</html>
This would produce the following result in HTML5 enabled latest version of Firefox.
HTML5−SVGRectangle
Following is the HTML5 version of an SVG example which would draw a rectangle using
<rect> tag −
<!DOCTYPE html>
<html>
<head>
<title>SVG</title>
HTML5
37
<meta charset="utf-8" />
</head>
<body>
<h2>HTML5 SVG Rectangle</h2>
<svg id="svgelem" height="200" xmlns="http://www.w3.org/2000/svg">
<rect id="redrect" width="300" height="100" fill="red" />
</svg>
</body>
</html>
This would produce the following result in HTML5 enabled latest version of Firefox.
HTML5−SVGLine
Following is the HTML5 version of an SVG example which would draw a line using <line>
tag −
<!DOCTYPE html>
<html>
<head>
<title>SVG</title>
<meta charset="utf-8" />
</head>
<body>
<h2>HTML5 SVG Line</h2>
<svg id="svgelem" height="200" xmlns="http://www.w3.org/2000/svg">
<line x1="0" y1="0" x2="200" y2="100" style="stroke:red;stroke-width:2"/>
HTML5
38
</svg>
</body>
</html>
You can use the style attribute which allows you to set additional style information like
stroke and fill colors, width of the stroke, etc.
This would produce the following result in HTML5 enabled latest version of Firefox.
HTML5−SVGEllipse
Following is the HTML5 version of an SVG example which would draw an ellipse using
<ellipse> tag –
<!DOCTYPE html>
<html>
<head>
<title>SVG</title>
<meta charset="utf-8" />
</head>
<body>
<h2>HTML5 SVG Ellipse</h2>
<svg id="svgelem" height="200" xmlns="http://www.w3.org/2000/svg">
<ellipse cx="100" cy="50" rx="100" ry="50" fill="red" />
</svg>
</body>
</html>
HTML5
39
This would produce the following result in HTML5 enabled latest version of Firefox.
HTML5−SVGPolygon
Following is the HTML5 version of an SVG example which would draw a polygon using
<polygon> tag –
<!DOCTYPE html>
<html>
<head>
<title>SVG</title>
<meta charset="utf-8" />
</head>
<body>
<h2>HTML5 SVG Polygon</h2>
<svg id="svgelem" height="200" xmlns="http://www.w3.org/2000/svg">
<polygon points="20,10 300,20, 170,50" fill="red" />
</svg>
</body>
</html>
This would produce the following result in HTML5 enabled latest version of Firefox.
HTML5
40
HTML5−SVGPolyline
Following is the HTML5 version of an SVG example which would draw a polyline using
<polyline> tag −
<!DOCTYPE html>
<html>
<head>
<title>SVG</title>
<meta charset="utf-8" />
</head>
<body>
<h2>HTML5 SVG Polyline</h2>
<svg id="svgelem" height="200" xmlns="http://www.w3.org/2000/svg">
<polyline points="0,0 0,20 20,20 20,40 40,40 40,60" fill="red" />
</svg>
</body>
</html>
This would produce the following result in HTML5 enabled latest version of Firefox.
HTML5−SVGGradients
Following is the HTML5 version of an SVG example which would draw an ellipse using
<ellipse> tag and would use <radialGradient> tag to define an SVG radial gradient.
Similarly, you can use <linearGradient> tag to create SVG linear gradient.
HTML5
41
<!DOCTYPE html>
<html>
<head>
<title>SVG</title>
<meta charset="utf-8" />
</head>
<body>
<h2>HTML5 SVG Gradient Ellipse</h2>
<svg id="svgelem" height="200" xmlns="http://www.w3.org/2000/svg">
<defs>
<radialGradient id="gradient" cx="50%" cy="50%" r="50%" fx="50%"
fy="50%">
<stop offset="0%" style="stop-color:rgb(200,200,200); stop-
opacity:0"/>
<stop offset="100%" style="stop-color:rgb(0,0,255); stop-
opacity:1"/>
</radialGradient>
</defs>
<ellipse cx="100" cy="50" rx="100" ry="50" style="fill:url(#gradient)" />
</svg>
</body>
</html>
This would produce the following result in HTML5 enabled latest version of Firefox.
HTML5
42
HTML5−SVGStar
Following is the HTML5 version of an SVG example which would draw a star using
<polygon> tag.
<html>
<head>
<style>
#svgelem{
position: relative;
left: 50%;
-webkit-transform: translateX(-40%);
-ms-transform: translateX(-40%);
transform: translateX(-40%);
}
</style>
<title>SVG</title>
<meta charset="utf-8" />
</head>
<body>
<h2 align="center">HTML5 SVG Star</h2>
<svg id="svgelem" height="200" xmlns="http://www.w3.org/2000/svg">
<polygon points="100,10 40,180 190,60 10,60 160,180" fill="red"/>
</svg>
</body>
</html>
This would produce the following result in HTML5 enabled latest version of Firefox.
HTML5 SVG Star
HTML5
118
HTML5 features include native audio and video support without the need for Flash.
The HTML5 <audio> and <video> tags make it simple to add media to a website. You
need to set src attribute to identify the media source and include a controls attribute so
the user can play and pause the media.
EmbeddingVideo
Here is the simplest form of embedding a video file in your webpage:
<video src="foo.mp4" width="300" height="200" controls>
Your browser does not support the <video> element.
</video>
The current HTML5 draft specification does not specify which video formats browsers
should support in the video tag. But most commonly used video formats are:
 Ogg: Ogg files with Thedora video codec and Vorbis audio codec.
 mpeg4: MPEG4 files with H.264 video codec and AAC audio codec.
You can use <source> tag to specify media along with media type and many other
attributes. A video element allows multiple source elements and browser will use the first
recognized format:
<!DOCTYPE HTML>
<html>
<body>
<video width="300" height="200" controls autoplay>
<source src="/html5/foo.ogg" type="video/ogg" />
<source src="/html5/foo.mp4" type="video/mp4" />
Your browser does not support the <video> element.
</video>
</body>
</html>
13. HTML5 − Audio & Video
HTML5
119
This will produce the following result –
VideoAttributeSpecification
The HTML5 video tag can have a number of attributes to control the look and feel and
various functionalities of the control:
Attribute Description
autoplay
This Boolean attribute if specified, the video will automatically begin to
play back as soon as it can do so without stopping to finish loading the
data.
autobuffer
This Boolean attribute if specified, the video will automatically begin
buffering even if it's not set to automatically play.
controls
If this attribute is present, it will allow the user to control video playback,
including volume, seeking, and pause/resume playback.
height
This attribute specifies the height of the video's display area, in CSS
pixels.
loop
This Boolean attribute if specified, will allow video automatically seek back
to the start after reaching at the end.
preload
This attribute specifies that the video will be loaded at page load, and
ready to run. Ignored if autoplay is present.
poster This is a URL of an image to show until the user plays or seeks.
src
The URL of the video to embed. This is optional; you may instead use the
<source> element within the video block to specify the video to embed
width This attribute specifies the width of the video's display area, in CSS pixels.
HTML5
120
EmbeddingAudio
HTML5 supports <audio> tag which is used to embed sound content in an HTML or XHTML
document as follows.
<audio src="foo.wav" controls autoplay>
Your browser does not support the <audio> element.
</audio>
The current HTML5 draft specification does not specify which audio formats browsers
should support in the audio tag. But most commonly used audio formats are ogg,
mp3 and wav.
You can use <source> tag to specify media along with media type and many other
attributes. An audio element allows multiple source elements and browser will use the first
recognized format:
<!DOCTYPE HTML>
<html>
<body>
<audio controls autoplay>
<source src="/html5/audio.ogg" type="audio/ogg" />
<source src="/html5/audio.wav" type="audio/wav" />
Your browser does not support the <audio> element.
</audio>
</body>
</html>
This will produce the following result –
HTML5
121
AudioAttributeSpecification
The HTML5 audio tag can have a number of attributes to control the look and feel and
various functionalities of the control:
Attribute Description
autoplay
This Boolean attribute if specified, the audio will automatically begin to
play back as soon as it can do so without stopping to finish loading the
data.
autobuffer
This Boolean attribute if specified, the audio will automatically begin
buffering even if it's not set to automatically play.
controls
If this attribute is present, it will allow the user to control audio playback,
including volume, seeking, and pause/resume playback.
loop
This Boolean attribute if specified, will allow audio automatically seek back
to the start after reaching at the end.
preload
This attribute specifies that the audio will be loaded at page load, and
ready to run. Ignored if autoplay is present.
src
The URL of the audio to embed. This is optional; you may instead use the
<source> element within the video block to specify the video to embed
HandlingMediaEvents
The HTML5 audio and video tag can have a number of attributes to control various
functionalities of the control using JavaScript:
Event Description
abort This event is generated when playback is aborted.
canplay
This event is generated when enough data is available that the media
can be played.
ended This event is generated when playback completes.
error This event is generated when an error occurs.
loadeddata
This event is generated when the first frame of the media has finished
loading.
loadstart This event is generated when loading of the media begins.
pause This event is generated when playback is paused.
play This event is generated when playback starts or resumes.
progress
This event is generated periodically to inform the progress of the
downloading the media.
ratechange This event is generated when the playback speed changes.
HTML5
122
seeked This event is generated when a seek operation completes.
seeking This event is generated when a seek operation begins.
suspend This event is generated when loading of the media is suspended.
volumechange This event is generated when the audio volume changes.
waiting
This event is generated when the requested operation (such as
playback) is delayed pending the completion of another operation
(such as a seek).
Following is the example which allows to play the given video:
<!DOCTYPE HTML>
<head>
<script type="text/javascript">
function PlayVideo(){
var v = document.getElementsByTagName("video")[0];
v.play();
}
</script>
</head>
<html>
<body>
<form>
<video width="300" height="200" src="/html5/foo.mp4">
Your browser does not support the <video> element.
</video>
<input type="button" onclick="PlayVideo();" value="Play"/>
</form>
</body>
</html>
HTML5
123
This will produce the following result –
ConfiguringServersforMediaType
Most servers don't by default serve Ogg or mp4 media with the correct MIME types, so
you'll likely need to add the appropriate configuration for this.
AddType audio/ogg .oga
AddType audio/wav .wav
AddType video/ogg .ogv .ogg
AddType video/mp4 .mp4
Ad

More Related Content

Similar to html5 _ Fundamentals a Basic Concepts of Understanding HTML.pdf (20)

Sitepoint.com a basic-html5_template
Sitepoint.com a basic-html5_templateSitepoint.com a basic-html5_template
Sitepoint.com a basic-html5_template
Daniel Downs
 
Html 5
Html 5Html 5
Html 5
AJINKYA N
 
1._Introduction_to_HTML5[1].MCA MODULE 1 NOTES
1._Introduction_to_HTML5[1].MCA MODULE 1 NOTES1._Introduction_to_HTML5[1].MCA MODULE 1 NOTES
1._Introduction_to_HTML5[1].MCA MODULE 1 NOTES
Sony235240
 
1. Introduction to HTML5.ppt
1. Introduction to HTML5.ppt1. Introduction to HTML5.ppt
1. Introduction to HTML5.ppt
JyothiAmpally
 
HTML.pptxsupercallefragalidtivexpialidoucious
HTML.pptxsupercallefragalidtivexpialidouciousHTML.pptxsupercallefragalidtivexpialidoucious
HTML.pptxsupercallefragalidtivexpialidoucious
robaoki5
 
HTML 5 Complete Reference
HTML 5 Complete ReferenceHTML 5 Complete Reference
HTML 5 Complete Reference
EPAM Systems
 
HTML 5, CSS3 and ASP.NET Best Practices by Example
HTML 5, CSS3 and ASP.NET Best Practices by ExampleHTML 5, CSS3 and ASP.NET Best Practices by Example
HTML 5, CSS3 and ASP.NET Best Practices by Example
Darren Sim
 
Introduction to html5
Introduction to html5Introduction to html5
Introduction to html5
Manav Prasad
 
Introduction to html55
Introduction to html55Introduction to html55
Introduction to html55
subrat55
 
1._Introduction_to_HTML5 Web Designing.ppt
1._Introduction_to_HTML5 Web Designing.ppt1._Introduction_to_HTML5 Web Designing.ppt
1._Introduction_to_HTML5 Web Designing.ppt
Divya573916
 
1._Introduction_to_HTML5 powerpoint presentation
1._Introduction_to_HTML5 powerpoint presentation1._Introduction_to_HTML5 powerpoint presentation
1._Introduction_to_HTML5 powerpoint presentation
JohnLagman3
 
1._Introduction_tyytggyyyyy666o_HTML5.ppt
1._Introduction_tyytggyyyyy666o_HTML5.ppt1._Introduction_tyytggyyyyy666o_HTML5.ppt
1._Introduction_tyytggyyyyy666o_HTML5.ppt
meganath16032003
 
1._Introduction_to_HTML5 les fonction et les balises
1._Introduction_to_HTML5 les fonction et les balises1._Introduction_to_HTML5 les fonction et les balises
1._Introduction_to_HTML5 les fonction et les balises
aziztara99
 
HTML_new_one is a ppt in markup language
HTML_new_one is a ppt in markup languageHTML_new_one is a ppt in markup language
HTML_new_one is a ppt in markup language
ervishalgour
 
Html5
Html5Html5
Html5
Jetti Chowdary
 
IJCER (www.ijceronline.com) International Journal of computational Engineerin...
IJCER (www.ijceronline.com) International Journal of computational Engineerin...IJCER (www.ijceronline.com) International Journal of computational Engineerin...
IJCER (www.ijceronline.com) International Journal of computational Engineerin...
ijceronline
 
Introduction to HTML5
Introduction to HTML5Introduction to HTML5
Introduction to HTML5
IT Geeks
 
WT Module-1.pdf
WT Module-1.pdfWT Module-1.pdf
WT Module-1.pdf
RamyaH11
 
Lecture 2 HTML part 1.pptxLecture 10 CSS part 2.pptxvvvvvvvvvvvvvv
Lecture 2 HTML part 1.pptxLecture 10 CSS part 2.pptxvvvvvvvvvvvvvvLecture 2 HTML part 1.pptxLecture 10 CSS part 2.pptxvvvvvvvvvvvvvv
Lecture 2 HTML part 1.pptxLecture 10 CSS part 2.pptxvvvvvvvvvvvvvv
ZahouAmel1
 
Grade 10 COMPUTER
Grade 10 COMPUTERGrade 10 COMPUTER
Grade 10 COMPUTER
Joel Linquico
 
Sitepoint.com a basic-html5_template
Sitepoint.com a basic-html5_templateSitepoint.com a basic-html5_template
Sitepoint.com a basic-html5_template
Daniel Downs
 
1._Introduction_to_HTML5[1].MCA MODULE 1 NOTES
1._Introduction_to_HTML5[1].MCA MODULE 1 NOTES1._Introduction_to_HTML5[1].MCA MODULE 1 NOTES
1._Introduction_to_HTML5[1].MCA MODULE 1 NOTES
Sony235240
 
1. Introduction to HTML5.ppt
1. Introduction to HTML5.ppt1. Introduction to HTML5.ppt
1. Introduction to HTML5.ppt
JyothiAmpally
 
HTML.pptxsupercallefragalidtivexpialidoucious
HTML.pptxsupercallefragalidtivexpialidouciousHTML.pptxsupercallefragalidtivexpialidoucious
HTML.pptxsupercallefragalidtivexpialidoucious
robaoki5
 
HTML 5 Complete Reference
HTML 5 Complete ReferenceHTML 5 Complete Reference
HTML 5 Complete Reference
EPAM Systems
 
HTML 5, CSS3 and ASP.NET Best Practices by Example
HTML 5, CSS3 and ASP.NET Best Practices by ExampleHTML 5, CSS3 and ASP.NET Best Practices by Example
HTML 5, CSS3 and ASP.NET Best Practices by Example
Darren Sim
 
Introduction to html5
Introduction to html5Introduction to html5
Introduction to html5
Manav Prasad
 
Introduction to html55
Introduction to html55Introduction to html55
Introduction to html55
subrat55
 
1._Introduction_to_HTML5 Web Designing.ppt
1._Introduction_to_HTML5 Web Designing.ppt1._Introduction_to_HTML5 Web Designing.ppt
1._Introduction_to_HTML5 Web Designing.ppt
Divya573916
 
1._Introduction_to_HTML5 powerpoint presentation
1._Introduction_to_HTML5 powerpoint presentation1._Introduction_to_HTML5 powerpoint presentation
1._Introduction_to_HTML5 powerpoint presentation
JohnLagman3
 
1._Introduction_tyytggyyyyy666o_HTML5.ppt
1._Introduction_tyytggyyyyy666o_HTML5.ppt1._Introduction_tyytggyyyyy666o_HTML5.ppt
1._Introduction_tyytggyyyyy666o_HTML5.ppt
meganath16032003
 
1._Introduction_to_HTML5 les fonction et les balises
1._Introduction_to_HTML5 les fonction et les balises1._Introduction_to_HTML5 les fonction et les balises
1._Introduction_to_HTML5 les fonction et les balises
aziztara99
 
HTML_new_one is a ppt in markup language
HTML_new_one is a ppt in markup languageHTML_new_one is a ppt in markup language
HTML_new_one is a ppt in markup language
ervishalgour
 
IJCER (www.ijceronline.com) International Journal of computational Engineerin...
IJCER (www.ijceronline.com) International Journal of computational Engineerin...IJCER (www.ijceronline.com) International Journal of computational Engineerin...
IJCER (www.ijceronline.com) International Journal of computational Engineerin...
ijceronline
 
Introduction to HTML5
Introduction to HTML5Introduction to HTML5
Introduction to HTML5
IT Geeks
 
WT Module-1.pdf
WT Module-1.pdfWT Module-1.pdf
WT Module-1.pdf
RamyaH11
 
Lecture 2 HTML part 1.pptxLecture 10 CSS part 2.pptxvvvvvvvvvvvvvv
Lecture 2 HTML part 1.pptxLecture 10 CSS part 2.pptxvvvvvvvvvvvvvvLecture 2 HTML part 1.pptxLecture 10 CSS part 2.pptxvvvvvvvvvvvvvv
Lecture 2 HTML part 1.pptxLecture 10 CSS part 2.pptxvvvvvvvvvvvvvv
ZahouAmel1
 

Recently uploaded (20)

Operations Management (Dr. Abdulfatah Salem).pdf
Operations Management (Dr. Abdulfatah Salem).pdfOperations Management (Dr. Abdulfatah Salem).pdf
Operations Management (Dr. Abdulfatah Salem).pdf
Arab Academy for Science, Technology and Maritime Transport
 
apa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdfapa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdf
Ishika Ghosh
 
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Library Association of Ireland
 
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 AccountingHow to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
Celine George
 
YSPH VMOC Special Report - Measles Outbreak Southwest US 5-3-2025.pptx
YSPH VMOC Special Report - Measles Outbreak  Southwest US 5-3-2025.pptxYSPH VMOC Special Report - Measles Outbreak  Southwest US 5-3-2025.pptx
YSPH VMOC Special Report - Measles Outbreak Southwest US 5-3-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
Introduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe EngineeringIntroduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe Engineering
Damian T. Gordon
 
Anti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptxAnti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptx
Mayuri Chavan
 
SPRING FESTIVITIES - UK AND USA -
SPRING FESTIVITIES - UK AND USA            -SPRING FESTIVITIES - UK AND USA            -
SPRING FESTIVITIES - UK AND USA -
Colégio Santa Teresinha
 
2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx
contactwilliamm2546
 
LDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini UpdatesLDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini Updates
LDM Mia eStudios
 
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulsepulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
sushreesangita003
 
Sinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_NameSinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_Name
keshanf79
 
Handling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptxHandling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptx
AuthorAIDNationalRes
 
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar RabbiPresentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Md Shaifullar Rabbi
 
How to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 WebsiteHow to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 Website
Celine George
 
To study Digestive system of insect.pptx
To study Digestive system of insect.pptxTo study Digestive system of insect.pptx
To study Digestive system of insect.pptx
Arshad Shaikh
 
How to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of saleHow to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of sale
Celine George
 
Unit 6_Introduction_Phishing_Password Cracking.pdf
Unit 6_Introduction_Phishing_Password Cracking.pdfUnit 6_Introduction_Phishing_Password Cracking.pdf
Unit 6_Introduction_Phishing_Password Cracking.pdf
KanchanPatil34
 
How to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odooHow to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odoo
Celine George
 
Social Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy StudentsSocial Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy Students
DrNidhiAgarwal
 
apa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdfapa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdf
Ishika Ghosh
 
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Library Association of Ireland
 
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 AccountingHow to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
Celine George
 
Introduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe EngineeringIntroduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe Engineering
Damian T. Gordon
 
Anti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptxAnti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptx
Mayuri Chavan
 
2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx
contactwilliamm2546
 
LDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini UpdatesLDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini Updates
LDM Mia eStudios
 
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulsepulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
sushreesangita003
 
Sinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_NameSinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_Name
keshanf79
 
Handling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptxHandling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptx
AuthorAIDNationalRes
 
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar RabbiPresentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Md Shaifullar Rabbi
 
How to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 WebsiteHow to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 Website
Celine George
 
To study Digestive system of insect.pptx
To study Digestive system of insect.pptxTo study Digestive system of insect.pptx
To study Digestive system of insect.pptx
Arshad Shaikh
 
How to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of saleHow to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of sale
Celine George
 
Unit 6_Introduction_Phishing_Password Cracking.pdf
Unit 6_Introduction_Phishing_Password Cracking.pdfUnit 6_Introduction_Phishing_Password Cracking.pdf
Unit 6_Introduction_Phishing_Password Cracking.pdf
KanchanPatil34
 
How to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odooHow to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odoo
Celine George
 
Social Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy StudentsSocial Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy Students
DrNidhiAgarwal
 
Ad

html5 _ Fundamentals a Basic Concepts of Understanding HTML.pdf

  • 1. HTML5 9 HTML5 is the next major revision of the HTML standard superseding HTML 4.01, XHTML 1.0, and XHTML 1.1. HTML5 is a standard for structuring and presenting content on the World Wide Web. HTML5 is a cooperation between the World Wide Web Consortium (W3C) and the Web Hypertext Application Technology Working Group (WHATWG). The new standard incorporates features like video playback and drag-and-drop that have been previously dependent on third-party browser plug-ins such as Adobe Flash, Microsoft Silverlight, and Google Gears. BrowserSupport The latest versions of Apple Safari, Google Chrome, Mozilla Firefox, and Opera all support many HTML5 features and Internet Explorer 9.0 will also have support for some HTML5 functionality. The mobile web browsers that come pre-installed on iPhones, iPads, and Android phones all have excellent support for HTML5. NewFeatures HTML5 introduces a number of new elements and attributes that can help you in building modern websites. Here is a set of some of the most prominent features introduced in HTML5.  New Semantic Elements: These are like <header>, <footer>, and <section>.  Forms 2.0: Improvements to HTML web forms where new attributes have been introduced for <input> tag.  Persistent Local Storage: To achieve without resorting to third-party plugins.  WebSocket : A next-generation bidirectional communication technology for web applications.  Server-Sent Events: HTML5 introduces events which flow from web server to the web browsers and they are called Server-Sent Events (SSE).  Canvas: This supports a two-dimensional drawing surface that you can program with JavaScript.  Audio & Video: You can embed audio or video on your webpages without resorting to third-party plugins.  Geolocation: Now visitors can choose to share their physical location with your web application. 1. HTML5 − Overview
  • 2. HTML5 10  Microdata: This lets you create your own vocabularies beyond HTML5 and extend your web pages with custom semantics.  Drag and drop: Drag and drop the items from one location to another location on the same webpage. BackwardCompatibility HTML5 is designed, as much as possible, to be backward compatible with existing web browsers. Its new features have been built on existing features and allow you to provide fallback content for older browsers. It is suggested to detect support for individual HTML5 features using a few lines of JavaScript. If you are not familiar with any previous version of HTML, I would recommend that you go through our HTML Tutorial before exploring the features of HTML5.
  • 3. HTML5 11 The HTML 5 language has a "custom" HTML syntax that is compatible with HTML 4 and XHTML1 documents published on the Web, but is not compatible with the more esoteric SGML features of HTML 4. HTML 5 does not have the same syntax rules as XHTML where we needed lower case tag names, quoting our attributes, an attribute had to have a value and to close all empty elements. HTML5 comes with a lot of flexibility and it supports the following features −  Uppercase tag names.  Quotes are optional for attributes.  Attribute values are optional.  Closing empty elements are optional. TheDOCTYPE DOCTYPEs in older versions of HTML were longer because the HTML language was SGML based and therefore required a reference to a DTD. HTML 5 authors would use simple syntax to specify DOCTYPE as follows: <!DOCTYPE html> The above syntax is case-insensitive. CharacterEncoding HTML 5 authors can use simple syntax to specify Character Encoding as follows − <meta charset="UTF-8"> The above syntax is case-insensitive. The<script>tag It's common practice to add a type attribute with a value of "text/javascript" to script elements as follows − <script type="text/javascript" src="scriptfile.js"></script> HTML 5 removes extra information required and you can use simply following syntax − <script src="scriptfile.js"></script> 2. HTML5 − Syntax
  • 4. HTML5 12 The<link>tag So far you were writing <link> as follows − <link rel="stylesheet" type="text/css" href="stylefile.css"> HTML 5 removes extra information required and you can simply use the following syntax − <link rel="stylesheet" href="stylefile.css"> HTML5Elements HTML5 elements are marked up using start tags and end tags. Tags are delimited using angle brackets with the tag name in between. The difference between start tags and end tags is that the latter includes a slash before the tag name. Following is the example of an HTML5 element − <p>...</p> HTML5 tag names are case insensitive and may be written in all uppercase or mixed case, although the most common convention is to stick with lowercase. Most of the elements contain some content like <p>...</p> contains a paragraph. Some elements, however, are forbidden from containing any content at all and these are known as void elements. For example, br, hr, link, meta, etc. Here is a complete list of HTML5 Elements. HTML5Attributes Elements may contain attributes that are used to set various properties of an element. Some attributes are defined globally and can be used on any element, while others are defined for specific elements only. All attributes have a name and a value and look like as shown below in the example. Following is the example of an HTML5 attribute which illustrates how to mark up a div element with an attribute named class using a value of "example" − <div class="example">...</div> Attributes may only be specified within start tags and must never be used in end tags. HTML5 attributes are case insensitive and may be written in all uppercase or mixed case, although the most common convention is to stick with lowercase. Here is a complete list of HTML5 Attributes.
  • 5. HTML5 13 HTML5Document The following tags have been introduced for better structure −  section: This tag represents a generic document or application section. It can be used together with h1-h6 to indicate the document structure.  article: This tag represents an independent piece of content of a document, such as a blog entry or newspaper article.  aside: This tag represents a piece of content that is only slightly related to the rest of the page.  header: This tag represents the header of a section.  footer: This tag represents a footer for a section and can contain information about the author, copyright information, et cetera.  nav: This tag represents a section of the document intended for navigation.  dialog: This tag can be used to mark up a conversation.  figure: This tag can be used to associate a caption together with some embedded content, such as a graphic or video. The markup for an HTML 5 document would look like the following − <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>...</title> </head> <body> <header>...</header> <nav>...</nav> <article> <section> ... </section> </article>
  • 6. HTML5 14 <aside>...</aside> <footer>...</footer> </body> </html> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>...</title> </head> <body> <header role="banner"> <h1>HTML5 Document Structure Example</h1> <p>This page should be tried in safari, chrome or Mozila.</p> </header> <nav> <ul> <li><a href="http://www.tutorialspoint.com/html">HTML Tutorial</a></li> <li><a href="http://www.tutorialspoint.com/css">CSS Tutorial</a></li> <li><a href="http://www.tutorialspoint.com/javascript">JavaScript Tutorial</a></li> </ul> </nav> <article> <section> <p>Once article can have multiple sections</p>
  • 7. HTML5 15 </section> </article> <aside> <p>This is aside part of the web page</p> </aside> <footer> <p>Created by <a href="http://tutorialspoint.com/">Tutorials Point</a></p> </footer> </body> </html>
  • 8. HTML5 16 As explained in the previous chapter, elements may contain attributes that are used to set various properties of an element. Some attributes are defined globally and can be used on any element, while others are defined for specific elements only. All attributes have a name and a value and look like as shown below in the example. Following is the example of an HTML5 attributes which illustrates how to mark up a div element with an attribute named class using a value of "example" − <div class="example">...</div> Attributes may only be specified within start tags and must never be used in end tags. HTML5 attributes are case insensitive and may be written in all uppercase or mixed case, although the most common convention is to stick with lowercase. StandardAttributes The attributes listed below are supported by almost all the HTML 5 tags. Attribute Options Function accesskey User Defined Specifies a keyboard shortcut to access an element. align right, left, center Horizontally aligns tags background URL Places an background image behind an element bgcolor numeric, hexidecimal, RGB values Places a background color behind an element class User Defined Classifies an element for use with Cascading Style Sheets. contenteditable true, false Specifies if the user can edit the element's content or not. contextmenu Menu id Specifies the context menu for an element. data-XXXX User Defined Custom attributes. Authors of a HTML document can define their own attributes. Must start with "data-". draggable true,false, auto Specifies whether or not a user is allowed to drag an element. 3. HTML5 − Attributes
  • 9. HTML5 17 height Numeric Value Specifies the height of tables, images, or table cells. hidden hidden Specifies whether element should be visible or not. id User Defined Names an element for use with Cascading Style Sheets. item List of elements Used to group elements. itemprop List of items Used to group items. spellcheck true, false Specifies if the element must have it's spelling or grammar checked. style CSS Style sheet Specifies an inline style for an element. subject User define id Specifies the element's corresponding item. tabindex Tab number Specifies the tab order of an element. title User Defined "Pop-up" title for your elements. valign top, middle, bottom Vertically aligns tags within an HTML element. width Numeric Value Specifies the width of tables, images, or table cells. For a complete list of HTML5 Tags and related attributes, please check our reference to HTML5 Tags. CustomAttributes A new feature being introduced in HTML 5 is the addition of custom data attributes. A custom data attribute starts with data- and would be named based on your requirement. Here is a simple example – <div class="example" data-subject="physics" data-level="complex"> ... </div> The above code will be perfectly valid HTML5 with two custom attributes called data- subject and data-level. You would be able to get the values of these attributes using JavaScript APIs or CSS in similar way as you get for standard attributes.
  • 10. HTML5 21 Web Forms 2.0 is an extension to the forms features found in HTML4. Form elements and attributes in HTML5 provide a greater degree of semantic mark-up than HTML4 and free us from a great deal of tedious scripting and styling that was required in HTML4. The<input>elementinHTML4 HTML4 input elements use the type attribute to specify the data type.HTML4 provides following types − Type Description text A free-form text field, nominally free of line breaks. password A free-form text field for sensitive information, nominally free of line breaks. checkbox A set of zero or more values from a predefined list. radio An enumerated value. submit A free form of button initiates form submission. file An arbitrary file with a MIME type and optionally a file name. image A coordinate, relative to a particular image's size, with the extra semantic that it must be the last value selected and initiates form submission. hidden An arbitrary string that is not normally displayed to the user. select An enumerated value, much like the radio type. textarea A free-form text field, nominally with no line break restrictions. button A free form of button which can initiates any event related to button. Following is the simple example of using labels, radio buttons, and submit buttons − ... <form action="http://example.com/cgiscript.pl" method="post"> <p> <label for="firstname">first name: </label> <input type="text" id="firstname"><br /> <label for="lastname">last name: </label> 5. HTML5 − Web Forms 2.0
  • 11. HTML5 22 <input type="text" id="lastname"><br /> <label for="email">email: </label> <input type="text" id="email"><br> <input type="radio" name="sex" value="male"> Male<br> <input type="radio" name="sex" value="female"> Female<br> <input type="submit" value="send"> <input type="reset"> </p> </form> ... The<input>elementinHTML5 Apart from the above-mentioned attributes, HTML5 input elements introduced several new values for the type attribute. These are listed below. NOTE: Try all the following example using latest version of Opera browser. Type Description datetime A date and time (year, month, day, hour, minute, second, fractions of a second) encoded according to ISO 8601 with the time zone set to UTC. datetime- local A date and time (year, month, day, hour, minute, second, fractions of a second) encoded according to ISO 8601, with no time zone information. date A date (year, month, day) encoded according to ISO 8601. month A date consisting of a year and a month encoded according to ISO 8601. week A date consisting of a year and a week number encoded according to ISO 8601. time A time (hour, minute, seconds, fractional seconds) encoded according to ISO 8601. number It accepts only numerical value. The step attribute specifies the precision, defaulting to 1. range The range type is used for input fields that should contain a value from a range of numbers. email It accepts only email value. This type is used for input fields that should contain an e-mail address. If you try to submit a simple text, it forces to enter only email address in [email protected] format. url It accepts only URL value. This type is used for input fields that should contain a URL address. If you try to submit a simple text, it forces to enter
  • 12. HTML5 23 only URL address either in http://www.example.com format or in http://example.com format. HTML5-datetime A date and time (year, month, day, hour, minute, second, fractions of a second) encoded according to ISO 8601 with the time zone set to UTC. Example <!DOCTYPE HTML> <html> <body> <form action = "/cgi-bin/html5.cgi" method = "get"> Date and Time : <input type = "datetime" name = "newinput" /> <input type = "submit" value = "submit" /> </form> </body> </html> Output
  • 13. HTML5 24 HTML5-datetimelocal A date and time (year, month, day, hour, minute, second, fractions of a second) encoded according to ISO 8601, with no time zone information. Example <!DOCTYPE HTML> <html> <body> <form action = "/cgi-bin/html5.cgi" method = "get"> Local Date and Time : <input type = "datetime-local" name = "newinput" /> <input type = "submit" value = "submit" /> </form> </body> </html> Output HTML5–date A date (year, month, day) encoded according to ISO 8601. Example <!DOCTYPE HTML> <html> <body> <form action = "/cgi-bin/html5.cgi" method = "get">
  • 14. HTML5 25 Date : <input type = "date" name = "newinput" /> <input type = "submit" value = "submit" /> </form> </body> </html> Output HTML5–month A date consisting of a year and a month encoded according to ISO 8601. Example <!DOCTYPE HTML> <html> <body> <form action = "/cgi-bin/html5.cgi" method = "get"> Month : <input type = "month" name = "newinput" /> <input type = "submit" value = "submit" /> </form> </body> </html>
  • 15. HTML5 26 Output HTML5-week A date consisting of a year and a week number encoded according to ISO 8601. Example <!DOCTYPE HTML> <html> <body> <form action = "/cgi-bin/html5.cgi" method = "get"> Week : <input type = "week" name = "newinput" /> <input type = "submit" value = "submit" /> </form> </body> </html> Output
  • 16. HTML5 27 HTML5–time A time (hour, minute, seconds, fractional seconds) encoded according to ISO 8601. Example <!DOCTYPE HTML> <html> <body> <form action = "/cgi-bin/html5.cgi" method = "get"> Time : <input type = "time" name = "newinput" /> <input type = "submit" value = "submit" /> </form> </body> </html> Output HTML5–number It accepts only numerical value. The step attribute specifies the precision, defaulting to 1. Example <!DOCTYPE HTML> <html> <body> <form action = "/cgi-bin/html5.cgi" method = "get">
  • 17. HTML5 28 Select Number : <input type = "number" min = "0" max = "10" step "1" value = "5" name = "newinput" /> <input type = "submit" value = "submit" /> </form> </body> </html> Output HTML5–range The range type is used for input fields that should contain a value from a range of numbers. Example <!DOCTYPE HTML> <html> <body> <form action = "/cgi-bin/html5.cgi" method = "get"> Select Range : <input type = "range" min = "0" max = "10" step "1" value = "5" name = "newinput" /> <input type = "submit" value = "submit" /> </form> </body> </html>
  • 18. HTML5 29 Output HTML5-email It accepts only email value. This type is used for input fields that should contain an e-mail address. If you try to submit a simple text, it forces to enter only email address in [email protected] format. Example <!DOCTYPE HTML> <html> <body> <form action = "/cgi-bin/html5.cgi" method = "get"> Enter email : <input type = "email" name = "newinput" /> <input type = "submit" value = "submit" /> </form> </body> </html> Output
  • 19. HTML5 30 HTML5–URL It accepts only URL value. This type is used for input fields that should contain a URL address. If you try to submit a simple text, it forces to enter only URL address either in http://www.example.com format or in http://example.com format. Example <!DOCTYPE HTML> <html> <body> <form action = "/cgi-bin/html5.cgi" method = "get"> Enter URL : <input type = "url" name = "newinput" /> <input type = "submit" value = "submit" /> </form> </body> </html> Output The<output>element HTML5 introduced a new element <output> which is used to represent the result of different types of output, such as output written by a script. You can use the for attribute to specify a relationship between the output element and other elements in the document that affected the calculation (for example, as inputs or parameters). The value of the for attribute is a space-separated list of IDs of other elements. <!DOCTYPE HTML>
  • 20. HTML5 31 <html> <script type="text/javascript"> function showResult() { x = document.forms["myform"]["newinput"].value; document.forms["myform"]["result"].value=x; } </script> <body> <form action="/cgi-bin/html5.cgi" method="get" name="myform"> Enter a value : <input type="text" name="newinput" /> <input type="button" value="Result" onclick="showResult();" /> <output name="result"/> </form> </body> </html> It will produce the following result − Theplaceholderattribute HTML5 introduced a new attribute called placeholder. This attribute on <input> and <textarea> elements provide a hint to the user of what can be entered in the field. The placeholder text must not contain carriage returns or line-feeds.
  • 21. HTML5 32 Here is the simple syntax for placeholder attribute − <input type="text" name="search" placeholder="search the web"/> This attribute is supported by latest versions of Mozilla, Safari and Crome browsers only. <!DOCTYPE HTML> <html> <body> <form action="/cgi-bin/html5.cgi" method="get"> Enter email : <input type="email" name="newinput" placeholder="[email protected]"/> <input type="submit" value="submit" /> </form> </body> </html> This will produce the following result − Theautofocusattribute This is a simple one-step pattern, easily programmed in JavaScript at the time of document load, automatically focus one particular form field. HTML5 introduced a new attribute called autofocus which would be used as follows − <input type="text" name="search" autofocus/> This attribute is supported by latest versions of Mozilla, Safari and Chrome browsers only.
  • 22. HTML5 33 <!DOCTYPE HTML> <html> <body> <form action="/cgi-bin/html5.cgi" method="get"> Enter email : <input type="text" name="newinput" autofocus/> <p>Try to submit using Submit button</p> <input type="submit" value="submit" /> </form> </body> </html> Therequiredattribute Now you do not need to have JavaScript for client-side validations like empty text box would never be submitted because HTML5 introduced a new attribute called required which would be used as follows and would insist to have a value − <input type="text" name="search" required/> This attribute is supported by latest versions of Mozilla, Safari and Chrome browsers only. <!DOCTYPE HTML> <html> <body> <form action="/cgi-bin/html5.cgi" method="get"> Enter email : <input type="text" name="newinput" required/> <p>Try to submit using Submit button</p> <input type="submit" value="submit" /> </form> </body> </html> It will produce the following result –
  • 24. HTML5 35 SVG stands for Scalable Vector Graphics and it is a language for describing 2D-graphics and graphical applications in XML and the XML is then rendered by an SVG viewer. SVG is mostly useful for vector type diagrams like Pie charts, Two-dimensional graphs in an X,Y coordinate system etc. SVG became a W3C Recommendation 14. January 2003 and you can check latest version of SVG specification at SVG Specification. ViewingSVGFiles Most of the web browsers can display SVG just like they can display PNG, GIF, and JPG. Internet Explorer users may have to install the Adobe SVG Viewer to be able to view SVG in the browser. EmbeddingSVGinHTML5 HTML5 allows embedding SVG directly using <svg>...</svg> tag which has following simple syntax − <svg xmlns="http://www.w3.org/2000/svg"> ... </svg> Firefox 3.7 has also introduced a configuration option ("about:config") where you can enable HTML5 using the following steps −  Type about:config in your Firefox address bar.  Click the "I'll be careful, I promise!" button on the warning message that appears (and make sure you adhere to it!).  Type html5.enable into the filter bar at the top of the page.  Currently it would be disabled, so click it to toggle the value to true. Now your Firefox HTML5 parser should be enabled and you should be able to experiment with the following examples. 6. HTML5 − SVG
  • 25. HTML5 36 HTML5−SVGCircle Following is the HTML5 version of an SVG example which would draw a circle using <circle> tag − <!DOCTYPE html> <html> <head> <title>SVG</title> <meta charset="utf-8" /> </head> <body> <h2>HTML5 SVG Circle</h2> <svg id="svgelem" height="200" xmlns="http://www.w3.org/2000/svg"> <circle id="redcircle" cx="50" cy="50" r="50" fill="red" /> </svg> </body> </html> This would produce the following result in HTML5 enabled latest version of Firefox. HTML5−SVGRectangle Following is the HTML5 version of an SVG example which would draw a rectangle using <rect> tag − <!DOCTYPE html> <html> <head> <title>SVG</title>
  • 26. HTML5 37 <meta charset="utf-8" /> </head> <body> <h2>HTML5 SVG Rectangle</h2> <svg id="svgelem" height="200" xmlns="http://www.w3.org/2000/svg"> <rect id="redrect" width="300" height="100" fill="red" /> </svg> </body> </html> This would produce the following result in HTML5 enabled latest version of Firefox. HTML5−SVGLine Following is the HTML5 version of an SVG example which would draw a line using <line> tag − <!DOCTYPE html> <html> <head> <title>SVG</title> <meta charset="utf-8" /> </head> <body> <h2>HTML5 SVG Line</h2> <svg id="svgelem" height="200" xmlns="http://www.w3.org/2000/svg"> <line x1="0" y1="0" x2="200" y2="100" style="stroke:red;stroke-width:2"/>
  • 27. HTML5 38 </svg> </body> </html> You can use the style attribute which allows you to set additional style information like stroke and fill colors, width of the stroke, etc. This would produce the following result in HTML5 enabled latest version of Firefox. HTML5−SVGEllipse Following is the HTML5 version of an SVG example which would draw an ellipse using <ellipse> tag – <!DOCTYPE html> <html> <head> <title>SVG</title> <meta charset="utf-8" /> </head> <body> <h2>HTML5 SVG Ellipse</h2> <svg id="svgelem" height="200" xmlns="http://www.w3.org/2000/svg"> <ellipse cx="100" cy="50" rx="100" ry="50" fill="red" /> </svg> </body> </html>
  • 28. HTML5 39 This would produce the following result in HTML5 enabled latest version of Firefox. HTML5−SVGPolygon Following is the HTML5 version of an SVG example which would draw a polygon using <polygon> tag – <!DOCTYPE html> <html> <head> <title>SVG</title> <meta charset="utf-8" /> </head> <body> <h2>HTML5 SVG Polygon</h2> <svg id="svgelem" height="200" xmlns="http://www.w3.org/2000/svg"> <polygon points="20,10 300,20, 170,50" fill="red" /> </svg> </body> </html> This would produce the following result in HTML5 enabled latest version of Firefox.
  • 29. HTML5 40 HTML5−SVGPolyline Following is the HTML5 version of an SVG example which would draw a polyline using <polyline> tag − <!DOCTYPE html> <html> <head> <title>SVG</title> <meta charset="utf-8" /> </head> <body> <h2>HTML5 SVG Polyline</h2> <svg id="svgelem" height="200" xmlns="http://www.w3.org/2000/svg"> <polyline points="0,0 0,20 20,20 20,40 40,40 40,60" fill="red" /> </svg> </body> </html> This would produce the following result in HTML5 enabled latest version of Firefox. HTML5−SVGGradients Following is the HTML5 version of an SVG example which would draw an ellipse using <ellipse> tag and would use <radialGradient> tag to define an SVG radial gradient. Similarly, you can use <linearGradient> tag to create SVG linear gradient.
  • 30. HTML5 41 <!DOCTYPE html> <html> <head> <title>SVG</title> <meta charset="utf-8" /> </head> <body> <h2>HTML5 SVG Gradient Ellipse</h2> <svg id="svgelem" height="200" xmlns="http://www.w3.org/2000/svg"> <defs> <radialGradient id="gradient" cx="50%" cy="50%" r="50%" fx="50%" fy="50%"> <stop offset="0%" style="stop-color:rgb(200,200,200); stop- opacity:0"/> <stop offset="100%" style="stop-color:rgb(0,0,255); stop- opacity:1"/> </radialGradient> </defs> <ellipse cx="100" cy="50" rx="100" ry="50" style="fill:url(#gradient)" /> </svg> </body> </html> This would produce the following result in HTML5 enabled latest version of Firefox.
  • 31. HTML5 42 HTML5−SVGStar Following is the HTML5 version of an SVG example which would draw a star using <polygon> tag. <html> <head> <style> #svgelem{ position: relative; left: 50%; -webkit-transform: translateX(-40%); -ms-transform: translateX(-40%); transform: translateX(-40%); } </style> <title>SVG</title> <meta charset="utf-8" /> </head> <body> <h2 align="center">HTML5 SVG Star</h2> <svg id="svgelem" height="200" xmlns="http://www.w3.org/2000/svg"> <polygon points="100,10 40,180 190,60 10,60 160,180" fill="red"/> </svg> </body> </html> This would produce the following result in HTML5 enabled latest version of Firefox. HTML5 SVG Star
  • 32. HTML5 118 HTML5 features include native audio and video support without the need for Flash. The HTML5 <audio> and <video> tags make it simple to add media to a website. You need to set src attribute to identify the media source and include a controls attribute so the user can play and pause the media. EmbeddingVideo Here is the simplest form of embedding a video file in your webpage: <video src="foo.mp4" width="300" height="200" controls> Your browser does not support the <video> element. </video> The current HTML5 draft specification does not specify which video formats browsers should support in the video tag. But most commonly used video formats are:  Ogg: Ogg files with Thedora video codec and Vorbis audio codec.  mpeg4: MPEG4 files with H.264 video codec and AAC audio codec. You can use <source> tag to specify media along with media type and many other attributes. A video element allows multiple source elements and browser will use the first recognized format: <!DOCTYPE HTML> <html> <body> <video width="300" height="200" controls autoplay> <source src="/html5/foo.ogg" type="video/ogg" /> <source src="/html5/foo.mp4" type="video/mp4" /> Your browser does not support the <video> element. </video> </body> </html> 13. HTML5 − Audio & Video
  • 33. HTML5 119 This will produce the following result – VideoAttributeSpecification The HTML5 video tag can have a number of attributes to control the look and feel and various functionalities of the control: Attribute Description autoplay This Boolean attribute if specified, the video will automatically begin to play back as soon as it can do so without stopping to finish loading the data. autobuffer This Boolean attribute if specified, the video will automatically begin buffering even if it's not set to automatically play. controls If this attribute is present, it will allow the user to control video playback, including volume, seeking, and pause/resume playback. height This attribute specifies the height of the video's display area, in CSS pixels. loop This Boolean attribute if specified, will allow video automatically seek back to the start after reaching at the end. preload This attribute specifies that the video will be loaded at page load, and ready to run. Ignored if autoplay is present. poster This is a URL of an image to show until the user plays or seeks. src The URL of the video to embed. This is optional; you may instead use the <source> element within the video block to specify the video to embed width This attribute specifies the width of the video's display area, in CSS pixels.
  • 34. HTML5 120 EmbeddingAudio HTML5 supports <audio> tag which is used to embed sound content in an HTML or XHTML document as follows. <audio src="foo.wav" controls autoplay> Your browser does not support the <audio> element. </audio> The current HTML5 draft specification does not specify which audio formats browsers should support in the audio tag. But most commonly used audio formats are ogg, mp3 and wav. You can use <source> tag to specify media along with media type and many other attributes. An audio element allows multiple source elements and browser will use the first recognized format: <!DOCTYPE HTML> <html> <body> <audio controls autoplay> <source src="/html5/audio.ogg" type="audio/ogg" /> <source src="/html5/audio.wav" type="audio/wav" /> Your browser does not support the <audio> element. </audio> </body> </html> This will produce the following result –
  • 35. HTML5 121 AudioAttributeSpecification The HTML5 audio tag can have a number of attributes to control the look and feel and various functionalities of the control: Attribute Description autoplay This Boolean attribute if specified, the audio will automatically begin to play back as soon as it can do so without stopping to finish loading the data. autobuffer This Boolean attribute if specified, the audio will automatically begin buffering even if it's not set to automatically play. controls If this attribute is present, it will allow the user to control audio playback, including volume, seeking, and pause/resume playback. loop This Boolean attribute if specified, will allow audio automatically seek back to the start after reaching at the end. preload This attribute specifies that the audio will be loaded at page load, and ready to run. Ignored if autoplay is present. src The URL of the audio to embed. This is optional; you may instead use the <source> element within the video block to specify the video to embed HandlingMediaEvents The HTML5 audio and video tag can have a number of attributes to control various functionalities of the control using JavaScript: Event Description abort This event is generated when playback is aborted. canplay This event is generated when enough data is available that the media can be played. ended This event is generated when playback completes. error This event is generated when an error occurs. loadeddata This event is generated when the first frame of the media has finished loading. loadstart This event is generated when loading of the media begins. pause This event is generated when playback is paused. play This event is generated when playback starts or resumes. progress This event is generated periodically to inform the progress of the downloading the media. ratechange This event is generated when the playback speed changes.
  • 36. HTML5 122 seeked This event is generated when a seek operation completes. seeking This event is generated when a seek operation begins. suspend This event is generated when loading of the media is suspended. volumechange This event is generated when the audio volume changes. waiting This event is generated when the requested operation (such as playback) is delayed pending the completion of another operation (such as a seek). Following is the example which allows to play the given video: <!DOCTYPE HTML> <head> <script type="text/javascript"> function PlayVideo(){ var v = document.getElementsByTagName("video")[0]; v.play(); } </script> </head> <html> <body> <form> <video width="300" height="200" src="/html5/foo.mp4"> Your browser does not support the <video> element. </video> <input type="button" onclick="PlayVideo();" value="Play"/> </form> </body> </html>
  • 37. HTML5 123 This will produce the following result – ConfiguringServersforMediaType Most servers don't by default serve Ogg or mp4 media with the correct MIME types, so you'll likely need to add the appropriate configuration for this. AddType audio/ogg .oga AddType audio/wav .wav AddType video/ogg .ogv .ogg AddType video/mp4 .mp4