FU_Lecture_HTML5_01
FU_Lecture_HTML5_01
Agenda
Embedded Media
Canvas
Offline Storage
Geo-Location
New Selector
Decorations
<!DOCTYPE html>
Simplified Encoding
<meta charset="utf-8">
Simplified Script, Style, and Link elements
<link rel="stylesheet" href="site.css" />
<style> h1 { color: red; } </style>
<script src="common.js"></script>
New or Enhanced Functions In HTML5
• Improved semantics • Video and audio
• Forms • Web sockets
• Canvas drawing • Geolocation (not strictly part of
HTML5, but being developed in
• Drag and drop conjunction with it)
• Local storage
• History
• Page to page messaging
• Microdata
• Desktop notifications
New or Enhanced Functions In HTML5
• HTML5 is not just about interactive creations with JavaScript APIs and
video/audio coolness. There are more than 20 new elements designed to
help you author your webpages, adding semantics to deliver more
accessible, reusable content.
• Later on we’ll examine new HTML5 form controls and multimedia
elements, but for now we’ll focus on the basics of creating a basic website
template with the new elements.
• The basic page structure as defined by HTML5 appears on the next page
Basic Page Structure
<header>
<nav>
<aside>
<article>
<section>
<section>
<section>
<footer>
New Structural Elements In HTML5
• We’ve already seen some basic HTML5 pages in the introductory sets of
notes, we’ll do a quick review of the basic markup in an HTML5
document and clarify the differences from the older versions and what is
and is not required in HTML5.
• The doctype should be the very first line in an HTML document. Called a
Document Type Definition (DTD), the doctype is a web standard’s
requirement and it tells the browser how to process the document, which is
why it must be the first thing in HTML document.
• The next page shows the old style XHTML doctype and the new HTML5
doctype.
New Structural Elements In HTML5
XHTML Strict 1.0 doctype:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
HTML5 doctype:
<!doctype html>
New Structural Elements In HTML5
The first line you should include inside the head of an HTML5 document is the
charset declaration, which tells the browser how the document should be
interpreted; in this case, you want to send it an HTML document.
In XHTML, this looked like this:
<meta http-equiv=“Content-Type” content=“text/html”; charset=utf-8”>
In HTML5, it is again, much simpler, and looks like this:
<meta charset=“utf-8” />
New Structural Elements In HTML5
HTML5 helps you to reduce the amount of markup from your pages, and calls to
JavaScript and CSS links are also reduced in size.
In XHTML, they looked like this:
<script type=“text/javascript” src=“myscript.js”> </script>
<link rel=“stylesheet” type=“text/css” href=“mystyles.css” />
In HTML5, they’re again much simpler, and look like this:
<script src=“myscript.js”></script>
<link rel=“stylesheet” href=“mystyles.css” />
New Structural Elements In HTML5
You can markup in either lowercase, or uppercase, or a combination of the two.
You can markup with either quotation marks on attribute values, or omit
quotation marks on attribute values, or a combination of the two.
For void elements, such as a <link> element, you can omit the closing slash or
include it.
All below are equivalent:
<link rel=“stylesheet” href=“mystyles.css” />
<LINK REL=“STYLESHEET” HREF=“MYSTYLES.CSS” />
<liNK reL=“styleSHEET” href=mystyles.css>
New Structural Elements In HTML5
In 2005, Google analyzed more than 1 billion web pages to find out what
class names were being used by developers and web authors. This provided
the basis for the new elements in HTML5.
The following are the 20 most popular class names at the time:
footer menu Title Small Text
Content Header Nav Copyright Button
Main Search Msonormal Date Smalltext
Body Style1 Top White link
Although several of these items are presentational (for example, white, style1,
msnormal), the others make up the elements included in the HTML5
specification.
New Structural Elements In HTML5
So why use these new elements?
HTML5 allows you to give your content semantic meaning, so, for example, if
you have navigation on your page, you can use the nav element because that
element provides meaning to its content.
As an example, let’s start at the top of a “typical” web page. The header element
is often the first thing on a web page, and it usually contains things like a logo,
the website name, or the main site navigation.
Things like a search form or a table of contents are also often included in the
header element.
New Structural Elements In HTML5
The HTML5 specification states that the <header> element can contain
navigation aids, but it is also possible for the navigation aids to be placed outside
of the <header>.
You are also not restricted to just a single <header> elements per page, and it
does not have to be at the top of a page.
You cannot place a <header> inside a <footer>, <address>, or another <header>
element.
The markup example on the next page illustrates this concept.
New Structural Elements In HTML5
The <hgroup> element allows you to add further information to your
<header> elements.
This element is used to group more than one related h1-6 headings. It can
contain only <h1>…<h6> elements. If your site has a subheading or a
tagline, you would use this element to group them together.
Although it is a useful grouping option, the <hgroup> element is primarily
intended to tell the document outline (we’ll learn about this later) which of
the headings is the most important. In the example, on the next page, the
document outline will exclude all headings within the hgroup except the
highest one, which in this case, is the h1 heading.
As you can see in the markup, the h2 heading is relevant to the h1 heading,
and so on, so the use of the hgroup makes sense. If you have a single
heading element, there would be no need to use the hgroup.
New Structural Elements In HTML5
The <nav> element, as you might expect from it name, is for navigational
content. It is used to link to other pages within the site or to other parts of
the page, like a table of contents, for example.
The most common use of a <nav> element is for the main navigation on a
website. It is common practice to use an unordered list to code navigation
content.
The following page illustrates both the traditional way of marking up
navigation and the way to do this in HTML5. Notice that there isn’t much
difference between the two, but it is profound from a semantic point of
view.
New Structural Elements In HTML5
<ul id=“nav”>
<li><a href=“#”>Home</a> </li>
<li><a href=“#”>About</a> </li>
<li><a href=“#”>News</a> </li>
<li><a href=“#”>Contact Us</a> </li>
</ul>
<nav>
<ul>
<li><a href=“#”>Home</a> </li>
<li><a href=“#”>About</a> </li>
<li><a href=“#”>News</a> </li>
<li><a href=“#”>Contact Us</a> </li>
</ul>
</nav>
<header>
<nav>
<section>
<section> <aside>
<footer>
<article>
<header>
<nav>
<section>
<section> <aside>
<footer>
New Structural Elements In HTML5
• The next few pages present an example webpage that utilizes all of the
new HTML5 structural elements that were presented in this set of notes.
• The page that is created represents a layout for a news page. It includes
some basic CSS to position the various elements, but I didn’t include
anything too advanced as far as the CSS is concerned; we’ll get more into
that later.
• Since the markup is fairly long, I’ve abbreviated some of the more
repetitive parts here. The full markup is available on the course website.