Html5 Notes
Html5 Notes
Html5 Notes
New HTML5:
Some of them include the header, footer, section, article, aside, nav and so on.
let's learn about the most commonly used structural/semantic tags - header, section, nav and
footer that help in organizing the content on web pages and make the code more readable.
Structural Tags
Tag Description
<details> Represents a widget from which the user can obtain additional information or controls on-
demand.
<head> Defines the head portion of the document that contains information about the document.
Metadata Tags
Tag Description
<base> Defines the base URL for all linked objects on a page.
<link> Defines the relationship between the current document and an external resource.
<style> Inserts style information (commonly CSS) into the head of a document.
Form Tags
Tag Description
Formatting Tags
Tag Description
<bdi> Represents text that is isolated from its surrounding for the purposes of bidirectional text
formatting.
<ins> Defines a block of text that has been inserted into a document.
<rp> Provides fall-back parenthesis for browsers that that don't support ruby annotations.
List Tags
Tag Description
Table Tags
Tag Description
<tbody> Groups a set of rows defining the main body of the table data.
<thead> Groups a set of rows that describes the column labels of a table.
Scripting Tags
Tag Description
<noscript> Defines alternative content to display when the browser doesn't support scripting.
<canvas> Defines a region in the document, which can be used to draw graphics on the fly via scripting
(usually JavaScript).
<embed> Embeds external application, typically multimedia content like audio or video into an HTML
document.
<noframes> Defines an alternate content that displays in browsers that do not support frames.
<source> Defines alternative media resources for the media elements like <audio> or <video>.
2 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
If so, then you will surely love the new doctype by HTML5, which looks
simple, clean and easy to memorize. Here it is:
1 <!DOCTYPE html>
2. Getting Simple – No
more Type attribute
for script and link
This is how you define your <script> and < link> tags in HTML4.
In HTML5, you don’t have to specify the MIME type value for
your <script> and <link> tag. All scripts and styles are assumed to
be type="text/javascript" and type="text/css" . You can simply write
your code as:
2 <script src="script.js"></script>
#Tips: HTML5 has added new attribute for <script> tag, which
is async. With this attribute, the script will be executed asynchronously
as soon as it is available.
3. Semantic Structure
– header , footer & nav
Previously, we added an id or classes to HTML structure and perhaps,
it can be serve as pseudo-semantic structure. But by nature, div have
no semantic structure even after added an id .
1
<div id="header">
2 ...
3 </div>
4 <div id="nav">
5 <ul>...</ul>
</div>
6
<div id="footer">
7
8 ...
9 </div>
1
<header>
2
...
3 </header>
4 <nav>
5 <ul>...</ul>
6 </nav>
<footer>
7
...
8
</footer>
9
4. Semantic Structure
– article vs section
HTML5 also offers new <article> and <section> tags to help us create
semantic content.
1 <section>
2 ...
3 </section>
1 <article>
2 ...
3 </article>
=== Find out more about HTML5 <article> and <section> tags from
links below! ===
http://oli.jp/2009/html5-structure1/ ( div vs section vs article )
http://www.iandevlin.com/blog/2011/04/html5/html5-section-or-article
1 <form id="myform">
2 Name: <input name="name" required placeholder="Your name" pattern="[A-z]{7}" />
3 <br/>
10 <br/>
12 </form>
13
By the way, you can always check the full list of new HTML5 input
types and attributes here.
6. HTML5 Canvas
The most exciting feature, HTML5 <canvas> tag allows us to render 2D
shapes or graphics on web page with help of JavaScript. Moreover,
we’re able to create an animation using HTML5 Canvas.
The HTML below shows a simple HTML5 Canvas declaration and use
JavaScript to draw a blue rectangle on it.
1
<canvas id="myCanvas" width="200" height="200"></canvas>
2
3 <script>
4 var c=document.getElementById("myCanvas");
5 var ctx=c.getContext("2d");
6 ctx.fillStyle="#0000FF";
ctx.fillRect(0,0,150,150);
7
</script>
8
1 <audio controls="controls">
</audio>
5
</audio>
5
1 <div contenteditable="true">
3 </div>
1 <script>
2 localStorage.variableName = "value";
3 alert(localStorage.variableName);
4 localStorage.removeItem("variableName");
5 alert(localStorage.variableName);
</script>
6
The localStorage stores the data with no time limit, which means the
data can be accessible at anytime and any windows/tabs (with some
conditions like same domain and same browser) even if the browser is
restarted.
1 <script>
2 sessionStorage.variableName = "value";
3 alert(sessionStorage.variableName);
4 sessionStorage.removeItem("variableName");
5 alert(sessionStorage.variableName);
</script>
6
1 <!--[if lt IE 9]>
2 <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
3 <![endif]-->
Simply include this script in the <header> tag and you will be able to
style the HTML5 elements in IE.
You can create very promising animations or even interactive games using Canvas.
Modernizr
Modernizr is a cool library that tests and detects browser support for a particular feature
WebStorage API
Cache API
HTML5 presents application cache. In other words, a web application is cached with the
help of a manifest file, to make the application accessible without an internet
connection.
Web Worker
Web Workers offer uncomplicated ways for web content to run scripts in background threads
without affecting the performance of the page.
Geolocation API
A lot of applications and websites include location-aware features like finding local businesses
or showing users location on a map. Geolocation API helps in enabling such features.
File API
HTML5 ultimately offers a standard way to communicate with local files, through the File API
specification. Here, File API is utilized to generate a thumbnail preview of images while the
images are being uploaded, verify uploads mime type matches its file extension or restrict the
size of an upload.