First, we want to declare and create the document type, we no longer use HTML 4 or XHTML 1.0 like PUBLIC -//W3C//DTD XHTML 1.0 Transitional..... Declaration, we can write this way:
- <!DOCTYPEhtml>
Take a look, it's simple and obvious, case-insensitive. It makes it easier to be backward compatible. At least it can save you some time in typing.
We have now defined the type for the HTML 5 document. Everything went well so far. Now, let's take a look at the new tags for HTML5. Before we browse the new tab, let’s take a look at how we usually write:
- <html>
- <head>
- ...other...
- </head>
- <body>
- <divid=header>
- <h1>CSS3-HTML5 Home</h1>
- </div>
- <divid=nav>
- <ul>
- <li>Home </li>
- <li>About </li>
- <li>Contact</li>
- </ul>
- </div>
- <divid=content>
- <h1>Title</h1>
- <p>...</p>
- </div>
- <divid=footer>
- <p>Copyright Information</p>
- </div>
- </body>
- </html>
Using <div> in the example above is a very common practice now. Its purpose is dual. First, it provides a unique identity ID that can be applied specifically to web page chapters. Second, identification is as a primitive, pseudo-semantic structure. The ID names on each website may be different, so it is difficult for us to understand what those IDs mean.
<header> tag:
The <header> tag is equivalent to the one we usually define with <div id=header>. If your website is still defined like this with <div id=header>, we can now replace it with <header>.
<nav> tag:
<nav> is the navigation tag, just like we usually use:
<div id=menu>
<ul>
<li>index</li>
<li>news</li>
...
</ul>
</div>
Now use <nav>:
- <nav>
- <ul>
- <li><ahref=index.html>Home</a></li>
- <li><ahref=/about/about/about</a></li>
- <li><ahref=/blog/>Blog</a></li>
- </ul>
- </nav>
<section> tag: The <section> tag can be a group of content or topic groups, usually with a start tag and an end tag. Of course, this tag can also be nested.
<article> tag: There can be a section of content inside the <article> tag.
<aside>
<footer> tag: <footer> tag, if you don’t say it, you can understand what this is for. There can also be multiple, usually at the bottom of the website.
Let's take a look at the last code:
- <!DOCTYPEhtml>
- <html>
- <head>
- ...stuff...
- </head>
- <body>
- <header>
- <h1>MySite</h1>
- </header>
- <nav>
- <ul>
- <li>Home</li>
- <li>About</li>
- <li>Contact</li>
- </ul>
- </nav>
- <section>
- <h1>MyArticle</h1>
- <article>
- <p>...</p>
- </article>
- </section>
- <footer>
- <p>...</p>
- </footer>
- </body>
- </html>
Through the code, it is more concise and easier to understand, right?