html5 overview
DESCRIPTION
HTML5 Overview. Peter Traeg 1/25/2011. Agenda. What is HTML5? Demos and lots of ‘em Does HTML5 kill Flash or Silverlight?. HTML5 Areas of Focus. Javascript HTML CSS Some are browser-specific features, others are not always fully implemented in some browsers. - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: HTML5 Overview](https://reader036.vdocuments.mx/reader036/viewer/2022062309/56815907550346895dc63994/html5/thumbnails/1.jpg)
1
HTML5 Overview
Peter Traeg
1/25/2011
![Page 2: HTML5 Overview](https://reader036.vdocuments.mx/reader036/viewer/2022062309/56815907550346895dc63994/html5/thumbnails/2.jpg)
Agenda
What is HTML5? Demos and lots of ‘em Does HTML5 kill Flash or Silverlight?
![Page 3: HTML5 Overview](https://reader036.vdocuments.mx/reader036/viewer/2022062309/56815907550346895dc63994/html5/thumbnails/3.jpg)
HTML5 Areas of Focus
Javascript HTML CSS Some are browser-specific features, others
are not always fully implemented in some browsers.
Pretty much all of what is shown here does NOT work in IE6/7/8. Much of it will work in IE9.
![Page 4: HTML5 Overview](https://reader036.vdocuments.mx/reader036/viewer/2022062309/56815907550346895dc63994/html5/thumbnails/4.jpg)
Just because people call it HTML5 does not make it so Many demonstrations of “HTML5” are of features not truly in the W3C HTML5
spec.
Technologies often called part of HTML5 that aren't (from the Mozilla HTML5 Developer center): WebGL FileReader XMLHttpRequest querySelector(All) Geolocation ECMAScript5 CSS3 XBL2 Web Workers Web Sockets Faster JavaScript
Moral: be careful when someone says HTML5 – what exactly are they talking about? For most people it’s just a basket of features – not a spec.
![Page 5: HTML5 Overview](https://reader036.vdocuments.mx/reader036/viewer/2022062309/56815907550346895dc63994/html5/thumbnails/5.jpg)
HTML5 History/Status Started by WHATWYG (Web Hypertext Application
Technology Working Group) in 2004. Most of these folks were from Webkit (Safari, Apple).
Adopted by W3C as part of a working group in 2007.
Hoped that a full W3C recommendation will be reached by late 2010.
Lots of frustration amongst the members of the working group in trying to get the spec. approved.
![Page 6: HTML5 Overview](https://reader036.vdocuments.mx/reader036/viewer/2022062309/56815907550346895dc63994/html5/thumbnails/6.jpg)
Javascript – Selection of Elements
New methods to get all elements that match on a class name:
var el = document.getElementById('section1');
var els = document.getElementsByTagName('div');
var els = document.getElementsByClassName('section');
Or find elements based on CSS selectorsvar els = document.querySelectorAll("ul li:nth-child(odd)");
var els = document.querySelectorAll("table.test > tr > td");
![Page 7: HTML5 Overview](https://reader036.vdocuments.mx/reader036/viewer/2022062309/56815907550346895dc63994/html5/thumbnails/7.jpg)
Javascript – Local Storage
New localStorage property on the window object lets you save data by key/value pair.// use localStorage for persistent storage
// use sessionStorage for per tab storage
textarea.addEventListener('keyup', function () {
window.localStorage['value'] = area.value;
window.localStorage['timestamp'] = (new Date()).getTime();
}, false);
textarea.value = window.localStorage['value'];
Surprise - Supported in IE8!
![Page 8: HTML5 Overview](https://reader036.vdocuments.mx/reader036/viewer/2022062309/56815907550346895dc63994/html5/thumbnails/8.jpg)
Javascript – Web SQL Database
var db = window.openDatabase("Database Name", "Database Version"); db.transaction(function(tx) { tx.executeSql("SELECT * FROM test", [], successCallback, errorCallback); });
Only supported in Chrome and Safari. Demo link
![Page 9: HTML5 Overview](https://reader036.vdocuments.mx/reader036/viewer/2022062309/56815907550346895dc63994/html5/thumbnails/9.jpg)
Javascript – Offline Support Offline caching of resources
Cache manifest file lists resources that the browser should make available even if it’s offline.
Fallback sections let you substitute files if the offline app requests a resource that’s not available offline.
window.applicationCache fires events to tell you when all the resources in a manifest have successfully downloaded or failed. If one resource fails the whole thing is considered bad.
![Page 10: HTML5 Overview](https://reader036.vdocuments.mx/reader036/viewer/2022062309/56815907550346895dc63994/html5/thumbnails/10.jpg)
Javascript – Web Workers
Ability to create background “threads” for long running processes so they don’t block the UI thread.
Workers can’t access the DOM directly.
main.js: var worker = new Worker('extra_work.js'); worker.onmessage = function(event) { alert(event.data); };
extra_work.js: self.onmessage = function(event) { // Do some work. self.postMessage(some_data); }
![Page 11: HTML5 Overview](https://reader036.vdocuments.mx/reader036/viewer/2022062309/56815907550346895dc63994/html5/thumbnails/11.jpg)
Javascript – Web Sockets
Supports sending messages over a TCP socket.var socket = new WebSocket(location);
socket.onopen = function(event) {
socket.postMessage(“Hello, WebSocket”);
}
socket.onmessage = function(event) { alert(event.data); }
socket.onclose = function(event) { alert(“closed”); }
Not supported on Firefox
![Page 12: HTML5 Overview](https://reader036.vdocuments.mx/reader036/viewer/2022062309/56815907550346895dc63994/html5/thumbnails/12.jpg)
Javascript - Notifications
Webkit specific feature – only in Chrome Pops up notification dialogs Like the notification dialogs that appear from
the Windows system tray.if (window.webkitNotifications.checkPermission() == 0) { // you can pass any url as a parameter window.webkitNotifications.createNotification(tweet.picture,
tweet.title, tweet.text).show();} else { window.webkitNotifications.requestPermission();}
![Page 13: HTML5 Overview](https://reader036.vdocuments.mx/reader036/viewer/2022062309/56815907550346895dc63994/html5/thumbnails/13.jpg)
Javascript – Drag/Drop
New “dragStart” event on elements Data you want to drag is placed into a dataTransfer
object The drag target must listen to these events:
dragEnter, dragOver, and drop DragEnter decides if the user can drop the item on this
target DragOver shows the appropriate UI feedback to illustrate
that a drop is possible. Drop fires when the user actually drops the item on the
target.
![Page 14: HTML5 Overview](https://reader036.vdocuments.mx/reader036/viewer/2022062309/56815907550346895dc63994/html5/thumbnails/14.jpg)
Javascript – Drag/Dropdocument.addEventListener('dragstart', function(event) { event.dataTransfer.setData('text', 'Customized text'); event.dataTransfer.effectAllowed = 'copy';
}, false);
Demo link
![Page 15: HTML5 Overview](https://reader036.vdocuments.mx/reader036/viewer/2022062309/56815907550346895dc63994/html5/thumbnails/15.jpg)
Javascript - Geolocation Lets you obtain latitude/longitude based on the
user’s location. User must “OK” the request.if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(function(position)
{ var lat = position.coords.latitude; var lng = position.coords.longitude; var options = { position: new google.maps.LatLng(lat, lng)
} var marker = new google.maps.Marker(options); marker.setMap(map); });}
![Page 16: HTML5 Overview](https://reader036.vdocuments.mx/reader036/viewer/2022062309/56815907550346895dc63994/html5/thumbnails/16.jpg)
Javascript – File API HTML <input type=“file”> can supply a reference to
a file object A DIV can act as a drop target to allow a user to
drag/drop files on it. This can be used for uploading multiple files.
The File object lets you read the file contents as a binary string, a data URL, or as text.
Once you have the file contents you can POST them to a server via XmlHttp request.
Demo - http://html5demos.com/file-api https://developer.mozilla.org/en/Using_files_from_w
eb_applications
![Page 17: HTML5 Overview](https://reader036.vdocuments.mx/reader036/viewer/2022062309/56815907550346895dc63994/html5/thumbnails/17.jpg)
HTML Features
Mostly changes around new HTML elements designed to create more semantic markup.
Also new attributes on existing elements to create more types of <input> elements.
Older browsers (IE6/7/8) just ignore elements they don’t understand.
![Page 18: HTML5 Overview](https://reader036.vdocuments.mx/reader036/viewer/2022062309/56815907550346895dc63994/html5/thumbnails/18.jpg)
HTML Doctype
The doctype for xhtml:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
The doctype for HTML5:<!DOCTYPE html>
![Page 19: HTML5 Overview](https://reader036.vdocuments.mx/reader036/viewer/2022062309/56815907550346895dc63994/html5/thumbnails/19.jpg)
HTML – New Semantic Elements
<header> <hgroup> : groups a set of h1-h6 elements when the
heading has multiple levels <nav> <section>
<article> <header>
<aside> <footer> <time> <mark>
![Page 20: HTML5 Overview](https://reader036.vdocuments.mx/reader036/viewer/2022062309/56815907550346895dc63994/html5/thumbnails/20.jpg)
HTML – Semantic Elements
Elements don’t have a specific style. They are designed to group content semantically. You use CSS to apply the style you want.
Even IE6 can recognize these new elements via a Javascript trick. See - http://diveintohtml5.org/semantics.html
![Page 21: HTML5 Overview](https://reader036.vdocuments.mx/reader036/viewer/2022062309/56815907550346895dc63994/html5/thumbnails/21.jpg)
HTML – New Input Types <input type="search"> for search boxes <input type="number"> for spinboxes <input type="range"> for sliders <input type="color"> for color pickers <input type="tel"> for telephone numbers <input type="url"> for web addresses <input type="email"> for email addresses <input type="date"> for calendar date pickers <input type="month"> for months <input type="week"> for weeks <input type="time"> for timestamps <input type="datetime"> for precise, absolute date+time stamps <input type="datetime-local"> for local dates and times
Demo: http://www.ilovecolors.com.ar/wp-content/uploads/html5-new-input-types.html
![Page 22: HTML5 Overview](https://reader036.vdocuments.mx/reader036/viewer/2022062309/56815907550346895dc63994/html5/thumbnails/22.jpg)
HTML – More Input Attributes Autocomplete Readonly Multiple Placeholder – ghosted text prompt Pattern – regex validation Required (opera only) Datalist (opera only) For number types: min, max, step CSS attributes for visual display when the control contains invalid
data. :invalid pseudo-class
![Page 23: HTML5 Overview](https://reader036.vdocuments.mx/reader036/viewer/2022062309/56815907550346895dc63994/html5/thumbnails/23.jpg)
HTML – Audio / Video
New <audio> and <video> elements Safari plays H.264 video Chrome plays H.264 and WebM (VP8) Firefox plays Ogg Theora (VP3) and WebM
(Firefox4) IE9 – H.264 video and AAC audio Attributes to show/hide video controls, loop
playback, autoplay, etc.
![Page 24: HTML5 Overview](https://reader036.vdocuments.mx/reader036/viewer/2022062309/56815907550346895dc63994/html5/thumbnails/24.jpg)
HTML – Audio/Video Tags
<audio src="sound.mp3" controls></audio>document.getElementById("audio").muted = false;
<video src="movie.mp4" autoplay controls></video>document.getElementById("video").play();
![Page 25: HTML5 Overview](https://reader036.vdocuments.mx/reader036/viewer/2022062309/56815907550346895dc63994/html5/thumbnails/25.jpg)
HTML – Canvas Element
Bitmap drawing construct This is not vector based. If you want to
rescale you really need to redraw. Once an object is drawn you can’t manipulate
it. You have to draw it again. Performance is quite good Fairly wide browser support – since Safari 3,
Firefox 3, and Chrome 3. Third party explorercanvas library for IE.
![Page 26: HTML5 Overview](https://reader036.vdocuments.mx/reader036/viewer/2022062309/56815907550346895dc63994/html5/thumbnails/26.jpg)
HTML – Canvas Example<canvas id="canvas" width="838" height="220"></canvas>
<script>
var canvasContext = document.getElementById("canvas").getContext("2d");
canvasContext.fillRect(250, 25, 150, 100);
canvasContext.beginPath();
canvasContext.arc(450, 110, 100, Math.PI * 1/2, Math.PI * 3/2);
canvasContext.lineWidth = 15;
canvasContext.lineCap = 'round';
canvasContext.strokeStyle = 'rgba(255, 127, 0, 0.5)';
canvasContext.stroke();
</script>
![Page 27: HTML5 Overview](https://reader036.vdocuments.mx/reader036/viewer/2022062309/56815907550346895dc63994/html5/thumbnails/27.jpg)
HTML – Canvas Drawing
Rectangles – filled, stroked (borders) Arcs – use to draw a circle Paths – moveTo(), lineTo(), stroke() Gradients – linear, and radial Text – fonts, horizontal text alignment,
baselines Images – scaling, drawing a portion of an
image.
![Page 28: HTML5 Overview](https://reader036.vdocuments.mx/reader036/viewer/2022062309/56815907550346895dc63994/html5/thumbnails/28.jpg)
HTML – Canvas 3D
Largely experimental, browser specific No defined spec from the W3C or WHATWG
as of yet.
![Page 29: HTML5 Overview](https://reader036.vdocuments.mx/reader036/viewer/2022062309/56815907550346895dc63994/html5/thumbnails/29.jpg)
HTML – SVG Element <svg> element Part of HTML5 spec Firefox 4 supports a new SVG inline option. Unlike <canvas> this is true vector based drawing. Excellent JS library - http://raphaeljs.com/ Supported on most browsers, including the iPhone Not supported in Android
![Page 30: HTML5 Overview](https://reader036.vdocuments.mx/reader036/viewer/2022062309/56815907550346895dc63994/html5/thumbnails/30.jpg)
CSS
New selectors Fonts Text Handling Columns Transitions Animations
![Page 31: HTML5 Overview](https://reader036.vdocuments.mx/reader036/viewer/2022062309/56815907550346895dc63994/html5/thumbnails/31.jpg)
CSS – Selectors
CSS3 Can select every nth-child – useful for zebra
striped displays (like an old green-bar report) First-child
![Page 32: HTML5 Overview](https://reader036.vdocuments.mx/reader036/viewer/2022062309/56815907550346895dc63994/html5/thumbnails/32.jpg)
CSS Font Support
Can dynamically load fonts into the browser! Supported in canvas as well (not sure about
SVG)
@font-face {
font-family: 'LeagueGothic';
src: url(LeagueGothic.otf);
}
![Page 33: HTML5 Overview](https://reader036.vdocuments.mx/reader036/viewer/2022062309/56815907550346895dc63994/html5/thumbnails/33.jpg)
CSS – Font Support
Different Browsers support different font types: OTF, TTF, SVG, WOFF, EOT.
Even IE5+ supports @font-face but with a proprietary format – EOT
Supported in Firefox 3.5+, Chrome 4+, Safari 3+
iOS supports SVG fonts, Android 2,2 supports OTF/TTF formats
http://www.html5rocks.com/tutorials/webfonts/quick/
![Page 34: HTML5 Overview](https://reader036.vdocuments.mx/reader036/viewer/2022062309/56815907550346895dc63994/html5/thumbnails/34.jpg)
CSS – Text Overflow
Three ways to deal with text overflow text-overflow: hidden text-overflow: no-wrap text-overflow: elipsis
![Page 35: HTML5 Overview](https://reader036.vdocuments.mx/reader036/viewer/2022062309/56815907550346895dc63994/html5/thumbnails/35.jpg)
CSS – Multi column support
Allows you to take a series of paragraphs and flow the content along multiple columns.
CSS attributes on a DIV: column-Count: column-rule: column-gap:
![Page 36: HTML5 Overview](https://reader036.vdocuments.mx/reader036/viewer/2022062309/56815907550346895dc63994/html5/thumbnails/36.jpg)
Additional Attributes
Text Stroke (outline) size and color Ability to set the opacity of the foreground
and background colors independently HSLA Color spec: Hue, Saturation,
Luminance, Alpha
![Page 37: HTML5 Overview](https://reader036.vdocuments.mx/reader036/viewer/2022062309/56815907550346895dc63994/html5/thumbnails/37.jpg)
CSS – Rounded Corners
-webkit-border-radius, -moz-border-radius, border-radius attribute
Progressive enhancement - going forward this is how we will add rounded corners to boxes rather than the current nested DIV approach we currently use. IE 6/7/8 users will see square corners.
![Page 38: HTML5 Overview](https://reader036.vdocuments.mx/reader036/viewer/2022062309/56815907550346895dc63994/html5/thumbnails/38.jpg)
CSS Gradients
Both linear and radial gradients Supported in FF 3.6+ -webkit-linear-gradient, -moz-linear-gradient,
-webkit-radial-gradient, -moz-radial-gradient
![Page 39: HTML5 Overview](https://reader036.vdocuments.mx/reader036/viewer/2022062309/56815907550346895dc63994/html5/thumbnails/39.jpg)
CSS Shadows/Reflections
Can now add drop shadows to text and box elements
text-shadow and box-shadow attributes -webkit-box-reflect – build your own coverflow
display with CSS! I believe -moz-box-reflect is in FF4.
![Page 40: HTML5 Overview](https://reader036.vdocuments.mx/reader036/viewer/2022062309/56815907550346895dc63994/html5/thumbnails/40.jpg)
CSS Backgrounds
Can now control background size to always cover or contain the background in an element
Multiple backgrounds – can layer multiple background images on one another
![Page 41: HTML5 Overview](https://reader036.vdocuments.mx/reader036/viewer/2022062309/56815907550346895dc63994/html5/thumbnails/41.jpg)
CSS Flexible Box Layout
A way to proportionally size boxes in relation to another.
A great way to center content vertically and horizontally.
Supported in Firefox 3+, Chrome, Safari, Mobile Safari (iOS), Android. Not in IE9!!
http://www.html5rocks.com/tutorials/flexbox/quick/
http://www.ie7nomore.com/fun/flexiblenav/
![Page 42: HTML5 Overview](https://reader036.vdocuments.mx/reader036/viewer/2022062309/56815907550346895dc63994/html5/thumbnails/42.jpg)
CSS Transitions
Lets you apply an animated transition when changing the value of a CSS property.
Mostly webkit, but coming in Firefox 4 Works on iOS but not Android GPU accelerated in iOS Cool transition demo at -
http://www.apple.com/html5/showcase/transitions/
![Page 43: HTML5 Overview](https://reader036.vdocuments.mx/reader036/viewer/2022062309/56815907550346895dc63994/html5/thumbnails/43.jpg)
CSS Transforms
Scale Rotate Perspective Firefox 3.5+ https://developer.mozilla.org/En/CSS/-moz-transform
![Page 44: HTML5 Overview](https://reader036.vdocuments.mx/reader036/viewer/2022062309/56815907550346895dc63994/html5/thumbnails/44.jpg)
CSS - Animations
Allows you specify from / to property values in CSS.
Duration, repetition, etc. all controlled via CSS.
Already in webkit, in FF 3.7+
![Page 45: HTML5 Overview](https://reader036.vdocuments.mx/reader036/viewer/2022062309/56815907550346895dc63994/html5/thumbnails/45.jpg)
What about Flash? Lots of stuff that HTML5 leaves out for us: Font metrics Bitmap manipulation Audio manipulation More flexible security model (cross-domain). However new
browsers support some of this in XmlHttpRequest 3D support – hardware acceleration Actionscript language Desktop client support (AIR) Totally cross-browser/cross-platform. With HTML5
![Page 46: HTML5 Overview](https://reader036.vdocuments.mx/reader036/viewer/2022062309/56815907550346895dc63994/html5/thumbnails/46.jpg)
Where to learn more
HTML5Rocks Apple HTML5 Demo Dive Into HTML5 HTML5 Peeks, Pokes, and Pointers HTML5Demos Can I Use? HTML5 Compatibility Tables Mozilla Developer Center HTML5 W3C Working Draft WHATWG Working Draft