Know the Specification In order to effectively use HTML, it’s essential to be familiar with the fundamentals of the language. Thorough knowledge of a specification’s elements and attributes is required to create valid, semantic, and accessible mark up. See (X)HTML Specification for guidance. Know Your Target Browsers HTML specifications are requirements, not only for markup developers, but also for browsers vendors. Unfortunately, browser vendors don’t always implement all the features of a particular spec. Therefore, it is essential that authors know what selectors and properties are supported in specific browsers and versions. See the following references for details:
Mark up Web pages according to semantic meaning and structure WCAG 2.0 Guideline 1.3.1 Info and Relationships states, "Information, structure, and relationships conveyed through presentation can be programmatically determined or are available in text." Screen readers must be able to extract the semantic meaning of elements and page structure in order to convey information to users in different modalities. Search engines must be able to extract the semantic meaning of elements and page structure in order to index and prioritize content.
Semantics
Mark up elements according to semantic meaning.
Header and Paragraph:
<h1>header</h1> <p>paragraph</p>
Structure
Nest tags in a manner consistent with the structural semantics.
Correct:
<p><strong>Inline element nested in a block element</strong></p>
Incorrect:
<strong><p>Block element nested in an inline element</p></strong>
Document Outline
Ensure that the document's outline is clear, i.e., headline tag hierarchy should be ordered in a logical descending manner.
Outline:
<h1>Level 1 header</h1> <p>paragraph</p> <h2>Level 2 header</h2> <p>paragraph</p>
Write Well-Formed Mark up In order for Web pages to render properly in user agents and be perceivable by end-users and search engines, syntax rules should be followed that are consistent with a page's doc type declaration. While XHTML syntax requires strict adherence to XML rules, HTML5 syntax is more permissive - allowing both XML and HTML rules. However, for consistency and maintenance sake, the DSP recommends the usage of XML syntax under the HTML5 doc type.
Write Tags in Lower Case
Tag case should follow XML rules. Correct:
<h1>header<h1>
Incorrect:
<H1>header<H1>
Close Non-empty Elements
Non- Empty elements should follow XML rules for closing tags.
Correct:
<p>Non-empty element</p>
Incorrect:
<p>Non-empty element
Add ending slash to empty elements
Empty elements should follow XML rules.
Correct:
<br />
Incorrect:
<br >
Nest tags in a manner consistent with syntax rules
Tags should properly encapsulate one another.
Correct:
<p><span>Nested Tag</span><p>
Incorrect:
<span><p>Nested Tag</span><p>
Separate presentation, structure, and behavior WCAG 2.0 Guideline 1.3.1 Info and Relationships states, "Information, structure, and relationships conveyed through presentation can be programmatically determined or are available in text." The W3C recommends separating structure (e.g HTML), presentation (e.g CSS), & behavior (e.g JavaScript). The benefits are improved performance due to caching, reduced maintenance effort, and the capability to render different presentations and/or behavior to a specific user agent.
Embedded presentation and behavior
Avoid presentation and behavior mark up and attributes. Correct:
<p class=”className”> Lorem ipsum </p>
Incorrect:
<p width=”200” > <font size="3" color="red">Lorem ipsum</font> </p>
Close Non-empty Elements
Externalize presentation and behavior in files.
Head Element:
<link href="file.css" rel="stylesheet" type="text/css" media="all" /> <script src="file.js" type="text/javascript"></script>
If required to use inline JavaScript or CSS, encapsulate code in CDATA. Applies only to XHTML 1.0 Transitional.
Inline JavaScript:
<script type="text/javascript"> <!-- <![CDATA[> ... //]]--> <script>
NLS Support for XHTML JSPs or plain HTML files should be written and processed using Unicode characters, stored and transmitted using UTF-8 format. In this respect, JSPs should include the following directives as appropriate: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> ... <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> ... Obviously the (X)HTML, corresponding DOCTYPE and XML declarations will vary depending on the combination of JSP/HTML source file and the standard being utilised. The example above assumes XHTML transitional output being defined within it's own source file. Other points to remember:
- HTML has implied dir and lang attributes for nearly every tag so that the direction and language can be applied properly.
- Default layout is generally left-to-right, indicated by dir="ltr".
- In most cases, a good HTML layout/design will let the browser convert the output to 'right-to-left' automatically if desired.
- In extreme cases it may be necessary to provide alternate versions of content/JSP's for some languages. For example, German is typically twice as long as the English equivalent translation as may require it's own HTML.
(X)HTML and Transitional (X)HTML XHTML is an XML representation of HTML. It enforces the correct nesting and closure of tags, and removes many notable concepts which are made exclusively available via CSS (such as font and other text decoration). Other points to remember:
- DOCTYPE is required on all pages.
- The XML declaration is recommended, but may be omitted due to problems with browser compatibility.
- All URL's must be properly encoded using & etc.
- CDATA is required around most JavaScript and CSS declarations.
<script type="text/javascript"><!-- <![CDATA[ ... //]]> --></script> References
|