+ All Categories

HTML5

Date post: 14-Nov-2014
Category:
Upload: mark-embling
View: 649 times
Download: 0 times
Share this document with a friend
Description:
HTML5 overview from DevEvening.
Popular Tags:
28
Mark Embling
Transcript
Page 1: HTML5

Mark Embling

Page 2: HTML5

What’s New?

• New semantic elements• New form <input> types• Data attributes• Audio/video capabilities• JS APIs– Canvas– Geo-location– Offline storage

Some of these are technically not part of the HTML5 spec (anymore)

Page 3: HTML5

But first…

A doctype which it’s actually possible to remember:

<DOCTYPE html>

• Puts all the browsers into standards mode• That’s about all it does

Page 4: HTML5

… and …

<meta charset="utf-8">

instead of

<meta http-equiv="Content-Type" value="text/html;charset=utf-8">

Page 5: HTML5

Semantic Elements

<header><hgroup><nav><article><section><aside><figure><figcaption><time>

<meter><progress><mark><footer>

Not a full list

Page 6: HTML5

Semantic Elements<DOCTYPE html><html><head><!-- stuff --></head><body> <header><h1>My Really Rubbish Blog Demo</h1></header> <nav><ul><!-- menu items… --></ul></nav> <article> <header><h1>Interesting Post</h1></header> <p>Bla bla bla. Interesting post here.</p> <footer> <p>Published on <time datetime="2011-03-30" pubdate>30th March ‘11</time></p> </footer> </article> <!-- some more articles --> <footer><p>Copyright Me 2011</p></footer></body></html>

Page 7: HTML5

Semantic Elements<DOCTYPE html><html><head><!-- stuff --></head><body> <header><h1>My Really Rubbish Blog Demo</h1></header> <nav><ul><!-- menu items… --></ul></nav> <article> <header><h1>Interesting Post</h1></header> <p>Bla bla bla. Interesting post here.</p> <footer> <p>Published on <time datetime="2011-03-30" pubdate>30th March ‘11</time></p> </footer> </article> <!-- some more articles --> <footer><p>Copyright Me 2011</p></footer></body></html>

Page 8: HTML5

Semantic Elements<DOCTYPE html><html><head><!-- stuff --></head><body> <header><h1>My Really Rubbish Blog Demo</h1></header> <nav><ul><!-- menu items… --></ul></nav> <article> <header><h1>Interesting Post</h1></header> <p>Bla bla bla. Interesting post here.</p> <footer> <p>Published on <time datetime="2011-03-30" pubdate>30th March ‘11</time></p> </footer> </article> <!-- some more articles --> <footer><p>Copyright Me 2011</p></footer></body></html>

<nav> <ul> <li><a href="/">Home</a></li> <li><a href="/things">Things</a></li> <li><a href="/widgets">Widgets</a></li> <li><a href="/doodads">Doodads</a></li> <li><a href="/thingumybobs">Thingumybobs</a></li> <li><a href="/contact">Contact Us</a></li> </ul></nav>

Page 9: HTML5

Semantic Elements<DOCTYPE html><html><head><!-- stuff --></head><body> <header><h1>My Really Rubbish Blog Demo</h1></header> <nav><ul><!-- menu items… --></ul></nav> <article> <header><h1>Interesting Post</h1></header> <p>Bla bla bla. Interesting post here.</p> <footer> <p>Published on <time datetime="2011-03-30" pubdate>30th March ‘11</time></p> </footer> </article> <!-- some more articles --> <footer><p>Copyright Me 2011</p></footer></body></html>

Page 10: HTML5

Semantic Elements<DOCTYPE html><html><head><!-- stuff --></head><body> <header><h1>My Really Rubbish Blog Demo</h1></header> <nav><ul><!-- menu items… --></ul></nav> <article> <header><h1>Interesting Post</h1></header> <p>Bla bla bla. Interesting post here.</p> <footer> <p>Published on <time datetime="2011-03-30" pubdate>30th March ‘11</time></p> </footer> </article> <!-- some more articles --> <footer><p>Copyright Me 2011</p></footer></body></html>

Page 11: HTML5

Semantic Elements: IE ≤ 8

• IE ignores them by default– Cannot be styled

• HTML5 Shim– http://remysharp.com/2009/01/07/html5-

enabling-script/– http://code.google.com/p/html5shim/

<!--[if lt IE 9]><script src="…/html5.js"></script><![endif]-->

Page 12: HTML5

Dropped Elements

Deprecated elements in HTML 4.01 & XHTML 1 are gone:

<applet><acronym> (use <abbr> instead)<frame> / <frameset><font><center><u><blink> & <marquee><tt>

Good riddance! Not a full list

Page 13: HTML5

Form Input Types• More specific input types• Browsers can present optimised

controls/keyboards/UI

emailcolordatedatetimedatetime-

localemailmonthnumberrange

searchteltimeurlweek

• Browser support right now is patchy• If not supported, it’ll default to a standard text input

Page 14: HTML5

Form Validation

• Attributes for validation of input

patternrequiredmin/max

• Not quite there yet in terms of support– Opera is probably best now– But no ability to change/style validation

errors

Page 15: HTML5

Data Attributes

• Allows arbitrary pieces of data to be attached to any element– The sort of data which doesn’t belong in class or id

• Data can be used via JS– Client-side sorting– Binding/templating– Build client-side visualisations– Anything!

Page 16: HTML5

Data Attributes

• Any attribute beginning with data-

<tr data-person-ref="1003">…</tr><tr data-sorting-key="bloggs joe">…</tr><button data-bind="enable: SaveEnabled">…</button>

• Ignored by the browser and validators– No browser (including old ones) will be upset by this– Apply to any element you want

Page 17: HTML5

Multimedia

• Native audio and video in the browser (no plugins)

• <audio>– Ogg Vorbis, MP3, AAC (M4A), WAV

(browser dependant)

• <video>– WebM, Ogg (Theora + Vorbis), MP4 (H.264

+ AAC)(browser dependant)

Page 18: HTML5

Multimedia

<audio src="music.mp3" controls> Fallback content</audio>

or

<audio controls> <source src="music.m4a" type="audio/mp4"> <source src="music.mp3" type="audio/mpeg"> Fallback content</audio>

Page 19: HTML5

Canvas

• A raster-based drawing surface right there in the page

• Manipulate via JavaScript• 2D currently (3D coming)• Browser support: all modern browsers & IE6-8 with

help– Excanvas code.google.com/p/explorercanvas/

<canvas id="mycanvas" width="400" height="300"> Fallback content</canvas>

Page 20: HTML5

Canvas

• Data visualisation– Graphs

code.google.com/p/flot/– Dials/gauges

• Animation and effects• Games– Rob Hawkes’ Rawkets

rawkets.com

Page 21: HTML5

Rawkets Canvas & websockets game by Rob Hawkesrawkets.com

Page 22: HTML5

Canvas

1. Get the context for the canvas. This is what is used for drawing.

var canvas = document.getElementById("mycanvas");var context = canvas.getContext("2d");

or with jQuery…

var canvas = $("#mycanvas").get(0);var context = canvas.getContext("2d");

Page 23: HTML5

Canvas

2. Do some drawing

// Draw a couple of rectanglescontext.fillRect(x, y, w, h);context.strokeRect(x, y, w, h);

// Draw a linecontext.beginPath();context.moveTo(x, y);context.lineTo(x, y);context.closePath();

Page 24: HTML5

Canvas

3. Repeat step 2Maybe do some more drawing

• fillRect(x, y, w, h)• strokeRect(x, y, w,

h)• beginPath()• closePath()• moveTo(x, y)• fill()• stroke()

• lineTo(x, y)• rect(x, y, w, h)• arc(x, y, radius,

startAngle, endAngle, anticlockwise)

• arcTo(x1, y1, x2, y2,

radius)Plus a lot more

Page 25: HTML5

Geo-location

• Find the user’s location via JS• Never happens without the user’s permission

– Asks first

• Returns an object:– coords.latitude– coords.longitude– coords.altitude– coords.accuracy– coords.altitudeAccuracy– coords.heading– coords.speed– timestamp

Page 26: HTML5
Page 27: HTML5

Resources

Stuff worth looking at

• Dive Into HTML5diveintohtml5.org

• Mozilla Developer Networkdeveloper.mozilla.org

• Rawkes (Rob Hawkes’ Blog)rawkes.com

• HTML5 Logow3.org/html/logo/

Stuff I’ve mentioned

• HTML5 Shimcode.google.com/p/html5shim/

• Excanvas code.google.com/p/explorercanvas/

• Flot (canvas-based graphs)code.google.com/p/flot/

• Rawkets rawkets.com

Page 28: HTML5

Thanks for Listening

markembling.info@markembling


Recommended