Day1 Html5 Intro
Day1 Html5 Intro
HTML5 ~= HTML + CSS + JS
HTML5 is a cooperation between the World Wide Web Consortium
(W3C) and the Web Hypertext Application Technology Working
Group (WHATWG).
WHATWG was working with web forms and applications, and W3C
was working with XHTML 2.0. In 2006, they decided to
cooperate and create a new version of HTML.
JavaScript
Reduce the need for external plugins (like Flash)
playback
Better support for local offline storage
New content specific elements, like
We should use article for content that we think it can be distributable. Just like
news or blog entry can we can share in RSS feed
While the content of the <figure> element is related to the main flow,
its position is independent of the main flow, and if removed it should
not affect the flow of the document
To specify HTML5 as the document type, add <!DOCTYPE html> at the
beginning of the file.
All the HTML coding in a document (except the DOCTYPE) is enclosed within a
two-sided <html> tag.
The <html> and </html> tags enclose the <head> and <body> sections.
The <head> area contains the page title (<title>) and any <meta> tags.
The <body> area contains all the displayable text for the page.
Enclose each paragraph in a two-sided <p> tag. Most browsers add space
between paragraphs when displaying the page.
To create a line break without starting a new paragraph, use the one-
sided <br> tag.
When coding for XHTML, end one-sided tags with a space and a slash ( /). The
space is required for recognition in HTML, and the slash is necessary for
recognition in XHTML.
Use <meta> tags in the <head> section to indicate keywords and the
document encoding language.
Use the <title> and </title> tags to enclose the text that should appear in the
browser’s title bar. Place these in the <head> section of the file.
HTML 5 Forms
HTML5 web forms have introduced new form elements, input types,
attributes, and other features. Many of these features we’ve been using in
our interfaces for years: form validation, combo boxes, placeholder text,
and the like. The difference is that where before we had to resort to
JavaScript to create these behaviors, they’re now available directly in the
browser; all you need to do is set an attribute in your markup to make them
available.
HTML5 not only makes marking up forms easier on the developer, it’s also
better for the user. With client-side validation being handled natively by the
browser, there will be greater consistency across different sites, and many
pages will load faster without all that redundant JavaScript.
<form> / <input> autocomplete Attribute
The autocomplete attribute specifies whether a form or input
field should have autocomplete on or off. When autocomplete is
on, the browser automatically complete values based on values
that the user has entered before.
<!DOCTYPE html>
<html><body>
<form action="demo_form.asp" autocomplete="on">
First name:<input type="text" name="fname"><br>
Last name: <input type="text" name="lname"><br>
E-mail: <input type="email" name="email"
autocomplete="off"><br>
<input type="submit">
</form></body></html>
<!DOCTYPE HTML>
<html>
<body>
<form action="/cgi-bin/html5.cgi" method="get">
Enter Department : <input type="text" name="dept" />
Enter email : <input type="text" name="newinput" autofocus />
<input type="submit" value="submit" />
</form>
</body>
</html>
<input> formaction Attribute
The formaction attribute specifies the URL of a file that will
<form> element.
Note: The formaction attribute is used with type="submit" and
type="image“
<form> element.
Note: The formmethod attribute can be used with type="submit"
and type="image".
<input> list Attribute
Data lists are currently only supported in Firefox and Opera, but
We obtain our drawing context by calling the getContext method and passing it
the string "2d", since we’ll be drawing in two dimensions:
Example: demo1.html
Output
Output
HTML 5 Web Storage
The Web Storage API defines a standard for how we can save simple data locally on a user’s computer
or device. Before the emergence of the Web Storage standard, web developers often stored user
information in cookies, or by using plugins. With Web Storage, we now have a standardized definition
for how to store up to 5MB of simple data created by our websites or web applications. Better still,
Web Storage already works in Internet Explorer 8.0!
Web Storage is a great complement to Offline Web Applications, because you need somewhere to store
all that user data while you’re working offline, andWeb Storage provides it.
Local Storage
Unlike session storage, local storage allows us to save persistent data to the user’s computer, via the
browser. When a user revisits a site at a later date, any data saved to local storage can be retrieved .
Local storage can at first glance seem to play a similar role to HTTP
cookies, but there are a few key differences. First of all, cookies are
intended to be read on the server side, whereas local storage is only
available on the client side.
<script type="text/javascript">
if( sessionStorage.hits ){
sessionStorage.hits = Number(sessionStorage.hits) +1;
}else{
sessionStorage.hits = 1;
}
document.write("Total Hits :" + sessionStorage.hits );
</script>
<p>Refresh the page to increase number of hits.</p>
</body>
</html>
<!DOCTYPE HTML>
<html>
<body>
<script type="text/javascript">
if( localStorage.hits ){
localStorage.hits = Number(localStorage.hits) +1;
}else{
localStorage.hits = 1;
}
document.write("Total Hits :" + localStorage.hits );
</script>
<p>Refresh the page to increase number of hits.</p>
<p>Close the window and open it again and check the result.</p>
</body>
</html>
In Chrome browser
Menu -> Tools -> Developer Tools, Click on the "Resources" tab and you can
select "Local Storage" in the side tree.
OR
Right click on the browser and select Inspect Element. Select Resources tab
and then click on the local storage item. We can see the user selected data
stored in the form of key/value pairs. Demo_local_storage
Setup the basic HTML document structure (i.e.
doctype, html, head, meta, title, body, footer,
article etc.)
Your task is to design the form elements used to create the form shown in
Figure-1 in the next slide.
You must use the HTML5 tags that are appropriate to replicate the form and
fulfill all the specifications listed.
Code the form with autocomplete active.
Given the image shown in Figure 1, it is easy to see that two field sets are
used to create the main structure of the form. Your task is to create the field
sets, including the names Customer Info and Books. Don't worry about the
content fields for the moment.
The Name field you create should have autofocus, placeholder text, and be
required.
The Telephone field should have placeholder text, a pattern to restrict entry,
and be required.
The Email address field should have placeholder text and allow multiple
entries. This field should also be required.
The Books field should have a data list. You can select the content you would
like to list.
The Quantity (Maximum 5) field should have a minimum value of 1 and a
maximum value of 5.