O'Reilly logo

HTML5 24-Hour Trainer by Mark Fletcher, Joseph W. Lowery

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required