Best Practice
Published by: Anil K. Panta
Best Practices
HTML is the backbone of any website. It's the first thing people see. Without it, there would be no website.
Because of this, it's important that you stick to good coding practices. If you don't follow the best practices, you will create a bad user experience for the web user.
Use the HTML5 <!DOCTYPE> Declaration
<!DOCTYPE html>
This should be the very first thing in a document, before the <html> tag, and before any whitespace.
Don’t Close Null Tags
A “null” or “empty” element is an element that has no content. These include:
<img>
<br>
<hr>
Surprised that an <img> element has no content? The image itself is an attribute of the tag, not the content.
In some previous versions, HTML (those based on the XML standard) required these elements to be closed with a slash.
Learn to Use the New Features
Sometimes, if you don’t know that something is available, you don’t know to look for it. For example, if you didn’t already know about the <video> element, you might not know just how easy it is to embed video on a web page.
So it’s a good idea to spend some time browsing the New Features list so that you are aware of what’s available.
Encourage Semantic Markup
In previous versions of the language, common structural elements like page headers, navigation menus, and main content sections were all indicated with the same HTML element, the <div> tag. In HTML, there are a host of new semantic elements intended to indicate the basic structure of a page:
<header>
<nav>
<main>
<article>
<aside>
<section>
<footer>
New text-level (inline) elements have also been introduced, such as <address> and <time>. These help search engines and other services to easily find information on a page, for display in other contexts. At the same time, existing inline elements which produce various effects like bold, italic, and underline have been refined or redefined to imply specific semantic meaning.