Course Tech 2013, Sasha Vodnik, A Crash Course in HTML5

Post on 08-May-2015

649 views 9 download

description

Over the past few years, HTML5 has changed web browsers and coding alike with a stream of new elements, attributes, and possibilities. In this session we’ll explore the major features that HTML5 offers developers, including semantic elements, form enhancements, and browser-native audio and video. We’ll also survey the landscape of browser support and get familiar with strategies for maintaining compatibility with legacy browsers like IE 7 and 8. Finally, we’ll look at the fundamental changes happening to the process of revising HTML as a language and we’ll consider some of the likeliest scenarios for the evolution of HTML in coming years.

Transcript of Course Tech 2013, Sasha Vodnik, A Crash Course in HTML5

A Crash Course in HTML5

Sasha Vodnik

Agenda

1. Where did HTML5 come from?

2. What’s different in HTML5?

3. How compatible is HTML5?

4. What’s around the corner for HTML?

1. Where did HTML5 come from?

• Web Hypertext Application Technology Working Group (WHATWG)

Language HTML 2 HTML 3 HTML 4XHTML 1

HTML5XHTML5

future

HTMLWHATWG WHATW

G

XHTML

2. What’s different in HTML5?

Semantics Multimedia CSS3 3D, Graphics, Effects

Offline & Storage Device Access Connectivity Performance & Integration

Simplified Syntax

• DOCTYPE

<!DOCTYPE html>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

HTML 4.01 transitional

XHTML 1.1

HTML5

Simplified Syntax

• script element

<script>…</script>

<script type="text/javascript">…</script>

HTML 4.01/ XHTML 1.1

HTML5<script src="file.js”></script>

<script type="text/javascript" src="file.js”></script>

Semantic Elements

• Instead of the generic div element, we have article, figcaption, figure, footer, header, hgroup, nav.

• In general, no different in a browser, but opens doors for predictive indexing by search engines, making content easier to find.

Semantic example

<body> <div class=“navigation”> … </div> <div class=“headings”> <h1>…</h1> <p class=“tagline”>…</p> </div> <div class=“maincontent”> … </div> <div class=“footer”> … </div></body>

<body> <nav> … </nav> <hgroup> <h1>…</h1> <p class=“tagline”>…</p> </hgroup> <article> … </article> <footer> … </footer></body>

Semantics: Microdata

• A system for adding semantic information to specific elements.

• Similar to microformats and RDFa• Main use case: marking information that

can show up in Google Rich Snippets

Microdata example<footer itemtype="http://www.data-vocabulary.org/Organization" itemscope="itemscope"> <p id="contact"> <span itemprop="name">Lakeland Reeds Bed &amp; Breakfast</span> <img src="images/flourish.gif" width="16" height="16" alt="" /> <span itemprop="address" itemscope="itemscope" itemtype="http://data-vocabulary.org/Address"> <span itemprop="street-address">45 Marsh Grass Ln.</span> <img src="images/flourish.gif" width="16" height="16" alt="" /> <span itemprop="locality">Marble</span>, <span itemprop="region">MN</span> <span itemprop="postal-code">55764</span> <img src="images/flourish.gif" width="16" height="16" alt="" /> <span itemprop="tel">(218) 555-5253</span> </span> </p></footer> Room selection at Lakeland Reeds Bed & Breakfast

Marble, MN - (218) 555-5253 Lakeland Reeds Bed & Breakfast offers 4 comfortable rooms that accommodate from 2 to 5 people. All have private baths and views of Twin Lakes.www.example.com

title element content

content marked as microdata

meta element content

URL

Google rich snippet incorporating microdata

Forms: New input types

• Instead of type="text", you can set the type attribute to email, color, range, time, date, url, search, number, or tel

• No issues with backward compatibility, because older browsers assume a value of text when they don’t understand the type value.

Forms: New input types

• Indispensable for mobile interfaces

type="email" type="tel" type="number"

type="date" type="url"

Forms: Native validation

• Add the required attribute to trigger a browser-defined error message when the field is left blank.

• Use the pattern attribute to specify a regular expression that the field value must match.

• These only work in browsers that support them; continue to back up with a script.

Native validation example

Field with required attribute

:invalid pseudo-class: red background

:valid pseudo-class:green background

CSS3: New color systems

<div style="background-color: hsl(0,100%, 50%);"></div> <div style="background-color: hsl(120,100%, 50%);"></div> <div style="background-color: hsl(240,100%, 50%);"></div>

<div style="background-color: rgb(255,0,0);"></div> <div style="background-color: rgb(0,255,0);"></div> <div style="background-color: rgb(0,0,255);"></div>

<div style="background-color: rgb(243,191,189);"></div> <div style="background-color: rgb(246,143,142);"></div> <div style="background-color: rgb(249,95,94);"></div> <div style="background-color: rgb(252,47,47);"></div> <div style="background-color: rgb(255,0,0);"></div>

<div style="background-color: hsla(0,100%,50%,0.2);"></div> <div style="background-color: hsla(0,100%,50%,0.4);"></div> <div style="background-color: hsla(0,100%,50%,0.6);"></div> <div style="background-color: hsla(0,100%,50%,0.8);"></div> <div style="background-color: hsla(0,100%,50%,1);"></div>

CSS 2: red green blue (rgb) CSS3: red green blue alpha (rgba)

CSS3: hue saturation light (hsl) CSS3: hue saturation light alpha (hsla)

CSS3: Shadows

box-shadow: 2px -2px 5px 0px rgba(63, 127, 255, 0.5);

text-shadow: 2px -2px 5px #9393fa;

CSS3: Rounded corners

border-radius: 25px;

CSS3: 2D Transforms

• rotate: in degrees or turns• translate: moves an element up, down,

left, or right• skew: changes alignment of one pair of

edges; creates a non-rectangular parallelogram

• scale: >0 and <1 for smaller; >1 for larger

rotate transform

-webkit-transform: rotateX(45deg) rotateY(45deg);-moz-transform: rotateX(45deg) rotateY(45deg);-o-transform: rotateX(45deg) rotateY(45deg);-ms-transform: rotateX(45deg) rotateY(45deg);transform: rotateX(45deg) rotateY(45deg);

translate transform

-webkit-transform: translateX(100px) translateY(-100px);-moz-transform: translateX(100px) translateY(-100px);-o-transform: translateX(100px) translateY(-100px);-ms-transform: translateX(100px) translateY(-100px);transform: translateX(100px) translateY(-100px);

skew transform-webkit-transform: skewX(-30deg);-moz-transform: skewX(-30deg);-o-transform: skewX(-30deg);-ms-transform: skewX(-30deg);transform: skewX(-30deg);

scale transform-webkit-transform: scale(0.5);-moz-transform: scale(0.5);-o-transform: scale(0.5);-ms-transform: scale(0.5);transform: scale(0.5);

CSS3: Animations

• transition property• applies to long list of properties, including position, color, font-family

audio &video elements

• Current versions of all major browsers support native audio and video playback

• HTML5 includes the audio and video elements for browsers that support them, but they do nothing in older browsers (we’re looking at you, IE6, 7, and 8!)

• track element enables embedding of captions

video example

<object type="application/x-shockwave-flash" data="media/bfly.swf" width="320" height="240"> <param name="movie" value="media/bfly.swf" /> <param name="wmode" value="opaque" /> <param name="loop" value="false" /> <param name="play" value="false" /> <img src="images/bfly.png" alt="a bush with purple flowers covered in dark butterflies" width="320" height="240" title="Unfortunately, your browser isn't able to play this video." /></object>

<video controls="controls" poster="images/bfly.png" width="320" height="240"> <source src="media/bfly.m4v" type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"' /> <source src="media/bfly.webm" type='video/webm; codecs="vp8, vorbis"' /> <source src="media/bfly.ogv" type='video/ogg; codecs="theora, vorbis"' /> <track kind="subtitles" src="subtitles.vtt" /></video>

HTML 4.01/XHTML 1.1

HTML5

Robust video example

<video controls="controls" poster="images/bfly.png" width="320" height="240"> <source src="media/bfly.m4v" type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"' /> <source src="media/bfly.webm" type='video/webm; codecs="vp8, vorbis"' /> <source src="media/bfly.ogv" type='video/ogg; codecs="theora, vorbis"' /> <track kind="subtitles" src="subtitles.vtt" /> <object type="application/x-shockwave-flash" data="media/bfly.swf" width="320" height="240"> <param name="movie" value="media/bfly.swf" /> <param name="wmode" value="opaque" /> <param name="loop" value="false" /> <param name="play" value="false" /> <img src="images/bfly.png" alt="a bush with purple flowers covered in dark butterflies" width="320" height="240" title="Unfortunately, your browser isn't able to play this video." /> </object></video>

HTML5 with nested fallback code

audio &video in browsers

native video controls

native audio controls

The canvas Element

• creates a space to draw graphics using JavaScript

example from https://developer.mozilla.org/en-US/docs/HTML/Canvas/Tutorial/Basic_usage?redirectlocale=en-US&redirectslug=Canvas_tutorial%2FBasic_usage

App Cache

• Lets developers cache web apps on the client side for offline use

Geolocation

• Provides access to user’s location data

• Canonical example: Google Maps

• With a Google Maps API key, a business could include a “Directions” link on its website that provides directions from the user’s location

Web sockets

• Baked-in replacement for AJAX• creates a persistent connection• low latency• near-realtime

Web Workers

• enables running scripts in the background• do computation-intensive work without

affecting interface scripts• uses the Worker() constructor

3. How compatible is HTML5?

• You can use it now!• New features in HTML5 were designed not

to fail in older browsers.• New elements like video and new input

types like email won’t break older browsers

• BUT you have to ensure any critical functionality doesn’t rely on HTML5/CSS3

Browser usage

• statcounter.com• clicky.com• w3counter.com

Research browser statistics for target audience to determine which browsers you need to support

Browser statistics

• Jan 2013: est. 11-14% of page views worldwide on IE7 or IE8

Graceful Degradation

• Test on older browsers you need to support

• Notice which parts of your code aren’t rendered the same (or at all) in an older browser

• Ensure everything you need convey is still conveyed in older browsers

Helpful Script Libraries

• Script libraries like modernizr can detect whether a browser supports a given feature, and let you specify different styling in older browsers.

4. What’s the future of HTML?

image all over the Internet; attribution not readily apparent

The W3C and WHATWG

• Both groups worked together to shape HTML5.

• WHATWG has moved to a continuous, rather than iterative, process. Their product is now known simply as HTML.

• W3C seems to be sticking with major version numbers, planning “HTML.next”.

• Upshot? Unclear, but not a showshopper.

HTML5 vs XHTML

• Some organizations still use XHTML, and it remains an active specification.

• HTML5 can be written to conform to XHTML specifications, or written more simply.

The future is mobile

• Desktop browsers will be with us for a while, but mobile web consumption is exploding.

• Both HTML5 and CSS3 will likely continue to evolve to let developers and users take advantage of new possibilities presented by mobile, handheld, and touch-enabled devices.

HTML5 & CSS3 resources

• caniuse.com browser support guide

• quirksmode.org browser support guide

• diveintohtml5.info free entry-level HTML5 book

• developers.whatwg.org HTML5 specs in an accessible format

• css3.info approachable guides to CSS3 properties and usage

HTML5 and CSS3 Illustrated Introductory

HTML5 and CSS3 Illustrated Complete