Chapter 9. Validating Your Pages

When your newly coded page is not looking like you expect, what's your best first step? Validate! Validating your web pages ensures a baseline functionality and rules out misspelled or missing HTML tags. Furthermore, valid HTML is web standards–compliant and, to the best of current capabilities, future-proof. Validation is a straightforward process made much simpler by the freely available online tools explored in this lesson.

WORKING WITH THE HTML5 DOCTYPE

Because several versions of HTML are in use, validators rely on a bit of code to establish which version the page is to be judged against. This code is the document type declaration or doctype. As noted in Lesson 2, the doctype for HTML5 is very simple:

<!DOCTYPE html>

Note

Although you should use the simplified doctype in the preceding example when coding pages with HTML5, it is entirely likely you'll encounter pages written with an earlier version of HTML. The World Wide Web Consortium (W3C) maintains a list of document type declarations for prior HTML versions at http://www.w3.org/QA/2002/04/valid-dtd-list.html.

For browsers and validators to work properly — and, in accordance with HTML syntax — the doctype must be the first line of code in your web page.

So what happens if you don't include a doctype? The biggest impact occurs when a browser tries to render the page. Without clear guidelines of which version of HTML to rely on, a browser is left to make its own assumptions and guess how to interpret ...

Get HTML5 24-Hour Trainer now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.