A Journey Into the Emotions of Software Developers
Html5 tutorial
1.
2. HTML5 will be the new standard for HTML. The previous version of HTML,
HTML 4.01, came in 1999. The web has changed a lot since then. HTML5 is still a
work in progress. However, the major browsers support many of the new HTML5
elements and APIs
Some rules for HTML5 were established:
1. New features should be based on HTML, CSS, DOM, and JavaScript
2. Reduce the need for external plugins (like Flash)
3. Better error handling
4. More markup to replace scripting
5. HTML5 is device independent
3. <!DOCTYPE html>
<html>
<head>
<title>Title of the document</title> Newly added Doc-type
</head> element. But Not a DTD
Declaration.
<body>
The content of the document......
</body>
</html>
4. HTML 4.01 Strict
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
HTML 4.01 Transitional
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
HTML 4.01 Frameset
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">
XHTML 1.0 Strict
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
XHTML 1.0 Transitional
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
XHTML 1.0 Frameset
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
XHTML 1.1
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
5. 1. The <canvas> element for 2D drawing
2. The <video> and <audio> elements for media playback
3. Support for local storage
4. New content-specific elements, like <article>, <footer>, <header>, <nav>,
<section>
5. New form controls, like calendar, date, time, email, url, search
6. Tag Description
<article> Defines an article
<aside> Defines content aside from the page content
Isolates a part of text that might be formatted in a different direction from other
<bdi>
text outside it
<command> Defines a command button that a user can invoke
<details> Defines additional details that the user can view or hide
<summary> Defines a visible heading for a <details> element
Specifies self-contained content, like illustrations, diagrams, photos, code listings,
<figure>
etc.
<figcaption> Defines a caption for a <figure> element
<footer> Defines a footer for a document or section
<header> Defines a header for a document or section
<hgroup> Groups a set of <h1> to <h6> elements when a heading has multiple levels
<mark> Defines marked/highlighted text
<meter> Defines a scalar measurement within a known range (a gauge)
<nav> Defines navigation links
7. <progress> Represents the progress of a task
<ruby> Defines a ruby annotation (for East Asian typography)
<rt> Defines an explanation/pronunciation of characters (for East Asian typography)
<rp> Defines what to show in browsers that do not support ruby annotations
<section> Defines a section in a document
<time> Defines a date/time
<wbr> Defines a possible line-break
8. New Media Elements
Tag Description
<audio> Defines sound content
<video> Defines a video or movie
<source> Defines multiple media resources for <video> and <audio>
<embed> Defines a container for an external application or interactive content (a plug-in)
<track> Defines text tracks for <video> and <audio>
New Form Elements
Tag Description
<datalist> Specifies a list of pre-defined options for input controls
<keygen> Defines a key-pair generator field (for forms)
<output> Defines the result of a calculation
Canvas Elements
Tag Description
<canvas> Used to draw graphics, on the fly, via scripting (usually JavaScript
10. Until now, there has not been a standard for showing a video/movie on a web page.
Today, most videos are shown through a plug-in (like flash). However, different
browsers may have different plug-ins.
HTML5 defines a new element which specifies a standard way to embed a
video/movie on a web page: the <video> element.
Example
<!DOCTYPE html />
<html>
<body>
<video width="320" height="240" controls="controls">
<source src="2.mp4" type="video/mp4" />
</video>
<br>
<video width="320" height="240" controls="controls">
<source src="1.wmv" type="video/wmv" />
Your browser does not support the video tag.
</video>
</body>
</html>
11. Video Formats and Browser Support
Browser MP4 WebM Ogg
Internet Explorer 9 YES NO NO
Firefox 4.0 NO YES YES
Google Chrome 6 YES YES YES
Apple Safari 5 YES NO NO
Opera 10.6 NO YES YES
12. Until now, there has not been a standard for playing audio files on a web page.
Today, most audio files are played through a plug-in (like flash). However, different
browsers may have different plug-ins.
HTML5 defines a new element which specifies a standard way to embed an audio file
on a web page: the <audio> element.
Example
<!DOCTYPE html>
<html>
<body>
<audio controls="controls">
<source src="audio.mp3" type="audio/mpeg" />
Your browser does not support the audio element.
</audio>
</body>
</html>
Note : You should also insert text content between the <audio> and </audio> tags for browsers that do not
support the <audio> element.
13. Audio Formats and Browser Support
Browser MP3 Wav Ogg
Internet Explorer 9 YES NO NO
Firefox 4.0 NO YES YES
Google Chrome 6 YES YES YES
Apple Safari 5 YES YES NO
Opera 10.6 NO YES YES
14. The meter element defines a scalar measurement within a known range, similar to
what might be represented by a gauge.
The progress element, which defines completion progress for some task.
Commonly, this element might represent the percentage from 0 percent to 100
percent of a task, such as loading to be completed:
<!DOCTYPE html>
<html>
<body>
<p>Progress: <progress id="progressBar" max="100.00" value="33.1">
33.1%</progress></p>
<br>
<p>Warp Drive Output: <meter min="0" max="10" low="3" optimum="7" high="9"
value="9.5" title="Captain she can't take much more of this!"></meter></p>
<input type="submit" />
</form>
</body>
</html>
15. HTML5 has added following 3 Form Elements
1. <datalist>
2. <keygen>
3. <output>
16. 1. The <datalist> element specifies a list of pre-defined options for an <input>
element.
2. The <datalist> element is used to provide an "autocomplete" feature on
<input> elements. Users will see a drop-down list of pre-defined options as
they input data.
3. Use the <input> element's list attribute to bind it together with a <datalist>
element.
<!DOCTYPE html>
<html>
<body>
<form action="demo_form.asp" method="get">
<input list="browsers" name="browser" />
<datalist id="browsers">
<option value="Internet Explorer">
<option value="Firefox"> <option value="Chrome"> <option value="Opera">
<option value="Safari"> </datalist>
<input type="submit" />
</form> </body> </html>
17. The purpose of the <keygen> element is to provide a secure way to authenticate users.
The <keygen> tag specifies a key-pair generator field in a form.
When the form is submitted, two keys are generated, one private and one public.
The private key is stored locally, and the public key is sent to the server. The public key
could be used to generate a client certificate to authenticate the user in the future.
<!DOCTYPE html>
<html>
<body>
<form action="demo_keygen.asp" method="get">
Username: <input type="text" name="usr_name" />
Encryption: <keygen name="security" />
<input type="submit" />
</form>
</body>
</html>
18. The <output> element represents the result of a calculation (like one performed by a
script).
<!DOCTYPE html>
<html>
<body>
<form oninput="x.value=parseInt(a.value)+parseInt(b.value)">0
<input type="range" name="a" value="50" />100
+<input type="number" name="b" value="50" />
=<output name="x" for="a b"></output>
</form>
</body>
</html>
19. Traditionally, the HTML input element is used to define most form fields. The particular
type of form field of interest is defined with the type attribute, which is set to text,
password, hidden, checkbox, radio, submit, reset, image, or button. HTML5 adds quite
a number of other values, which we will briefly explore here.
21. A variety of date controls can now be directly created by setting the type attribute to
date, datetime, datetime-local, month, week, or time.
<p><label>date:
<input type="date" name="date">
</label></p>
<p><label>datetime:
<input type="datetime" name="datetime">
</label></p>
<p><label>datetime-local:
<input type="datetime-local" name="datetime2">
</label></p>
<p><label>time:
<input type="time" name="time">
</label></p>
<p><label>month:
<input type="month" name="month">
</label></p>
<p><label>week:
<input type="week" name="week">
</label></p>
25. The new details element is supposed to represent some form of extra details, such as a
tooltip or revealed region that may be shown to a user
<details onclick="this.open='open'">
<dt>Help?</dt>
<dd>This could give you help with HTML5 but we need more
implementations to prove how things will work.</dd>
</details>
26. <!DOCTYPE html>
<html>
<body>
<label>Text area: (spellcheck on) <textarea name="comments"
spellcheck="true">There is a tyyypooo here. Did the browser spot it?
</textarea></label>
</body>
</html>
28. <!DOCTYPE html>
<html>
<body>
<p contenteditable="true">This paragraph of text is editable. Click it and you will see.
Of course there is no sense of saving it with code to transmit the information to the
server. This paragraph of text is editable. Click it and you will see. Of course there is no
sense of saving it with code to transmit the information to the server.</p>
</body>
</html>
29. <!DOCTYPE html>
<html>
<body>
<label for="phonenum" class="required">Phone Number:</label>
<input type="text" name="phonenum" id="phonenum"
required pattern="^(d{3}) d{3}-d{4}$"
title="Phone number of form (xxx) xxx-xxxx required">
<input type="submit" value="go to goole "/>
</form>
</body>
</html>
30. The pattern attribute specifies a regular expression that the <input> element's value is
checked against.
Note: The pattern attribute works with the following input types: text, search, url, tel,
email, and password.
<!DOCTYPE html>
<html>
<body>
<form action="demo_form.asp">
Country code: <input type="text" name="country_code"
pattern="[A-Za-z]{3}" title="Three letter country code" />
<input type="submit" />
</form>
</body>
</html>
31.
32.
33.
34. The required attribute is a boolean attribute. When present, it specifies that an input
field must be filled out before submitting the form.
Note: The required attribute works with the following input types: text, search, url,
tel, email, password, date pickers, number, checkbox, radio, and file.
<!DOCTYPE html>
<html>
<body>
<form action="demo_form.asp">
Username: <input type="text" name="username" required="required" />
<input type="submit" />
</form>
</body>
</html>
35. The placeholder attribute specifies a short hint that describes the expected value of an
input field
Note: The placeholder attribute works with the following input types: text, search, url,
tel, email, and password.
<!DOCTYPE html>
<html>
<body>
<form action="demo_form.asp">
<input type="text" name="fname" placeholder="First name" /><br />
<input type="text" name="lname" placeholder="Last name" /><br />
<input type="submit" value="Submit" />
</form>
</body>
</html>
36. The email type is used for input fields that should contain an e-mail address.
<!DOCTYPE html>
<html>
<body>
<form action="demo_form.asp">
E-mail: <input type="email" name="usremail" /><br />
<input type="submit" />
</form>
</body>
</html>
37. The novalidate attribute is a boolean attribute. When present, it specifies that the
form-data (input) should not be validated when submitted.
<!DOCTYPE html>
<html>
<body>
<form action="demo_form.asp" novalidate>
E-mail: <input type="email" name="useremail" required/>
<input type="submit" />
</form>
</body>
</html>
38. The autofocus attribute is a boolean attribute. When present, it specifies that an
<input> element should automatically get focus when the page loads.
<!DOCTYPE html>
<html>
<body>
<form action="demo_form.asp">
First name:<input type="text" name="fname" autofocus="autofocus" /><br />
Last name: <input type="text" name="lname" /><br />
<input type="submit" />
</form>
</body>
</html>
39. The form attribute specifies one or more forms an <input> element belongs to.
Tip: To refer to more than one form, use a space-separated list of form ids.
<!DOCTYPE html>
<html>
<body>
<form action="demo_form.asp" id="form1">
First name: <input type="text" name="fname" /><br />
<input type="submit" value="Submit" />
</form>
<p>The "Last name" field below is outside the form element, but still part of the form.</p>
Last name: <input type="text" name="lname" form="form1" />
</body>
</html>
40. The formaction attribute specifies the URL of a file that will process the input control
when the form is submitted.
The formaction attribute overrides the action attribute of the <form> element
<!DOCTYPE html>
<html>
<body>
<form action="demo_form.asp">
First name: <input type="text" name="fname" /><br />
Last name: <input type="text" name="lname" /><br />
<input type="submit" value="Submit" /><br />
<input type="submit" formaction=“Page2.aspx" value="Submit as admin" />
</form>
</body>
</html>
41. The formmethod attribute defines the HTTP method for sending form-data to the
action URL. The formmethod attribute overrides the method attribute of the <form>
element.
<!DOCTYPE html>
<html>
<body>
<form action="demo_form.asp" method="get">
First name: <input type="text" name="fname" /><br />
Last name: <input type="text" name="lname" /><br />
<input type="submit" value="Submit" />
<input type="submit" formmethod="post" formaction="demo_post.asp" value="Submit
using POST" />
</form>
</body>
</html>
42. The novalidate attribute is a boolean attribute. When present, it specifies that the
<input> element should not be validated when submitted. The formnovalidate attribute
overrides the novalidate attribute of the <form> element
<!DOCTYPE html>
<html>
<body>
<form action="demo_form.asp">
E-mail: <input type="email" name="userid" /><br />
<input type="submit" value="Submit" /><br />
<input type="submit" formnovalidate="formnovalidate" value="Submit without validation" />
</form>
</body>
</html>
43. Value Description
_blank The response is displayed in a new window or tab
_self The response is displayed in the same frame (this is default)
_parent The response is displayed in the parent frame
_top The response is displayed in the full body of the window
framename The response is displayed in a named iframe
<!DOCTYPE html> <html> <body>
<form action="demo_form.asp">
First name: <input type="text" name="fname" /><br />
Last name: <input type="text" name="lname" /><br />
<input type="submit" value="Submit as normal" />
<input type="submit" formtarget="_blank" value="Submit to a new window/tab" />
</form>
</body>
</html>
44. HTML5 defines a standard way to include developer-defined data attributes in tags,
often for the consumption by scripts. The general idea is to use the prefix data- and
then pick a variable name to include some non-visual data on a tag.
<p id="p1" data-author="Thomas A. Powell">This is a data-X example</p>
Reading meta data using Standard Dom
<form>
<input type="button" value="Show Author" onclick="alert(document.
getElementById('p1').getAttribute('data-author')); ">
</form>
HTML5 DOM objects and properties
<form>
<input type="button" value="Show Author" onclick="alert(document.
getElementById('p1').dataset.author);">
</form>
45. 1. The HTML5 <canvas> element is used to draw graphics, on the fly, via scripting
(usually JavaScript).
2. The <canvas> element is only a container for graphics, you must use a script to
actually draw the graphics.
3. A canvas is a drawable region defined in HTML code with height and width
attributes.
4. Canvas has several methods for drawing paths, boxes, circles, characters, and
adding images.
<canvas id="myCanvas" width="200" height="100"></canvas>
Note : The <canvas> element has no drawing abilities of its own. All drawing must
be done inside a JavaScript:
46. <!DOCTYPE html>
<html>
<body>
<canvas id="myCanvas" width="200" height="100" style="border:1px solid #c3c3c3;">
Your browser does not support the canvas element.
</canvas>
<script type="text/javascript“>
var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
ctx.fillStyle="#FF0000";
ctx.fillRect(0,0,150,75);
</script>
</body>
</html>
47. The HTML5 Geolocation API is used to get the geographical position of a user. Since this
can compromise user privacy, the position is not available unless the user approves it.
1. It usages Use the getCurrentPosition() method to get the user's position
The getCurrentPosition() Method return following information
Property Description
coords.latitude The latitude as a decimal number
coords.longitude The longitude as a decimal number
coords.accuracy The accuracy of position
coords.altitude The altitude in meters above the mean sea level
coords.altitudeAccuracy The altitude accuracy of position
coords.heading The heading as degrees clockwise from North
coords.speed The speed in meters per second
timestamp The date/time of the response
48. <!DOCTYPE html>
<html>
<body>
<p id="demo">Click the button to get your coordinates:</p>
<button onclick="getLocation()">Try It</button>
<script>
var x=document.getElementById("demo");
function getLocation()
{
if (navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(showPosition);
}
else{x.innerHTML="Geolocation is not supported by this browser.";}
}
function showPosition(position)
{
x.innerHTML="Latitude: " + position.coords.latitude +
"<br />Longitude: " + position.coords.longitude;
}
</script>
</body>
</html>
http://abkeya.com/blog/2011/02/using-navigator-geolocation-getcurrentposition-to-display-
user%E2%80%99s-current-location-on-google-map-and-getting-user-input/
49. 1. With HTML5, web pages can store data locally within the user's browser.
2. Earlier, this was done with cookies.
3. Web Storage is more secure and faster. The data is not included with every server
request, but used ONLY when asked for.
4. It is also possible to store large amounts of data, without affecting the website's
performance.
5. The data is stored in key/value pairs, and a web page can only access data stored by
itself
There are two new objects for storing data on the client:
1. localStorage - stores data with no expiration date
2. sessionStorage - stores data for one session
50. The localStorage object stores the data with no expiration date. The data will not be
deleted when the browser is closed, and will be available the next day, week, or year.
<!DOCTYPE html>
<html>
<body>
<div id="result"></div>
<script>
if(typeof(Storage)!=="undefined")
{
localStorage.lastname="Smith";
document.getElementById("result").innerHTML="Last name: " + localStorage.lastname;
}
else
{
document.getElementById("result").innerHTML="Sorry, your browser does not support web storage...";
}
</script>
</body>
</html>
51. The sessionStorage object is equal to the localStorage object, except that it stores the
data for only one session. The data is deleted when the user closes the browser window
52. <!DOCTYPE html>
<html> <head> <script>
function clickCounter()
{
if(typeof(Storage)!=="undefined")
{
if (sessionStorage.clickcount)
{
sessionStorage.clickcount=Number(sessionStorage.clickcount)+1;
}
else
{
sessionStorage.clickcount=1;
}
document.getElementById("result").innerHTML="You have clicked the button " + sessionStorage.clickcount + " time(s) in this
session.";
}
else
{
document.getElementById("result").innerHTML="Sorry, your browser does not support web storage...";
}
}
</script> </head> <body> <p><button onclick="clickCounter()" type="button">Click me!</button></p>
<div id="result"></div> <p>Click the button to see the counter increase.</p>
<p>Close the browser tab (or window), and try again, and the counter is reset.</p> </body>
</html>
53. HTML5 introduces application cache, which means that a web application is cached,
and accessible without an internet connection.
Application cache gives an application three advantages:
1. Offline browsing - users can use the application when they're offline
2. Speed - cached resources load faster
3. Reduced server load - the browser will only download updated/changed
resources from the server
54. 1. To enable application cache, include the manifest attribute in the document's
<html> tag:
2. Every page with the manifest attribute specified will be cached when the user
visits it.
3. If the manifest attribute is not specified, the page will not be cached (unless the
page is specified directly in the manifest file).
4. The recommended file extension for manifest files is: ".appcache”
5. A manifest file needs to be served with the correct MIME-type, which is
"text/cache-manifest". Must be configured on the web server.
55. The manifest file is a simple text file, which tells the browser what to cache.
The manifest file has three sections:
1. CACHE MANIFEST - Files listed under this header will be cached after they are
downloaded for the first time
2. NETWORK - Files listed under this header require a connection to the server, and
will never be cached
3. FALLBACK - Files listed under this header specifies fallback pages if a page is
inaccessible
abc.appcache
CACHE MANIFEST <!DOCTYPE html>
# 2012-02-21 v1.0.0
<html lang="en" manifest="/abc.appcache">
/theme.css
/logo.gif // your html document
/main.js </html>
NETWORK:
login.asp
FALLBACK:
/html5/ /offline.html
56. Cache Expires on any of the following cases.
1. The user clears the browser's cache
2. The manifest file is modified (see tip below)
3. The application cache is programmatically updated
57. HTML5 Replacement of Flash
http://www.techrepublic.com/blog/webmaster/how-to-replace-flash-and-silverlight-
with-html5/995
HTML5 for Mobile
http://www.engineyard.com/blog/2011/mobile-development-with-html5/
http://www.mobilehtml5.com/
HTML5 for Storage
http://diveintohtml5.info/storage.html
http://php-html.net/tutorials/html5-local-storage-guide/
HTML Cache
http://html5doctor.com/go-offline-with-application-cache/