HTML5: Quick Introduction
So, if you’re wondering what you have to do in order to convert your old HTML4 web application to HTML5. Well, the W3C working group have made it easy for us, in the way that you don’t have to code again all your application or learn things you already know. But of course, you can improve you application so it can fit nicely into the HTML5 world, and remain compatible with older browsers, namely IE6/5/6/7/8.
Now, with all that being said, I guess you want to see some lines of code. So, lets start!
To upgrade your application, it all start with changing a simple line of code which is of course the Doctype. The new HTML5 Doctype is as simple as typing:
1 < !DOCTYPE html>
Isn’t that so simple? No more version, no more DTD validation file, just two words!
Well, of cours bear in mind that the new HTML5 Doctype won’t break your older code because HTML4 tags are still supported by HTML5. So, you have to proceed to this change if you want to validate your application and most of all, if you want to play with the new semantic tags such as the <article></article>, <section></section>, <header></header>, and <footer>.
I should mention also that the <!DOCTYPE> is not mandatory but I recommend you to put it in your code because that tells the browser to switch to Strict Mode, which means that your code will be treated as standard compliant code.
Now, the next step is to define the language you use in your application and charset as well. In fact, these two elements are very important in a web application because there are used by search engines and also for accessibility reasons, so please do not forget to use them!
So, you can set the language attribute to the correct language used by your web application, in my case I used “en” because I obviously use English as my main language. And this is how you define it:
1 <html lang="en">
Right? Next, we set the default charset, and for this I assume that you are already using the UTF-8 charset in your current application, if not please switch to this charset as soon as you can, I even advice you to set this charset as your default charset in your code editor. This will avoid a lot of headaches, believe me To set the UTF-8 charset, add this line to the head section of your HTML5 document:
1 <meta charset="utf-8">
Now, let’s put it all together:
<!DOCTYPE html><html lang="en">
<meta name="description" content="">
<meta name="author" content="">
<h1>My HTML5 clean template</h1>
So I think this needs a bit of explanation
- As you can notice, we put the <meta charset=”utf-8″> at the very top of the head section, and we did it for purpose: The browser needs to know what charset it should use to encode the rest of the document!
- I intentionally put the <script> just before the closing body tag, because of performance issues!
- The <style> may remain in the head section so the Render Engine of the browser can proceed quickly and apply styles to your page!
Well, I believe I reached the end of my article. Please feel free to read the other articles related to HTML5 for more advanced techniques.