Lecture 4 HTML5
Lecture 4 HTML5
2
What is HTML5?
• HTML5 is the newest version of HTML
• But not all browsers support all HTML5 yet
(Source: https://html5test.com/results/desktop.html)
• It incorporates all features from earlier versions of HTML,
including the stricter XHTML.
• It adds a diverse set of new tools for the web developer to
use.
Goals of HTML5
• Support all existing web pages. With HTML5, there is no
requirement to go back and revise older websites.
• Reduce the need for external plugins and scripts to show website
content.
• Improve the semantic definition (i.e. meaning and purpose) of page
elements.
• Make the rendering of web content universal and independent of
the device being used.
• Handle web documents errors in a better and more consistent
fashion.
A Rough History of Web Standards
91-92 93-94 95-96 97-98 99-00 01-02 03-04 05-06 07-08 09-10 11-12 13-14
HTML 5 CSS
2004 WHATWG started 1996 – CSS 1 W3C Rec
2008 W3C Working Draft 1998 – CSS 2 W3C Rec
2012 (2010) W3C Candidate Rec 1999 – CSS 3 Proposed
2022 W3C Rec 2005 – CSS 2.1 W3C Candidate Rec
2001 – CSS 3 W3C Working Draft
WHATAG – Web Hypertext Application Technology Working Group W3C – World Wide Web Consortium
5
History of HTML
1991 HTML first published
2014
2012 HTML5
Though HTML5 was published officially in
2014
2012, it has been in development since
2004.
HTML4 vs HTML5
HTML5 HTML4
HTML5 uses new structures such as drag, HTML 4 uses common structures like
drop and much more. headers , footers.
Embedded video and audio without using HTML 4 cannot embed video or audio
flash player. directly and makes use of flash player for
it.
HTML 5 is capable of handling inaccurate HTML 4 cannot handle inaccurate syntax
syntax
HTML 5 introduced many new API’s which HTML 4 has traditional API’s which does
facilitate flexibility of web pages. not include canvas and content editable
API’s.
In HTML 5, new tags and new features like In HTML 4, local storage is not possible
local storage are enhanced. and tags that can handle only one
dimension
7
8
• HTML5
New Elements in HTML5
13
HTML Extended
• Document Flow: div, section, article, nav,
aside, header, footer
• Audio, Video and Embed
• Canvas: paths, gradients, image manipulation,
events
• Microdata for semantics and enhanced search
engine results (Google Rich Snippets)
14
HTML5 Media Elements
Tag Description
Defines sound or music content
<audio controls>
<source src="horse.ogg" type="audio/ogg">
<audio> <source src="horse.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
15
What are Semantic Elements?
A semantic element clearly describes its meaning to both the browser and the developer.
Examples of non-semantic elements: <div> and <span> - Tells nothing about its content.
Examples of semantic elements: <form>, <table>, and <article> - Clearly defines its content.
17
HTML5 Media
• Multimedia on the web is sound, music,
videos, movies, and animations.
• HTML 5 VIDEO
• HTML 5 AUDIO
• HTML Helpers (Plug-ins)
• HTML YouTube Videos
HTML Helpers (Plug-ins)
Canvas SVG
function draw() {
var canvas =
document.getElementById("canvas");
if (canvas.getContext) {
var ctx = canvas.getContext("2d");
ctx.fillStyle = "rgb(200,0,0)";
ctx.fillRect (10,10,55,50);
ctx.fillStyle = "rgb(0,0,200)";
ctx.fillRect (30,30,55,50);
}
}
22
Form Enhancements
• Placeholder text
• Specific text input: email, URL, number, search
• Slider
• Date picker
• User Agent validation
23
CSS Effects
• Rounded corners
• Gradients
• Box and text shadows
• Fonts
• Transparencies
• Multiple background images and border images
• Multiple columns and grid layout
• Box sizing
• Stroke and outlines
• Animation, movement and rotation
• Improved selectors
24
CSS Effect Example
.amazing {
border: 1px solid blue; .amazing {
color: red; border: 1px solid blue;
background-color: gold; color: red;
background-color: gold;
-webkit-border-radius: 40px;
-moz-border-radius: 40px; -webkit-border-radius: 40px;
-moz-border-radius: 40px;
Amazing CSS
border-radius: 40px;
Effects
#474747;
-moz-box-shadow: 8px 8px 6px
#474747;
-webkit-box-shadow: 8px 8px 6px
#474747;
-moz-box-shadow: 8px 8px 6px
box-shadow: 8px 8px 6px #474747; #474747;
box-shadow: 8px 8px 6px #474747;
text-shadow: 8px 8px 2px #595959;
filter: dropshadow(color=#595959, text-shadow: 8px 8px 2px #595959;
offx=8, offy=8); filter: dropshadow(color=#595959,
} offx=8, offy=8);
}
http://css3generator.com/
25
CSS Timelines
http://mattbango.com/notebook/web-development/pure-css-timeline/
26
Offline Applications
<html mainfest="http://m.health.unm.edu/someapp.manifest">
…
</html>
CACHE MANIFEST
someapp.manifest #v1.01
NETWORK:
Search.cfm
Login.cfm
/dynamicpages
FALLBACK:
/dynamicpage.cfm /static.html
http://www.whatwg.org/specs/web-apps/current-work/multipage/offline.html
27
Web storage
The Web Storage API defines a standard for how we can save simple data locally on a user’s computer
or device. Before the emergence of the Web Storage standard, web developers often stored user
information in cookies, or by using plugins. With Web Storage, we now have a standardized definition
for how to store up to 5MB of simple data created by our websites or web applications.
Web Storage is a great complement to Offline Web Applications, because you need somewhere to store
all that user data while you’re working offline, and Web Storage provides it.
Local Storage
Unlike session storage, local storage allows us to save persistent data to the user’s computer, via the
browser. When a user revisits a site at a later date, any data saved to local storage can be retrieved.
Local Storage
• Beyond cookies - local storage
– Manipulated by JavaScript
– Persistent
– 5MB storage per “origin”
– Secure (no communication out of the browser)
• Session storage
– Lasts as long as the browser is open
– Each page and tab is a new session
• Browser based SQLite or IndexedDB
29
HTML Local Storage Objects
• HTML local storage provides two objects for storing data on the client:
– window.localStorage - stores data with no expiration date
– window.sessionStorage - stores data for one session (data is lost when the browser tab
is closed)
• Before using local storage, check browser support for localStorage and
sessionStorage.
<script>
// Check browser support
if (typeof(Storage) !== "undefined") {
// Store
localStorage.setItem("lastname", "Smith");
// Retrieve
document.getElementById("result").innerHTML =
localStorage.getItem("lastname");
} else {
document.getElementById("result").innerHTML = "Sorry,
your browser does not support Web Storage...";
}
</script>
30
Local Storage
• Web storage
window.localStorage['value'] = 'Save this!';
• Session storage
sessionStorage.useLater('fullname’, 'Garth Colasurdo');
alert("Hello " + sessionStorage.fullname);
• Database storage
var database = openDatabase("Database Name", "Database Version");
database.executeSql("SELECT * FROM test", function(result1) {
………
});
http://dev.w3.org/html5/webstorage/
31
Geolocation
The first new API we’ll cover is geolocation. Geolocation allows your visitors to share their current
location.
Depending on how they’re visiting your site, their location may be determined by any of the following:
■ IP address
■ wireless network connection
■ cell tower
■ GPS hardware on the device
Privacy Concerns
Not everyone will want to share their location with you, as there are privacy concerns
inherent to this information. Thus, your visitors must opt in to share their location.
Nothing will be passed along to your site or web application unless the user agrees.
The decision is made via a prompt at the top of the browser. The following figure
shows how this prompt looks like in Chrome.
With geolocation, you can determine the user’s current position. You can also be notified of changes to
their position, which could be used, for example, in a web application that provided real-time driving
directions.
Geolocation: methods
These different tasks are controlled through the three methods currently available
in the Geolocation API:
■ getCurrentPosition
■ watchPosition
■ clearPosition
Web Worker
• JavaScript is a single threaded by design.
• We cannot execute multiple scripts in parallel, because
anything we ask the browser to do will be processed in
sequences.
• When executing scripts in an HTML page, the page
becomes unresponsive until the script is finished.
• Web Workers are introduced to solve this problem. It
introduces functionality that resembles threads.
• With Web Workers, we can load scripts and make them
run in the background, independent from the main
thread.
• A Web Worker script cannot lock up or affect the main thread.
This means, we can do a CPU intensive processing while still
allowing the user to keep using the application or game.
• A web worker is a JavaScript that runs in the background,
independently of other scripts, without affecting the performance
of the page. You can continue to do whatever you want: clicking,
selecting things, etc., while the web worker runs in the
background.
• Web Workers add thread-like functionality to JavaScript.
• We can now spawn a worker that runs independently of the main
script.
• Main script communicates with worker via messages.
35
Markup Elements
New elements in HTML 5 :
Tag Description
For external content, like text from a news-article, blog,
<article>
forum, or any other content from an external source
For content aside from the content it is placed in. The aside
<aside>
content should be related to the surrounding content
<command> A button, or a radiobutton, or a checkbox
For describing details about a document, or parts of a
<details>
document
<summary> A caption, or summary, inside the details element
For grouping a section of stand-alone content, could be a
<figure>
video
<figcaption> The caption of the figure section
36