cooperation between W3C
and WHATWG
1
only one and it is very simple: <!DOCTYPE html>
Example
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Title of the document</title>
</head>
<body>
Content of the document......
</body>
</html>
<canvas>
element for 2D drawing<video>
and <audio>
elements for media playback<article>
<footer>
<header>
<nav>
<section>
calendar
, date
, time
, email
, url
, search
The New <canvas>
Element
New Media Elements
<audio>
: Defines sound or music content<video>
: Defines video or movie content<source>
: Defines sources for <video>
and <audio>
<track>
: Defines tracks for <video>
and <audio>
<embed>
: Defines containers for external applications (like plug-ins)New Form Elements
<datalist>
<keygen>
<output>
New Semantic/Structural Elements
<header>
<hgroup>
<nav>
<section>
<main>
<article>
<aside>
<footer>
<details>
<summary>
<figure>
<figcaption>
<mark>
<time>
<bdi>
<wbr>
<dialog>
<command>
<meter>
<progress>
<ruby>
<rt>
<rp>
Removed Elements
<acronym>
<applet>
<basefont>
<big>
<center>
<dir>
<font>
<frame>
<frameset>
<noframes>
<strike>
<tt>
HTML5 Semantic Elements
A semantic element clearly describes its meaning to both the browser and the developer
<div>
and <span>
tells nothing about its content.<form>
, <table>
, and <img>
, clearly defines its content.New Semantic Elements in HTML5
<header>
<nav>
<section>
<article>
<aside>
<figure>
<figcaption>
<footer>
<details>
<summary>
<mark>
<time>
HTML5 Forms
HTML5 <input>
Types
color
: <input type="color" name="favcolor">
date
, datetime
, datetime-local
: <input type="datetime-local" name="name">
number
: <input type="number" name="quantity" min="1" max="5">
range
(slider): <input type="range" name="points" min="1" max="10">
search
, tel
(telephone num), time
, url
, week
, month
HTML5 Form Elements
<datalist>
<input list="browsers">
<datalist id="browsers">
<option value="Internet Explorer">
<option value="Firefox">
<option value="Chrome">
<option value="Opera">
<option value="Safari">
</datalist>
<keygen>
<form action="demo_keygen.asp" method="get">
Username: <input type="text" name="usr_name">
Encryption: <keygen name="security">
<input type="submit">
</form>
<output>
<form oninput="x.value=parseInt(a.value)+parseInt(b.value)">0
<input type="range" id="a" value="50">100 +
<input type="number" id="b" value="50">=
<output name="x" for="a b"></output>
</form>
<form>
: autocomplete
, novalidate
<input>
: autocomplete
autofocus
form
formaction
formenctype
formmethod
formnovalidate
formtarget
height
width
list
min
max
multiple
pattern (regexp)
placeholder
<input>
formmethod Attribute
<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>
<Canvas>
only a container for graphics, you must use a script to actually draw the graphics
What is SVG?
SVG Advantages
Differences Between SVG and Canvas
Comparison of Canvas and SVG
<video width="512" height="288" controls>
<source src="game-of-throne.mp4" type="video/mp4">
<source src="fallback.ogg" type="video/ogg">
Your browser does not support the video tag.
</video>
Video Formats and Browser Support: MP4, WebM, and Ogg
video/mp4
video/webm
video/ogg
<video>
, DOM Methods and Properties
<video>
<source>
<track>
: define text tracks in media player<audio controls>
<source src="horse.ogg" type="audio/ogg">
<source src="horse.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
Audio Formats and Browser Support: MP3, Wav, and Ogg
audio/mpeg
audio/ogg
audio/wav
<audio>
, <source>
<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>
Displaying the Result in a Map
function showPosition(position) {
var latlon = position.coords.latitude + ","
+ position.coords.longitude;
var img_url = "http://maps.googleapis.com/maps/api/staticmap?center="
+ latlon + "&zoom=14&size=400x300&sensor=false";
document.getElementById( "mapholder" ).innerHTML = "<img src='"
+ img_url + "'>";
}
getCurrentPosition()
watchPosition()
Make an Element Draggable(default): <img draggable="true">
, see example
With HTML5, web pages can store data locally within the user’s browser. Earlier, this was done with cookies
. However, Web Storage is more secure and faster. The data is not included with every server request, but used ONLY when asked for. It is also possible to store large amounts of data, without affecting the website’s performance.
name/value
pairs, and a web page can only access data stored by itself.The localStorage Object
// Store
localStorage.setItem( "lastname", "Smith" );
// Retrieve
document.getElementById( "result" ).innerHTML =
localStorage.getItem( "lastname" );
// Store
localStorage.lastname = "Smith";
// Retrieve
document.getElementById( "result" ).innerHTML =
localStorage.lastname;
localStorage.removeItem( "lastname" );
The sessionStorage Object
HTML5 introduces application cache
, which means that a web application is cached, and accessible without an internet connection.
3 advantages: Offline browsing
, Speed
, Reduced server load
HTML5 Cache Manifest Example
<!DOCTYPE HTML>
<html manifest="demo.appcache">
<body>
The content of the document......
</body>
</html>
CACHE MANIFEST
+ NETWORK
+ FALLBACK
Updating the Cache
Refs
<input>
Types<Canvas>
Web Hypertext Application Technology Working Group (WHATWG)↩