Een introductie tot HTML5

148
HTML5 Een introductie Thomas Byttebier — thomasbyttebier.be Navorming Het Perspectief — 28/01/2014

description

Wat is er nieuw in HTML5? Navorming 28/01/2013, Het Perspectief Gent.

Transcript of Een introductie tot HTML5

Page 1: Een introductie tot HTML5

HTML5Een introductie

Thomas Byttebier — thomasbyttebier.be Navorming Het Perspectief — 28/01/2014

Page 2: Een introductie tot HTML5

HTML5 combineert HTML4 & XHTML1

HTML5? WTF! Waarom geen XHTML2?

Page 3: Een introductie tot HTML5

HTML syntax

<DIV CLASS=belangrijk> <br> !<ul> <li>list item <li>nog een list item </ul> !

Page 4: Een introductie tot HTML5

XHTML syntax

<div class="belangrijk"> <br /> !<ul> <li>list item</li> <li>nog een list item</li> </ul> !

Page 5: Een introductie tot HTML5

Ja maar… is HTML5 al ‘af’?

Page 6: Een introductie tot HTML5

2022

Page 7: Een introductie tot HTML5

Is HTML5 al “af”? Wanneer kunnen we HTML5 gebruiken?

Page 8: Een introductie tot HTML5
Page 9: Een introductie tot HTML5

HTML4 was al jaren ‘af’…

Page 10: Een introductie tot HTML5

Je kan nu al HTML5 gebruiken! *

Page 11: Een introductie tot HTML5

Pfff… ik kende nu net HTML4

Is wat ik leerde dan nog bruikbaar?

Page 12: Een introductie tot HTML5

HTML5 is backwards compatible

Page 13: Een introductie tot HTML5

Je kan elk HTML4 element blijven gebruiken

Geen enkele browser zal er over vallen

maar…

Page 14: Een introductie tot HTML5

<frame>, <frameset>… <font> <big> <center> <strike> … !!

Sommige elementen worden afgeraden (valideren!)

Page 15: Een introductie tot HTML5

bgcolor cellpadding cellspacing valign … !!

Sommige attributen worden afgeraden (valideren!)

Page 16: Een introductie tot HTML5

<b> <i> <small> <a> !!

Sommige elementen krijgen een nieuwe betekenis of ander gebruik

Page 17: Een introductie tot HTML5

<b>

“Tekst die anders moet worden weergegeven dan de gewone tekst, zonder extra nadruk mee te geven.”

—W3C HTML5 specification

Page 18: Een introductie tot HTML5
Page 19: Een introductie tot HTML5

<i>

“Tekst die andere stem of sfeer moet worden gelezen dan de gewone tekst, zonder extra nadruk mee te geven.”

—W3C HTML5 specification

Page 20: Een introductie tot HTML5
Page 21: Een introductie tot HTML5
Page 22: Een introductie tot HTML5

<small>

“Tekst die ‘de kleine lettertjes’ voorstelt: copyrightinformatie, algemene voorwaarden, legale verplichtingen…”

—W3C HTML5 specification

Page 23: Een introductie tot HTML5
Page 24: Een introductie tot HTML5
Page 25: Een introductie tot HTML5

<a>

“Het blijft een inline element, maar je kan er nu ook block-level elementen in plaatsen.”

—W3C HTML5 specification

Page 26: Een introductie tot HTML5
Page 27: Een introductie tot HTML5
Page 28: Een introductie tot HTML5

<h1><a>Artikel titel</a></h1> <p><a><img></a></p> <p><a>Eerste alinea</a></p> <p><a>Lees meer »</a></p>

HTML4

Page 29: Een introductie tot HTML5

<a> <h1>Artikel titel</h1> <p><img></p> <p>Eerste alinea</p> <p>Lees meer »</p> </a>

HTML5

Page 30: Een introductie tot HTML5

Kan ik alles van HTML5 nu al gebruiken?

Page 31: Een introductie tot HTML5

HTML5 in 3 niveaus

1 Zonder problemen vandaag al bruikbaar, werkt in elke browser

2 Bruikbaar, maar oudere browsers tonen gelijkaardig element

3 Bruikbaar mits hacks, anders breekt je site in oudere browsers

Page 32: Een introductie tot HTML5

Zonder problemen vandaag al bruikbaar: het werkt in

elke browser

1

Page 33: Een introductie tot HTML5

De nieuwe doctype

Page 34: Een introductie tot HTML5

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

HTML4 (XHTML1)

Page 35: Een introductie tot HTML5

<!DOCTYPE html>

HTML5

Page 36: Een introductie tot HTML5

Over de namespace en taal

Page 37: Een introductie tot HTML5

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="nl" lang="nl">

HTML4 vs HTML5

<html lang="nl">

Page 38: Een introductie tot HTML5

Het karakterset

Page 39: Een introductie tot HTML5

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

HTML4 vs HTML5

<meta charset="utf-8">

Page 40: Een introductie tot HTML5

De CSS link tag

Page 41: Een introductie tot HTML5

<link rel="stylesheet" type="text/css" href="layout.css" />

HTML4 vs HTML5

<link rel="stylesheet" href="layout.css" />

Page 42: Een introductie tot HTML5

De javascript script tag

Page 43: Een introductie tot HTML5

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

HTML4 vs HTML5

<script src="javascript.js"></script>

Page 44: Een introductie tot HTML5

<!DOCTYPE html> <html lang="nl"> <head> <title></title> <meta charset="utf-8" /> <link rel="stylesheet" href="layout.css" /> <script src="js.js"></script> </head> <body> <!-- Jouw webpagina code --> </body> </html>

Samengevat: de nieuwe HTML5 startstructuur

Page 45: Een introductie tot HTML5

Vandaag al bruikbaar, oudere browsers tonen een

gelijkaardig element

2

Page 46: Een introductie tot HTML5

Nieuwe elementen voor formulieren

Page 47: Een introductie tot HTML5

Flashback: welke formelementen bestaan al in HTML4?

Page 48: Een introductie tot HTML5

<input type="text">

Page 49: Een introductie tot HTML5

<textarea>Tekst</textarea>

Page 50: Een introductie tot HTML5

<input type="password">

Page 51: Een introductie tot HTML5

<input type="file">

Page 52: Een introductie tot HTML5

<input type="submit">

Page 53: Een introductie tot HTML5

<input type="radio">

Page 54: Een introductie tot HTML5

<input type="checkbox">

Page 55: Een introductie tot HTML5

<select> <option>Nederlands</option> <option>Afrikaans</option>

</select>

Page 56: Een introductie tot HTML5

Nieuwe formelementen in HTML5

Page 57: Een introductie tot HTML5

<input type="email">

Page 58: Een introductie tot HTML5

<input type="email">

Page 59: Een introductie tot HTML5

<input type="tel">

Page 60: Een introductie tot HTML5

<input type="tel">

Page 61: Een introductie tot HTML5

<input type="search">

Page 62: Een introductie tot HTML5

<input type="search">

Page 63: Een introductie tot HTML5

<input type="url">

Page 64: Een introductie tot HTML5

<input type="url">

Page 65: Een introductie tot HTML5

<input type="date">

Page 66: Een introductie tot HTML5

<input type="date">

Page 67: Een introductie tot HTML5

<input type="date">

Page 68: Een introductie tot HTML5

<input type="color">

Page 69: Een introductie tot HTML5

<input type="range">

Page 70: Een introductie tot HTML5

Nieuwe attributen voor input-elementen

Page 71: Een introductie tot HTML5

<input type="text" required>

Verplichte velden

Page 72: Een introductie tot HTML5

<input type="text" autofocus>

Autofocus

Page 73: Een introductie tot HTML5
Page 74: Een introductie tot HTML5

<input type="text" placeholder="Vul hier je naam in">

Placeholder

Page 75: Een introductie tot HTML5
Page 76: Een introductie tot HTML5

Extra voordelen

• sommige toestellen tonen een input gerelateerde keyboard layout

• nieuwere browsers tonen aangepaste inputveldjes

• nieuwere browsers doen automatische inputvalidering !!

Page 77: Een introductie tot HTML5

Wat dan met oudere browsers?

• elke input type die ze niet kennen, vervangen ze door <input type=“text”>

• placeholder, autofocus, required, inputvalidering moet je als web developer opvangen via js & server side code !

Page 78: Een introductie tot HTML5

Vandaag enkel bruikbaar mits js/css hacks, anders

breekt je webpagina in oudere browsers

3

Page 79: Een introductie tot HTML5

Nieuwe inline elemententext-level semantics

Page 80: Een introductie tot HTML5

<mark>

“Om tekst te markeren die in een bepaalde context relevant is, maar in de normale context geen extra aandacht vraagt.”

—W3C HTML5 specification

Page 81: Een introductie tot HTML5

<p> Schrijf jij semantische <mark>HTML</mark>? </p>

<mark>

Page 82: Een introductie tot HTML5
Page 83: Een introductie tot HTML5

<time>

“Om data, tijdstippen of beide aan te duiden.”

—W3C HTML5 specification

Page 84: Een introductie tot HTML5

<p> Kom eens langs op <time datetime="2015-04-07"> 7 april</time>. </p>

<time>

Page 85: Een introductie tot HTML5

<p> De staking vond plaats in <time datetime="1933-11">november </time> van dat jaar. </p>

<time>

Page 86: Een introductie tot HTML5

<p> Op <time datetime="01-01"> 1 januari</time> zijn we gesloten. </p>

<time>

Page 87: Een introductie tot HTML5

<p> Ik ben geboren in <time datetime="1980">1980 </time>. </p>

<time>

Page 88: Een introductie tot HTML5

<p> Het wonder vond plaats op <time datetime="2012-06-13 20:18"> 13 juni 2012</time>. </p>

<time>

Page 89: Een introductie tot HTML5
Page 90: Een introductie tot HTML5
Page 91: Een introductie tot HTML5

<meter>

“Om maateenheden aan te duiden, onderdeel van een schaal.”

—W3C HTML5 specification

Page 92: Een introductie tot HTML5

<p> Je behaalde een <meter value="9" max="10">9</meter> op je examen HTML. </p>

<meter>

Page 93: Een introductie tot HTML5

<progress>

“Duidt de afgewerkte hoeveelheid aan van een taak.”

—W3C HTML5 specification

Page 94: Een introductie tot HTML5

<p> Je takenlijstje is al voor <progress value="60" max="100">60% </progress> afgehandeld. </p>

<progress>

Page 95: Een introductie tot HTML5
Page 96: Een introductie tot HTML5

Nieuwe block-level elementensectioning content

Page 97: Een introductie tot HTML5

<section>

“Om inhoudelijk gerelateerde zaken te groeperen.”

—W3C HTML5 specification

Page 98: Een introductie tot HTML5

<section> <h1>HTML5</h1> <p>HTML5 is de toekomst.</p> <p>Er is geen weg terug.</p> <p><img src="i.jpg" alt=""></p> </section>

<section>

Page 99: Een introductie tot HTML5

<article>

“Om inhoudelijk gerelateerde zaken te groeperen. De inhoud blijft duidelijk als die uit de context van de website gehaald zou worden (bijv. in een RSS-lezer).”

—W3C HTML5 specification

Page 100: Een introductie tot HTML5
Page 101: Een introductie tot HTML5
Page 102: Een introductie tot HTML5

<header>

“Bevat een groep inleidende of navigatie-elementen voor het element waarin header zich bevindt. Ook logo’s of zoekvelden zijn mogelijke inhoud.”

—W3C HTML5 specification

Page 103: Een introductie tot HTML5

<body> <header> (logo en navigatie) </header> (rest van de pagina) </body>

<header>

Page 104: Een introductie tot HTML5
Page 105: Een introductie tot HTML5

<section> <header> <p>Een introductie tot…</p> <h1>Moestuinieren</h1> </header> <p> Elke lente begint het weer te kriebelen. </p> </section>

<header>

Page 106: Een introductie tot HTML5

<footer>

“Bevat meer informatie over het element waarin footer zich bevindt: auteur, copyrightinformatie, links naar gerelateerde informatie…”

—W3C HTML5 specification

Page 107: Een introductie tot HTML5

<body> <header> (logo en navigatie) </header> (rest van de pagina) <footer> (copyrightinfo, contactinfo…) </footer> </body>

<footer>

Page 108: Een introductie tot HTML5
Page 109: Een introductie tot HTML5

<section> <header> <h1>Moestuinieren</h1> </header> <p>Elke lente begint het weer te kriebelen.</p> <footer> <p>Auteur: Thomas Byttebier</p> </footer> </section>

<footer>

Page 110: Een introductie tot HTML5

<main>

“Bevat de belangrijkste content van de body van een webpagina. Het kan daarom maar 1 keer voorkomen op een pagina.”

—W3C HTML5 specification

Page 111: Een introductie tot HTML5

<body> <header> (logo en navigatie) </header> <main> (belangrijkste content) </main> <footer> (copyrightinfo, contactinfo…) </footer> </body>

<main>

Page 112: Een introductie tot HTML5
Page 113: Een introductie tot HTML5

<aside>

“Bevat informatie die zijdelings gerelateerd is aan de inhoud rond het aside element, en die als aparte content gezien kan worden: pull quotes, zijkolommen, reclame, navigatie…”

—W3C HTML5 specification

Page 114: Een introductie tot HTML5
Page 115: Een introductie tot HTML5
Page 116: Een introductie tot HTML5

<nav>

“Bevat belangrijke navigatielinks.”

—W3C HTML5 specification

Page 117: Een introductie tot HTML5

<body> <header> (logo) <nav>(unordered list)</nav> </header> <main> (belangrijkste content) </main> <aside> (zijinformatie) </aside> <footer> (copyrightinfo, contactinfo…) </footer> </body>

<nav>

Page 118: Een introductie tot HTML5
Page 119: Een introductie tot HTML5

<figure>

“Bevat een op zich staand beeld: foto, video, illustratie… (optioneel) met een onderschrift. ”

—W3C HTML5 specification

Page 120: Een introductie tot HTML5

<figcaption>

“Bevat het onderschrift van een figure.”

—W3C HTML5 specification

Page 121: Een introductie tot HTML5

<figure> <img src="o.jpg" alt="twee meisjes"> <figcaption> Twee meisjes op het strand van Oostduinkerke. Ze lezen modebladen. </figcaption> </figure>

<figure>

Page 122: Een introductie tot HTML5

<figure> <img src="d.jpg" alt="diagram"> <figcaption> Het aantal nieuwe leden per jaar. </figcaption> </figure>

<figure>

Page 123: Een introductie tot HTML5

<figure> <img src="d.jpg" alt=“diagram 10"> <img src="d2.jpg" alt=“diagram 11"> <img src="d3.jpg" alt=“diagram 12"> <figcaption> Het aantal nieuwe leden per jaar. </figcaption> </figure>

<figure>

Page 124: Een introductie tot HTML5

Bron: html5doctor.com

Page 125: Een introductie tot HTML5

http://html5doctor.com/downloads/h5d-sectioning-flowchart.png

In de war?

Page 126: Een introductie tot HTML5

De nieuwe elementen zijn vandaag bruikbaar, mits een regeltje CSS:

section, article, header, footer, main, nav, aside, figure, hgroup { display:block; }

Page 127: Een introductie tot HTML5

Internet Explorer < 9 heeft ook wat javascript nodig

Page 128: Een introductie tot HTML5

<!--[if lt IE 9]> <script src=“http:// html5shiv.googlecode.com/svn/trunk/ html5.js"></script> <![endif]--> <style> article, aside, dialog, figure, footer, header, main, hgroup, menu, nav, section { display: block; } </style>

Voeg ze toe aan je startstructuur: nieuwe elementen in elke browser

Page 129: Een introductie tot HTML5

De nieuwe document outline van HTML5

Page 130: Een introductie tot HTML5

<h1>Altijd de belangrijkste kop van de volledige pagina</h1> <h2>Nieuwsitem</h2> <p>Tekst</p> <h3>Subkop</h3> <p>Tekst</p> <h3>Subkop</h3> <p>Tekst</p> ...

De document outline van HTML4

Page 131: Een introductie tot HTML5

<h1>Belangrijkste kop van de volledige pagina</h1> <article> <h1>Belangrijkste kop van article</h1> <p>Tekst</p> <h2>Subkop van article</h2> <p>Tekst</p> <h2>Subkop van article</h2> <p>Tekst</p> </article>

De document outline van HTML5

Page 132: Een introductie tot HTML5

Nieuwe interactieve elementen in HTML5: geavanceerde oplossingen

voor vanalles

Page 133: Een introductie tot HTML5
Page 134: Een introductie tot HTML5
Page 135: Een introductie tot HTML5

<video src="film.ogg" controls> Je browser ondersteunt geen HTML video. </video> !<audio src="audio.ogg"> Je browser ondersteunt geen HTML audio. </audio>

Video en audio in HTML5

Page 136: Een introductie tot HTML5

<video controls> <source src="film.ogg" type="video/ogg"> <source src="film.mp4" type="video/mp4"> Je browser ondersteunt geen HTML video. </video>

Ondersteuning voor meer browsers

Page 137: Een introductie tot HTML5

<video controls> <source src="film.ogg" type="video/ogg"> <source src="film.mp4" type="video/mp4"> <object data="flvplayer.swf" type="application/x-shockwave-flash"> <param value="flvplayer.swf" name="movie"/> </object> </video>

Eventueel Flash fall-back voor IE

Page 138: Een introductie tot HTML5

<video controls> <source src="film.ogg" type="video/ogg"> <source src="film.mp4" type="video/mp4"> <img src="fail.png" alt="fail!"> </video>

Of gewoon een foto als fall-back

Page 139: Een introductie tot HTML5
Page 140: Een introductie tot HTML5
Page 141: Een introductie tot HTML5
Page 142: Een introductie tot HTML5
Page 143: Een introductie tot HTML5
Page 144: Een introductie tot HTML5

Nog onbruikbaar in vele browsers. Gebruik javascript om ondersteuning

te detecteren (bijv. modernizr.js)

Page 145: Een introductie tot HTML5

Superhandig: caniuse.com

Page 146: Een introductie tot HTML5

Meer weten?

Page 147: Een introductie tot HTML5

Meer weten?

Page 148: Een introductie tot HTML5

Bronnen en links

• html5doctor.com • diveintohtml5.org • modernizr.com • matthiasbynens.be • apple.com/html5 • html5demos.com