HTML and CSS Reference
In-Depth Information
Best practices —Valid code follows a set of best practices that have been designed by working groups, and
so by learning to write valid code you are also learning the best practices for building web pages. This is es-
pecially important for people who are new to web development because often browsers will automatically
correct mistakes that you have made in your code without telling you about them. This can lead you to be-
lieve that you are writing nice valid code when, in fact, you are making a lot of mistakes.
More maintainable web pages —Writing code that conforms to a widely accepted set of standards makes it
easier for multiple people to work on one project. Inevitably, everybody has his or her own, slightly differ-
ent, programming style; by following web standards when writing code, you can ensure that your markup is
consistent and easy for other people to understand.
It's just more professional —If you are serious about creating quality sites, writing good valid code will
show people that you know what you are doing. If you work in client services, it is also a great way of
showing your clients that you are committed to building websites that are future-proof, maintainable, and
standards-compliant. ( Pro Tip: Clients like those words; put them in your project proposals.)
Using validator.w3.org
Several code validators are available, but the exercises for this topic use http://validator. w3.org .
Validator.w3.org is a free service maintained by the W3C that you can use to validate your HTML and CSS code
against various web standards. You can run your code through the validator in a number of ways.
Provide a link to a page on the web.
Upload a file from your computer.
Copy and paste your code directly into the browser.
The validator will attempt to identify what version of HTML the page is written in by looking at the DOCTYPE de-
claration at the top of the page. (See the sidebar on DOCTYPEs, earlier in this chapter.) This enables the validator to
run your code against the relevant set of web standards. You can also explicitly tell the validator which standard you
would like to test against by selecting one from the Document Type drop-down menu in the More Options section on
the validator home page.
It's time to test the web page that you created earlier to see if it validates.
1. Open http://validator.w3.org .
2. Select the Validate by Direct Input method.
3. Copy and paste your code into the text box.
4. Click Check.
You should now see that your code passed validation as HTML5 (see Figure 1-5). Congratulations!
Search WWH ::




Custom Search