When creating pages, it is important for your website to be valid. That means there should be no errors in the HTML code of your webpages. This is not mandatory but it will provide a boost for your website; both in terms of consistency and search engine rankings.
- HTML5 documents start with the <!DOCTYPE html> declaration which is much shorter than previous versions such as XHTML and HTML 4.
- You don’t have to close void tags with a slash: you can just input <br> instead of <br /> if you desire
- Attributes need quotation signs only if there is a space in the attribute or other special characters such as an equals sign.
- Elements and attributes can be arbitrarily-cased (they could be in lowercase, uppercase or mixed case) and that would not be a problem.
- Some attributes and tags were deprecated in HTML5 so you should keep yourself from using them, such as the attributes target, scope, align, bgcolor, border, background, cellpadding, cellspacing and so on. You can get a full list of deprecated attributes and tags at: https://www.tutorialspoint.com/html5/html5_deprecated_tags.htm
- You should be okay if you put ampersands (&) as text on a page instead of writing them as an entity (&)
- Void tags need not be closed; make sure you close all other tags that need a closing pair, like <p>…</p>
- In fact, you can add an arbitrarily named tag or attribute in HTML5 and the browser will render the page but the tags/attributes may not constitute a valid HTML5 document. A custom HTML5 element must have a dash in its name and you should be using the data attribute for arbitrary attributes instead of just inserting arbitrary attributes.
- The alt attribute for images (<img>) is still required
- Do not place block-level elements such as <p> inside inline-level elements such as <button>
- Identifiers (id attributes) and class names should not contain a whitespace inside their name.
- Avoid duplicate declaration of attributes on the same element
- You should close all non-void tags, closing the container tag without closing one of its children will still result in a validation error.
You can validate your pages one at a time at: https://validator.w3.org/. The validator will show the actual errors so that you can see what is wrong and resolve it. Therefore, it might be good to validate the documents regularly while your websites are in development. As usual, the errors are of the highest importance.