Validate Your HTML
Validate Your HTML Markup
Motivation
To educate the world about the benefits of making sure their markup of HTML and other web and non-web languages is valid according to the web standards.
What is valid HTML markup?
Most web browsers will accept various variations in the HTML markup language, but often will not know exactly what to do, unless the markup is well-formed and strictly abides by the WWW standards. To make it easier for browsers, for other HTML consumers and processors, and for general good measure, one should make sure the HTML validates and thus is valid.
Why validate?
- By validating your pages you make sure the structure of the document is acceptable to standards-compliant browsers.
- When you deviate from the standard, you don't know how the browser is going to react.
- Saying that "I don't know if my site is standards compliant or not, but it looks good in all browsers." (or just in one browser and one platform on which it was tested) is not a good idea.
- The browsers may not display this page correctly in future versions, or a new browser may do things differently.
- (For instance, when MSIE 5.0 came, it was more standards-compliant than MSIE 4.x and as a result many sites that worked with IE before became broken. This happened in the release of MSIE 6.0, and in Windows XP Service Pack 2, as well.)
- The browser has a tough job as it is, so you shouldn't make it tougher by sending it mal-formed input.
Caveats
- Standards-compliance is not a panacea.
- Even if all the output from the site is standards-compliant it doesn't mean it will display correctly.
- This is either because of bugs in the browsers, or because you haven't done the right thing.
- So, it is important to test the pages in as many browsers as possible, in addition to validating them.
How to validate?
A DuckDuckGo search for “html validator” as well as a Google search will yield many results. Note that you should first choose a version of the HTML or XHTML standards (such as HTML5 or XHTML 1.1) and use their correct Doctype to indicate that you are using them. Different HTML pages (even ones on the same site) may adhere to different versions of the standards, and validate accordingly, as long as they specify the appropriate doctypes.
Some prominent validators
- The W3C validator
- tidyp - a library and a command-line program for validating and fixing HTML. It is recommended to run it with all warnings displayed.
The more general case: linting and validating
WWW Markup Validation is a specific case of “linting” where one runs a program to make sure bad idioms are not present in one’s code or markup. There are links to more linters and checkers below.
Links
- Coding Horror: “HTML Validation: Does It Matter?”
- Perl Elements to Avoid - mentions other good practices.
- tidyall - an all-in-one linter, validator and tidier.
- check-all-the-things - another all-in-one checker, this time from the Debian project.
- HTML Dog - Recommended HTML, CSS, and JavaScript tutorials.
- Mozilla Developer Network (MDN) - Recommended reference and tutorials for web technologies.
- List of tools for static code analysis - on Wikipedia.
Project Links
- Canonical URL for the document - on Shlomi Fish’s home site. That page should validate as XHTML 1.1.
- GitHub repository - contains the Markdown sources, an issue tracker and more resources. Contributions are welcome. Currently, that page does not validate, but it appears to be GitHub’s fault.
Licence
This document is Copyright by Shlomi Fish, 2017, and is available under the terms of the Creative Commons Attribution License 4.0 Unported (or at your option any later version of that licence).
For securing additional rights, please contact Shlomi Fish and see the explicit requirements that are being spelt from abiding by that licence.
Credits
Valid XHTML 1.0 Logo taken from the Wikimedia Commons under the public domain.