X
    Categories: HTML 5

Validation of HTML5 documents

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.

  1. HTML5 documents start with the <!DOCTYPE html> declaration which is much shorter than previous versions such as XHTML and HTML 4.
  2. You don’t have to close void tags with a slash: you can just input <br> instead of <br /> if you desire
  3. Attributes need quotation signs only if there is a space in the attribute or other special characters such as an equals sign.
  4. Elements and attributes can be arbitrarily-cased (they could be in lowercase, uppercase or mixed case) and that would not be a problem.
  5. 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
  6. You should be okay if you put ampersands (&) as text on a page instead of writing them as an entity (&amp;)
  7. Void tags need not be closed; make sure you close all other tags that need a closing pair, like <p>…</p>
  8. 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.
  9. The alt attribute for images (<img>) is still required
  10. Do not place block-level elements such as <p> inside inline-level elements such as <button>
  11. Identifiers (id attributes) and class names should not contain a whitespace inside their name.
  12. Avoid duplicate declaration of attributes on the same element
  13. 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.

Ivan Dimov: Ivan is a student of IT, a freelance web designer/developer and a tech writer. He deals with both front-end and back-end stuff. Whenever he is not in front of an Internet-enabled device he is probably reading a book or traveling. You can find more about him at: http://www.dimoff.biz. facebook, twitter