Power Features of HTML5: Part 1

1. New Doctype

 
In HTML5 "<!DOCTYPE html>" means "this page is written in HTML5". Unlike earlier versions of HTML, in HTML5 the doctype declaration is case-insensitive. In other words <!doctype html> works as well as <!DOCTYPE html>.
 

2. Figure Element

 
It is often necessary to include images, graphs and compound objects that contain text and images and so on in our Web documents, all of which usually are called figures. HTML 3 attempted to introduce the fig element to represent such constructs; HTML5 reintroduces the idea with the element named figure acting as a semantic element.
 
Code Used
  1. <!DOCTYPE html>  
  2. <html>  
  3. <body>  
  4.     <p>  
  5.         <strong>Starfish or sea stars are echinoderms belonging to the class Asteroidea. The  
  6.             names "starfish" and "sea star" essentially refer to members of this class.</strong></p>  
  7.     <figure>  
  8. <img src="img1.jpg" alt="star fish" width="600" height="600">  
  9. </figure>  
  10. </body>  
  11. </html> 
HTML1.jpg
 
Check
 
HTML2.jpg
 

3. <small> Redefined

 
The <small> element creates subheadings closely related to the logo. It's a useful presentational element; however, that would now be an incorrect usage. The small element has been redefined, more appropriately, to refer to small print. Imagine a copyright statement in the footer of your site; according to the new HTML5 definition of this element; the <small> would be the correct wrapper for this information. The small element now refers to "small print".
 

4. No More Types for Scripts and Links

 
A <script> tag allows scripting language code to be either directly embedded within the document as in the following:
  1. <script type="text/javascript">  
  2.     alert("Hi from JavaScript!");  
  3. </script> 
or, linked to from a Web page: as in the following:
  1. <script type="text/javascript" href="ajaxtcr.js">  
  2. </script> 
A <link> tag specifies a special relationship between the current document and another document. Most commonly, it is used to specify a style sheet used by the document.
  1. <link rel="stylesheet" media="screen" href="global.css" type="text/css" > 
However, the <link> tag has a number of other interesting possible uses, such as to set up navigation relationships and to hint to browsers about pre-cacheable content.
 

5. To Quote or Not to Quote

 
That is the question. Remember, HTML5 is not XHTML. You don't need to wrap your attributes in quotation marks if you don't want to you. You don't need to close your elements. With that said, there's nothing wrong with doing so, if it makes you feel more comfortable.
 
<p class=myClass id=someId> Start
 

6. Spellcheck Attribute

 
HTML5 defines a spellcheck attribute globally for elements. Interestingly, some browsers, such as Firefox, have supported spell checking of form fields and elements in content editing mode using the contenteditable attribute for some time. HTML5 makes this attribute standard. Enabling the spell checking of an element content is a matter of setting the spellcheck attribute to true:
  1. <p spellcheck="true">Spellcheck on: There is a tyyypooo here.  
  2. Did the browser spot it?</p>  

7. Placeholders and Autofocus Attribute

 
This HTML5 attribute specifies a short bit of text to help the user determine what type of information to fill in for a form of control. Likely, the text will be placed in the field and cleared upon focus. Web page authors use the value attribute to populate some text in a form field:
  1. <input type="text" name="firstname" id="firstname" value="Thomas"
Quite often, people put placeholder or advisory text here, like so:
  1. <input type="text" name="middlename" id="middlename" value="Enter your middle name here"
However, using the value attribute in this manner is somewhat inappropriate, because the purpose of the attribute is not to supply instructions for the field's use but rather to supply a potential value for the user to submit to the server. HTML5 introduces the placeholder attribute to be used as in the following:
  1. <input type="text" name="firstname" id="firstname" placeholder="Enter your name here"
HTML5 also introduces the autofocus attribute, which when placed on a field should cause a supporting browser to immediately focus this field once the page is loaded:
  1. <label>Search:<input type="search" name="query" id="searchBox" autofocus></label> 
Also under HTML5, it should be possible to advise the browser to display the autocomplete suggestions provided for fields if similar field names have been used in the past:
  1. <input type="text" name="firstname" id="firstname" placeholder="Enter your name here" autocomplete>. 
Code Example
  1. <!DOCTYPE html>  
  2. <html>  
  3. <body>  
  4.     <form>  
  5.     <input type="text" name="fname" placeholder="First name"><br>  
  6.     <input type="text" name="lname" placeholder="Last name"><br>  
  7.     <input type="submit" value="Submit">  
  8.     </form>  
  9.     <p>  
  10.         <strong>Here see use of Placeholder.</strong></p>  
  11. </body>  
  12. </html> 
HTML3.jpg
 
Check output
 
HTML4.jpg
 

8. Web Storage in HTML 5

 
Before HTML 5 the only way to store information was either by adding it to the Document Object Model (DOM) or by using cookies. But both have some drawbacks.
 
Storing data in HTML is easy to do but it requires JavaScript, and it can only store data as long as the application and browser are open. As soon as the user's session ends, the data is lost. One more thing is that data stored in HTML is visible to everyone.
 
Cookies are limited to around 4KB of data, which is not a lot of space to store information. Plus, cookies are sent with every HTTP request and that can slow down your application. HTML5 local storage provides you with more space that is associated with the user agent and is only transferred to and from the server when the application asks for it.
 
Now first we understand, what is Web Storage?? The answer is Web Storage is a separate API that was originally part of the HTML5 Specification, but now is a separate document in the aegis of HTML5. It is sometimes called Local Storage or DOM Storage depending upon the browser manufacturer. Web Storage allows users to store data in key/value pairs on the user's local machine. This data persists even if the user leaves the application or closes the browser.
 
Note: Web Storage is different from cookies. There are two types of Web Storage as in the following:
  1. Session Storage.
  2. Local Storage.
Local Storage is name/value pairs stored on the local disk. Every site has a separate storage area. The data stored in this area persists even if the user leaves the site or closes the web browser. The data is only available to the domain that added it, and that data is only sent when a client on that domain requests it.
 
When you store data in Web Storage, it will be stored as a string. This means that if you have structured data (such as database information) or integers and floating-point, you need to convert them to strings so that they can be stored in Web Storage. Use parseInt( ) and parseFloat( ) methods to convert yours integers and floats back when you retrieve the data. Local storage is best for storing non-sensitive data that takes up a lot of space.
 
Session storage is name/value pairs that are stored on the local disk for the length of the page session. Session storage will deliver stored data to user agents on the same domain and in the same window as to when the data was stored. After that window closes the stored data is removed. If a new window is opened to the same site, a new instance of session storage is created. Session storage is most useful for temporary data that should be saved and restored if the browser session is accidentally refreshed. But you do not store sensitive data in session storage like local storage. You should check to ensure that the browser supports Web Storage using a function as in the following:
  1. function supportsWebStorage( )  
  2. {  
  3.     Try  
  4.     {  
  5.         Return 'localStorage' in window && window['localStorage'] !== null;  
  6.     }  
  7.     catch (e)  
  8.     {  
  9.         Return false;  
  10.     }  
When using Web Storage, the first thing you do is define a storage object. This tells the user agent whether you're using local storage or session storage.
 
These objects are:
  • Window.localStorage.
  • Window.sessionStorage.

9. The Semantic Header and Footer

 
Previously we used:
 
<div id= "header">
…………
</div>
<div id= "footer">
…………
</div>
 
Divs, by nature, have no semantic structure, even after an id is applied. Now, with HTML5, we have access to the <header> and <footer> elements. The mark-up above can now be replaced with:
 
<header>
…….
</header>
<footer>
……...
</footer>
 
In detail, HTML5 documents may contain a header element, that is used to set the header section of a document and thus often contains the standard h1 to h6 heading elements:
  1. <header>  
  2. <h1>Welcome to the Future World of HTML5.</h1>  
  3. <h2>Magical World</h2>  
  4. </header> 
Similarly, a footer element is provided for document authors to define the footer content of a document, that often contains navigation, legal, and contact information:
  1. <footer>  
  2. <p>Copyright</p>  
  3. </footer> 
Code Example
  1. <!DOCTYPE html>  
  2. <html>  
  3. <head>  
  4.     <meta http-equiv="Content-Type" content="text/html; charset=utf-8">  
  5.     <title>HTML5 header and footer example</title>  
  6. </head>  
  7. <body>  
  8.     <header>  
  9. <h1>Welcome to the Future World of HTML5.</h1>  
  10. <h2>Magic World</h2>  
  11. </header>  
  12.     <p>  
  13.         See example</p>  
  14.     <p>  
  15.         Powerful language</p>  
  16.     <footer>  
  17. <p>Coyright.</p>  
  18. </footer>  
  19. </body>  
  20. </html> 
HTML5.jpg
 
Check
 
HTML6.jpg
 

10. Required Attribute

 
By adding it to a form field, the browser requires the user to enter data into that field before submitting the form. This replaces the basic form validation currently implemented with JavaScript, making things a little more usable and saving us a little more development time. Required is a Boolean attribute.
  1. <input type="text" name="firstname" id="firstname" required> 
Code Example
  1. <!DOCTYPE html>  
  2. <html>  
  3. <body>  
  4.     <form>  
  5.     Email:  
  6.     <input type="text" name="email" required>  
  7.     <input type="submit">  
  8.     </form>  
  9.     <p>  
  10.         <strong>Example of Required Attribute</strong></p>  
  11. </body>  
  12. </html> 
HTML7.jpg
 
Check Output
 
HTML8.jpg
 

11. Video Support

 
To insert Video, use a <video> tag and set its src attribute to a local or remote URL containing a playable movie. You should also display playblack controls by including the controls attribute, as well as set the dimensions of the movie to its natural size.
  1. <video src="2012.mp4"  
  2. width="480" height="360" controls>  
  3. <strong>HTML5 video element</strong>  
  4. </video>
Code Example
  1. <!DOCTYPE html>  
  2. <html>  
  3. <body>  
  4.     <video width="480" height="360" controls>  
  5. <source src="2012.mp4" type="video/mp4">  
  6. <source src="2012.ogg" type="video/ogg">  
  7. Your browser does not support the video tag.  
  8. </video>  
  9. </body>  
  10. </html> 
Check this
 
HTML9.jpg
 

12. Audio Support

 
HTML5's audio element is quite similar to the video element. The element should support common sound formats such as WAV files:
  1. <audio src="coffee music.wav"></audio> 
You also have autobuffer and autoplay attributes for the audio element.
  1. <audio controls autobuffer autoplay>  
  2. <source src="Coffee music.ogg" type="audio/ogg">  
  3. <source src="Coffee music.wav" type="audio/wav">  
  4. </audio> 
Code Example
  1. <!DOCTYPE html>  
  2. <html>  
  3. <head>  
  4.     <meta http-equiv="Content-Type" content="text/html; charset=utf-8">  
  5.     <title>HTML5 audio</title>  
  6. </head>  
  7. <body>  
  8.     <h1>  
  9.         Simple Audio</h1>  
  10.     <h2>  
  11.         wav Format</h2>  
  12.     <audio src="coffee music.wav" controls></audio>  
  13.     <h2>  
  14.         ogg Format</h2>  
  15.     <audio src="coffee music.ogg" controls></audio>  
  16.     <h2>  
  17.         Multiple Formats and Fallback</h2>  
  18.     <audio controls autobuffer autoplay>  
  19. <source src="coffee music.ogg" type="audio/ogg">  
  20. <source src="coffee music.wav" type="audio/wav">  
  21. </audio>  
  22. </body>  
  23. </html> 
Check
 
HTML10.jpg
 

13. Header Group <hgroup>

 
In some cases, a page, article, or section may require more than one heading, such as where you have a title and a subtitle. This HTML5 element represents a grouping of heading elements (h1-h6).
 
Code Example
  1. <!DOCTYPE html>  
  2. <html>  
  3. <head>  
  4.     <meta http-equiv="Content-Type" content="text/html; charset=utf-8">  
  5.     <title>hgroup Example</title>  
  6. </head>  
  7. <body>  
  8.     <header>  
  9. <hgroup>  
  10. <h1>Welcome to the HTML5 World</h1>  
  11. <h2>Header Group</h2>  
  12. </hgroup>  
  13. <nav>  
  14. <ul>  
  15. <li><a href="#">Link</a></li>  
  16. <li><a href="#">Link</a></li>  
  17. <li><a href="#">Link</a></li>  
  18. <li><a href="#">Link</a></li>  
  19. </ul>  
  20. </nav>  
  21. </header>  
  22.     <hgroup>  
  23. <h1>Section head</h1>  
  24. <h2>A subhead</h2>  
  25. </hgroup>  
  26.     <p>  
  27.         This is the best way</p>  
  28.     <p>  
  29.         Best part of HTML5</p>  
  30.     <footer><p>HTML 5</p></footer>  
  31. </body>  
  32. </html> 
Check  
 
HTML11.jpg


Similar Articles