Starting Up with HTML 5
What people mean by HTML5
- HTML5 as specified by W3C
- W3C APIs external to HTML5 (Geoloc, DOM4, WebGL)
- CSS 3 and 4
- vendor-specific features :(
- "all the cool & new stuff"
The W3C HTML5 spec
- HTML elements
- APIs
- Stuff for browser makers
HTML5 syntax & parser
- based on real-world HTML4.01 parsers (mostly IE & WebKit)
- shorter, less redundant syntax
- less strict than XHTML
- error-tolerant parser
Basic HTML5 document
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8"/>
<title>Hello, world</title>
</head>
<body>
<p>Hello, world!</p>
</body>
</html>
Minimal syntax
<!DOCTYPE html>
<meta charset=UTF-8>
<title>Hello, world</title>
<p>Hello, world!
Maybe not the best for writing, but good for serving.
Minimize your HTML5 with mod_pagespeed
Default attribute values
<script>
<style>
<link rel=stylesheet
href=styles.css>
<input>
New HTML elements
- text-level semantics:
<mark> <time> <ruby> <rt> <rp>
- forms:
<output> <progress> <meter> <datalist>
- ui:
<details> <summary> <command>
Audio & video formats
- Ogg Vorbis; WebM & Ogg Theora:
Firefox 4+, Opera 10.6+, Chrome 6+
- MP3; h.264:
IE 9+, Safari 5+, Chrome 6+
Many sources for multimedia
<video controls>
<source src="nggyu.webm">
<source src="nggyu.mp4">
</video>
Canvas
An element that JavaScript can draw on
<canvas width="500"
height="400">
…fallback content here…
</canvas>
Contexts (outside HTML5):
Canvas API and 2d context
var canvas=$("canvas")[0],
ctx=canvas.getContext("2d");
ctx.fillStyle =
"rgba(255, 0, 0, 0.5)";
ctx.fillRect(x, y, w, h);
Demo
Content sectioning and grouping
HTML5 Forms
- new
<input>
types
- new elements (
<output>
, <progress>
, <meter>
)
- client-side validation (without JS)
New input types
email tel url search
color range number
date datetime datetime-local time month week
Demo
Multi-file upload
<input type=file multiple>
server-side sees this the same way as many single inputs with the same name
degrades to a single-file input when unsupported
JS: fileInput.files
- a FileList
Demo (FileList), demo (FileAPI)
<progress> & <meter>
<progress value="250"
max="1000">
25 out of 1000
</progress>
<meter min=0 max=100 value=25>
25%</meter>
Demo
Pros and cons of new input types
GOOD: Unsupported degrade to text
.
BAD: Bad support worse than no support.
Advice: for now, use the ones that are text-like (email
, tel
, url
)
wufoo.com has a nice support table
APIs hyped as "HTML5 APIs..."
The APIs list
NOT part of HTML5!
What to do?
- Use widely-implemented parts of HTML5
- Use parts of HTML5 that degrade well
- Use progressive enhancement
- Use polyfills and shims (html5shiv needed for IE8-)
- Stay out of the really unstable features
Where to get more information?
Keep the web OPEN
and ACCESSIBLE to all.