35
HTML5, CSS3 PRO Bruce D. Kyle MCP MCSD Principal Instructor @brucedkyle [email protected]

HTML Semantic Tags

Embed Size (px)

DESCRIPTION

This 20-minute presentation provides an introduction to several HTML5 semantic tags: article, section, aside, header, footer, nav. Includes how you can address browser compatibility issues.

Citation preview

Page 1: HTML Semantic Tags

HTML5, CSS3 PROBruce D. Kyle MCP MCSDPrincipal Instructor@[email protected]

Page 2: HTML Semantic Tags

Prerequisites & Context

• Pre-course announcement

• Builds on your HTML4 experience

• Passed online HTML exam– HTML page structure– Elements and attributes

• Previous class – Dev Tools• This class – Semantic Tags• Next class – HTML5 Forms

Page 3: HTML Semantic Tags

Context

• Previous class – Dev Tools• This class – Semantic Tags• Next class – HTML5 Forms

Page 4: HTML Semantic Tags

Copyright 2014 NextechU LLCImages licensed from Getty Images

Page 5: HTML Semantic Tags

SEMANTIC TAGSNew Elements

Page 6: HTML Semantic Tags

Class Objectives

• Tell why semantic tags are a big deal

• Know when to use semantic tags on your Web page

• Identify semantic tags on a Web page

• Determine which browsers (devices) support semantic tags

• Provide backward compatibility for legacy browsers

Page 7: HTML Semantic Tags
Page 8: HTML Semantic Tags

<h1>Articles on: Fruit</h1>

<h2>Apple</h2><p>The apple is the pomaceous fruit of the apple tree...</p>

<h2>Orange</h2><p>The orange is a hybrid of ancient cultivated origin, possibly between pomelo and tangerine...</p>

<h2>Banana</h2><p>Bananas come in a variety of sizes and colors when ripe, including yellow, purple, and red...</p>

Where is the article?

Page 9: HTML Semantic Tags

<h1>Articles on: Fruit</h1>

<h2>Apple</h2><p>The apple is the pomaceous fruit of the apple tree...</p>

<h2>Orange</h2><p>The orange is a hybrid of ancient cultivated origin, possibly between pomelo and tangerine...</p>

<h2>Banana</h2><p>Bananas come in a variety of sizes and colors when ripe, including yellow, purple, and red...</p>

Where is the article?

<section>  <h1>Articles on: Fruit</h1>

  <article>    <h2>Apple</h2>    <p>The apple is the pomaceous fruit of the apple tree...</p>  </article>

  <article>    <h2>Orange</h2>    <p>The orange is a hybrid of ancient cultivated origin, possibly between pomelo and tangerine...</p>  </article>

  <article>    <h2>Banana</h2>    <p>Bananas come in a variety of sizes and colors when ripe, including yellow, purple, and red...</p>  </article>    </section>

Page 10: HTML Semantic Tags

Why new elements?

HTML 4

<div id="nav">

<div class="header">

<div id="footer">

Page 11: HTML Semantic Tags

Why new elements?

HTML 4 HTML5

<nav>

<header>

<footer>

<div id="nav">

<div class="header">

<div id="footer">

Page 12: HTML Semantic Tags

Semantic Tags

• article• aside• audio• canvas• command• datalist• details• embed• figcaption• figure

• footer• header• hgroup• keygen• mark• meter• nav• output• progress• rp

• rt• ruby• section• source• summary• time• video• wbr

Page 13: HTML Semantic Tags

Semantic Tags

• article• aside• audio• canvas• command• datalist• details• embed• figcaption• figure

• footer• header• hgroup• keygen• mark• meter• nav• output• progress• rp

• rt• ruby• section• source• summary• time• video• wbr

Page 14: HTML Semantic Tags
Page 15: HTML Semantic Tags

DEMOSemantic Tag

Page 16: HTML Semantic Tags

When to use section and article

<section>• Independent• Block of related

content (articles)

• Would the content would make sense on its own in a feed reader? If so use <article>

• Is the content related? If so use <section>• Finally if there’s no semantic relationship use

<div>

<article>• Self-contained

composition in a document, page, application, or site

• Like a blog article and its content

<div>• The content

!

Page 17: HTML Semantic Tags

Why Use Semantic Tags?

Page 18: HTML Semantic Tags

Semantics are for you, not the other way around

Developer comprehension

Lighter Code Repurposing

Accessibility

Search Engine Optimization

Page 19: HTML Semantic Tags

But CanIuse?

Page 20: HTML Semantic Tags

But CanIuse?

Page 21: HTML Semantic Tags

Modernizr

Page 22: HTML Semantic Tags

EXERCISE

Page 23: HTML Semantic Tags

Quiz

Which is a semantic tag?

<h1>

<section>

<header>

<a>

Page 24: HTML Semantic Tags

Quiz

Who gets the most out of semantic tags?

A) Bill GatesB) W3CC) GoogleD) You

Which is a semantic tag?

<h1>

<section>

<header>

<a>

Page 25: HTML Semantic Tags

Quiz

What JavaScript library helps you with backward compatibility?A) jQueryB) QC) ModernizrC) My mom’s JavaScript libraryWho gets the most out

of semantic tags?

A) Bill GatesB) W3CC) GoogleD) You

Which is a semantic tag?

<h1>

<section>

<header>

<a>

Page 26: HTML Semantic Tags

Quiz

What JavaScript library helps you with backward compatibility?A) jQueryB) QC) ModernizrC) My mom’s JavaScript library

Which is a semantic tag?

Who gets the most out of semantic tags?

A) Bill GatesB) W3CC) GoogleD) You

<h1>

<section>

<header>

<a>

What site tells me if I can use a HTML5 feature?

A) CanIUse.comB) CanITryItOut.com

Page 27: HTML Semantic Tags

Class Objectives

• Tell why semantic tags are a big deal

• Know when to use semantic tags on your Web page

• Inspect semantic tags to a Web page

• Find which browsers (devices) support semantic tags

• Provide backward compatibility for legacy browsers

Page 29: HTML Semantic Tags

YOUR QUESTIONS

Page 30: HTML Semantic Tags

HTML5, CSS3 PROBruce D. Kyle MCP MCSDPrincipal Instructor@[email protected]

Page 31: HTML Semantic Tags
Page 32: HTML Semantic Tags

BONUS

Page 33: HTML Semantic Tags

How browsers handle unknown elements

• All browsers render unknown elements inline, i.e. as if they had a display:inline CSS rule.

• You probably want it to act like:article, aside, figure, footer, header, hgroup, menu, nav, section {

display: block; }

Page 34: HTML Semantic Tags

Except for IE before IE9

Note: But prior to IE9, IE ignored tags it did not know about. So you may want to use some JavaScript to replace your semantic elements.

<!--[if lt IE 9]><script> var e = ("abbr,article,aside,audio,canvas,datalist,details," + "figure,footer,header,hgroup,mark,menu,meter,nav,output," + "progress,section,time,video").split(','); for (var i = 0; i < e.length; i++) { document.createElement(e[i]); }</script><![endif]-->

Page 35: HTML Semantic Tags

Except for IE before IE9

Note: But prior to IE9, IE ignored tags it did not know about. So you may want to use some JavaScript to create elements.

<!--[if lt IE 9]> <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script><![endif]-->

Or just use Modernizr, which includes html5shiv