Professional Documents
Culture Documents
Slide 1
HTML5 Features
HTML5 features
Slide 2
Unit objectives
After completing this unit, you should be able to:
• List new elements in HTML5
• Describe HTML5 structural elements
– section, article, header, footer, figure, figcaption
• Describe the attributes of the HTML5 input element
– input type attributes tel, email, datetime, number, range, color
This unit covers the new structural and form features of HTML5.
There is also a hands-on lab exercise available to reinforce the concepts that are presented
in this unit.
After completing this unit, you should be able to:
List new elements in HTML5
Describe HTML5 structural elements - section, article, header, footer, figure, and
figurecaption
Describe the attributes of the HTML5 input element - tel, email, datetime,
number, range, and color
Slide 3
Topics
• New HTML5 tags
• HTML5 structural elements
• HTML5 input elements and data attributes
Slide 4
Slide 5
There are many elements that are introduced in HTML5. The table shows some of the new
HTML5 elements. Notice that the new HTML5 element tags have intuitive names, such as audio
that is used to embed sound content, and canvas that is used for graphical content. Not all of
these new element tags are covered in the lecture unit, so take a moment to read through the
table.
Slide 6
<!-- --> Comments in source that are not displayed in the browser
This table shows more of the elements that were added in HTML5.
The last tag in the table is the comments tag.
Comments in HTML can assist the developer to explain what the code does. The browsers do not
display these comments.
Slide 7
<!--[if
<!--[if lt
lt IE
IE 9]>
9]>
<script
<script
src="//html5shim.googlecode.com/svn/trunk/html5.js">
src="//html5shim.googlecode.com/svn/trunk/html5.js">
</script>
</script>
<![endif]-->
<![endif]-->
Slide 8
Slide 9
In a division-based layout, each part of a page that you want to format differently is separated into
its own division.
Think of the natural divisions into which you can divide the page that is shown on the slide.
These divisions might include the page title, a banner with selectable tabs, an area for the image,
and further blocks for text and thumbnail images.
The <div> tag is not new in HTML5, but is a good starting point for laying out a page or
document. Then, you can use some of the other new HTML5 structural elements inside the <div>
tag.
Most HTML elements have a semantic meaning. In other words, the element describes either the
function or the type of data that is contained within. For example, a <p> element is a paragraph
that usually contains some text.
In contrast, the <div> tag has no innate semantic meaning besides the logical grouping of the
content.
Slide 10
A number of new structural elements are introduced in HTML5. You can use these dedicated
elements to mark up your website, rather than using the generic <div> or <span> elements.
An <article> defines a block of code that can be distinguished from the rest of the page.
A <section> defines a logical separation in the document such as the numbered chapters of an
online manual.
A <header> element is used to group the headers for a page.
The <footer> defines the area at the bottom of the page.
You can continue to use HTML4 and earlier generic elements, such as paragraphs, within the
new HTML5 elements.
10
Slide 11
This code example shows some of the new HTML5 structural elements.
Here, the <article> element is used to create an online news report. The <article> includes a
header.
Within the <article>, the page is marked up into sections that have their own headers. The page
also includes a <footer> element.
11
Slide 12
The <aside> tag is used to provide additional information that is related to the main discussion.
The aside tag lets you extract and display further content or go to additional resources without
detracting from the main discussion.
The <figure> tag defines a self-contained element that is referred to from the main content. The
<figure> element can be used to embed graphics, images, or code sections.
The <figurecaption> tag defines the caption for the contents of the <figure> element.
12
Slide 13
Navigational elements
• <nav>
– An area where navigational links are placed into
<body>
<body>
<nav>
<nav>
<div
<div class="menu">
class="menu">
<a
<a href="#">Home</a>
href="#">Home</a>
<a
<a href="about.html">About</a>
href="about.html">About</a>
<a
<a href="register.html">Register</a>
href="register.html">Register</a>
<a
<a href="#">Sign
href="#">Sign in</a>
in</a>
</div>
</div>
</nav>
</nav>
<h1>Pages
<h1>Pages for
for You</h1>
You</h1>
...
...
Websites typically have sections that are dedicated to navigational links that go to these sites or
for moving between pages of a single application. In HTML5 syntax, these navigational links are
placed inside a <nav> tag.
The <nav> tag is a convenience tag for grouping navigational links in a web page.
13
Slide 14
14
Slide 15
list No No No No 11.0
The intent of the new HTML5 input attributes is to provide a number of different input types that
are self-validating.
During the transitional period of adoption of the HTML5 specification, support for some of the
built-in features might be lacking in some browsers.
You still need custom JavaScript to support input validation in older browsers. When modern
browsers support HTML5, there is less of a need for custom validation scripts on the client, as
these fields are automatically validated according to their input attributes.
15
Slide 16
The <input type="color" /> attribute is supported by the Opera browser. In Opera, the input field
shows as a color drop-down list.
In non-supporting browsers, this input type is displayed as a regular text input field into which the
user might type a valid color name or color code.
16
Slide 17
The <input type="date" /> attribute is a date control (year, month, day) with no time zone.
The example shows the input type="date" field as it is seen in Firefox 3.6.25. It is displayed as a
normal text input field in this browser, since this attribute type is not supported in this particular
version of Firefox.
17
Slide 18
18
Slide 19
The datetime-local attribute provides input for a date and time (year, month, day, hour, minute,
second, fraction of a second) with no time zone.
The datetime-local input field is displayed as a drop-down calendar in the Opera browser. The
time field displays as a spinner control.
19
Slide 20
The <input type="email" /> attribute is supported in the Google Chrome and the Opera browsers.
The email input field is displayed as a regular text input field in all other browsers.
Reverting to <input type="text" /> for those browsers that do not support the email attribute is an
example of the "graceful degradation" in the way non-supporting browsers handle this input
attribute.
Graceful degradation means that your website continues to operate even when viewed with
browsers in which not all features are supported.
20
Slide 21
The <input type="text" list="some_list" /> is an input field for those browsers that support the
<datalist> feature.
You can fill the list by nesting <option> elements inside the <datalist> tag.
On this slide, these options are the types of fruits listed in the drop-down list.
A complete code example is shown in the student notebook that accompanies this course.
You can provide compatibility with browsers that do not support the <datalist> tag by surrounding
the <option> tags with a <select> tag.
Browsers that understand the <datalist> tag ignore the surrounding <select> elements and use
what is in the <option> tags.
Non-supporting browsers do not recognize the <datalist> tag. Instead, these browsers fallback to
showing what they see as a standard <select> tag.
With the autocomplete feature, you can type part of a list option in the input field. For example,
“app” if one of the selectable options is “apples” or “or” if one of the selectable items is “oranges”.
21
Slide 22
The <input type="number" /> takes a numeric value as input. You can optionally specify the
minimum and maximum values.
The example shows the number selector in the Chrome browser. Only the numbers between the
minimum and the maximum are available for selection.
22
Slide 23
23
Slide 24
The differences between <input type="search" /> and <input type="text" /> are mostly in style.
WebKit-based browsers return a history of recently searched text strings. The search input field
on the Safari browser has rounded corners.
24
Slide 25
The input type="tel" pattern="[parameters]" attribute expects a telephone number as input. On its
own, the <input type="tel" /> provides nothing more than a text entry field in the browsers.
It does not enforce numeric only input since many telephone numbers include other characters,
such as the plus sign and hyphens.
You need to supply your own pattern matcher if you want the browser to validate the telephone
number.
25
Slide 26
The URL attribute is used to validate that the user typed in a properly formatted URL or web
address.
The Opera browser adds a prefix of http:// to any URL that does not include a protocol.
26
Slide 27
Placeholder text is used to provide hints of what the input text format looks like.
The placeholder fills the input text field with the example values in a lighter shade of text.
The form does not submit the placeholder text value if the input text is not overwritten.
27
Slide 28
28
Slide 29
What happens if browser-based validation is not supported for these input attributes?
There are a number of choices available to you to perform validation in browsers that do not
support the new HTML5 input attributes.
You can use prebuilt script libraries for fallback input field validations, or commercially
available products, like Modernizr.
You can use open source shim libraries for field validation.
You can use Dojo and JQuery libraries to abstract some of the browser differences away
from the developer.
You can include your own custom JavaScript validation for fields.
You can code client-side validation that is attached to the form submit event handler to
validate all the fields on the form when the form is submitted.
You can assume that more browsers will support these features over time, and leave all
final validation to server-side processing.
29
Slide 30
Unit summary
Having completed this unit, you should be able to:
• List new elements in HTML5
• Describe HTML5 structural elements
– section, article, header, footer, figure, figcaption
• Describe the attributes of the HTML5 input element
– input type attributes tel, email, datetime, number, range, color
30