HTML5 is the fifth revision of the well-known and loved markup language. There are many new features and abilities that HTML5 has to offer and this post will get you familiarized with them. I will not go into in-depth detail about every aspect of HTML5, but I will get you familiarized with its key aspects; after all, this is only an introduction to HTML5.
The New HTML Standard
Within HTML5 you will find new elements, new attributes, full CSS3 support, video and audio, 2D/3D graphics, local storage, local SQL databases and web applications to name a few things. Basically what this means is that HTML5 is packed with awesome features that are going to make life easier for developers and, therefore, also for users.
The developers of HTML5 decided that things didn’t need to get more complex, so they decided on a very simple and minimal document approach. Below you’ll find that this is all the code necessary to create an HTML5 document. That is it. What makes this documentation amazing is that its simplicity doesn’t require you to worry that you have the right DOCTYPE or the right anything else.
< !DOCTYPE html> <html> <head> <title> </title> </head> <body> </body> </html>
HTML 4 became a standard in 1999 – that’s a very long time ago. Unfortunately, that has also been too long as so many things have changed in the way the web is built and used. Today, many HTML 4 elements are either obsolete or used in the way they were not intended to be used. To make things easier for everyone HTML5 has done away with rid the following elements:
However, it has also added a bunch more. Here are some examples of the new elements:
The article tag is a little bit self-explanatory. It is to contain independent and self-contained information – meaning that the content can stand on its own and make sense on its own. An article or a post on a blog would be a perfect example. You can have multiple article tags within one page.
<article> <h1>Web typography trends in 2013</h1> <p>From a user's perspective web-safe fonts were great but from a designer's perspective it was a creative disaster.</p> </article>
<figure> and <figcaption>
The figure tag is responsible for content such as images, illustrations or diagrams while figcaption, like the name suggests, provides a caption to the figure. The caption can be placed before or after the image within the figure tag. Once again figure is a self-contained element which means that if it is removed it will not affect the comprehension of the remaining content. Yes, images within the figure tag are related to the overall content of the page but – like I said – they are not crucial to it.
<figure> <img src="myIMG.png" alt="NYC Skyline" width="300" height="200"/> <figcaption>Fig1. - A paronamic view of NYC's skyline at night.</figcaption> </figure>
The hgroup tag is used to group headings – it should only be used to group h1 through h6 and nothing else. It is a very SEO friendly element as it clearly showcases the headings form the particular section. Of course, you are free to have as many hgroups as you like but I wouldn’t recommend it if you are SEO conscious. The hgroup tag can be used on one or more headings.
<hgroup> <h1>Web typography trends in 2013</h1> <h2>by Paula borowska</h2> </hgroup> <p>From a user's perspective web-safe fonts were great but from a designer's perspective it was a creative disaster.</p><p> </p>
<header> and <footer>
The header element is used to specify the header of either the page or a section which is why you can have multiple header tags within one page. At the same time the footer element is playing a similar role as it is to be treated as the footer section of the whole document or a section. You can have multiple footers per page as well.
<article> <header> <h1>Web typography trends in 2013</h1> <p>Published Match 23, 2013</p> </header> <p>From a user's perspective web-safe fonts were great but from a designer's perspective it was a creative disaster.</p> </article> </pre> <pre><code><footer> <p>Copyright Paula Borowska</p> <p>Published Match 23, 2013</p> </footer>
The nav tag is also one of the intuitive ones as it is an element dedicated to navigation links. It is not supposed to be used by every possible link, but navigation links such as in the a page’s main/top navigation or footer navigation links.
<nav> <a href="#/">Home</a> <a href="#">About</a> <a href="#">Contact</a> </nav>
The code below is taken straight from w3schools examples and it will create a diagonal black line within the canvas.
<canvas id="myCanvas" width="200" height="100" style="border:1px solid #d3d3d3;"> Your browser does not support the HTML5 canvas tag.</canvas> <script> var c=document.getElementById("myCanvas"); var ctx=c.getContext("2d"); ctx.moveTo(0,0); ctx.lineTo(200,100); ctx.stroke(); </script>
Video and Audio
Neither video nor audio is new to HTML5 however, controls of both audio and video are. What HTML5 is doing is providing a standard for showing video and playing audio. They alleviate the need for a plug in and provide typical controls such as pause and play. Please keep in mind that it is a good idea to define width and height for videos as there is no ‘reserved’ space, if you will, for when the video is loading and therefore the layout shifts when it changes form the video not being there and for when it is actually there once loaded. Lastly, for both video and audio you can have multiple sources linked to different files. They will play in order with the typical hierarchy ruling that the first file is played first.
<video width="400" height="300" controls> <source src="movie.mp4" type="video/mp4"/> </video> <audio controls> <source src="song.mp3" type="audio/mpeg"/> </audio>
New Input Types and Form Attributes
HTML5 has made a big improvement on form elements. There are two big things being done to them, one of them being new input types and the other is new form attributes. With input types what happens is that the input is customized to the information required. For instance, if you specify the input to be date type the input will anticipate a date and throw an error otherwise. Additionally, on smartphones, the appropriate UI elements will show; if you specify for the input type to be a number on a smartphone you will only see number keys. Here is a list of all new input types:
<input type="email" name="usremail"/> <input type="range" name="points" min="1" max="10"/> Quantity (between 1 and 5): <input type="number" name="quantity" min="1" max="5"/> <input type="date" name="bday"/> <input type="date" name="bday"/> <input type="url" name="homepage"/>
On top of that, there are new attributes for forms. For the form element you can have an attribute of:
While for the input element you can add an attribute of:
- height and width
- min and max
- pattern (regexp)
I know, that is a lot! But as with the input types, the attributes will help make the form filling experience better for the users – if you choose to include the awesome attribute of course. Most of the attributes are self explanatory. Some of them are more useful than others and will be more used by developers then others. I suggest just taking a good look at the list and seeing what can be handy for you and your visitors and just include it. Some of these attributes can come in very handy.
<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>
That is it!
Yup, that sums it up. HTML5 is a very interesting language and has many new fun features. Personally, I believe that most of the features are more useful than confusing and you should truly take your time to learn about them in greater detail. HTML5 is going forward in helping both developers and users to have a much simpler and easier experience which is the only reason you need in order to use this language. (Okay fine, it is also very hip to use it too!)