(X)HTML Tutorial

Standards and Best Practices

(X)HTML Standards

Because HTML developed gradually and haphazardly, many tags were adopted early on which no longer form part of current standards (HTML 4.0 or XHTML). Since web pages which use these tags still exist, today's browsers try to support them, but, as time goes on, they will cease to do so. Tags which are currently supported but no longer form part of the recommended standards are known as deprecated tags. Deprecated tags will still work (for now), but their use is strongly discouraged.

Some of the most common deprecated tags are ones which are used for styling, rather than describing, data. That is, their use is not semantic. A classic example is the <center> element, which causes the text to be centred on the screen. Tags like this are best avoided. Instead, cascading stylesheets (CSS) should be used for styling elements in web pages.

The most recent recommendations from the W3C are for HTML 4.01 and XHTML 1.0 (links are to the W3C's full documentation, which includes lists of tags). Conforming to these standards will ensure that your web pages display correctly in the latest browsers and will have the greatest longetivity.

Accessibility

Users do not all experience web pages in the same way. Vision impaired users, for instance, may have no ability to understand that text is a title, for instance, if the only thing that identifies it as a title is visual formatting (e.g. centring or bold type). Other users may be unable to perceive certain colour contrasts. Many users experience the web through assistive technologies such as screen readers (web browsers that read the text out loud). In some cases, you may be required to by law to make your web pages accessibile to users with disabilities.

There are a variety of methods for making web pages accessible, and the literature on this subject is now vast. A good starting point is the W3C's Web Accessibility Initiative (WAI) home page. One of the most important methods for making your web pages accessibile to assistive technologies is code validation, discussed below.

Code Validation

If the code of an (X)HTML file follows the syntactic conventions of its document type is considered valid. You can validate (check the validity of) your code online by entering the address of your web page in the W3C's Markup Validation Service. It will provide a detailed (if sometimes hard to understand) report of any errors.

Note that an XML file that follows the syntax of XML is considered well formed. Since the names of XML tags are defined by the file's creator, rather than by the needs of a web browser, the correct syntax for its markup must be declared at the top of the file. When the file conforms to the declared syntax, it is considered valid XML. For (X)HTML the distinction between well-formedness and validity is more or less blurred.

Semantic Coding

The growth of XML, and the frequent interaction between (X)HTML and XML, have encouraged the adoption of semantic markup wherever possible. For instance, it is better to use the (X)HTML <h1> (Header 1) for a web page title than to enlarge the font and make it bold. The latter simply changes the appearance of the text, but the former actually describes its place in the structure of the document.

Semantic coding can also make your web page more accessible since it provides explicit information about the data, rather than information implicit in the visual presentation.

Wherever possible, you should separate content and presentation by coding your content in (X)HTML and your presentation in CSS.