arrows pointing right and left

XHTML Cheat Sheet

email Scott Turner
  • Prefix the whole thing with
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  • The root element should be html.
  • Use the following in the head section.
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
    <meta http-equiv="Content-Style-Type" content="text/css"/>
    Also the charset should agree with what the server sends in HTTP.
  • If a white background is desired, use <body style="background: white">.
  • In tables, define column widths using one <col width="..."> for each. This precedes the first <tr>.
  • To indicate alignment, use style="text-align:...;vertical-align:...".
  • All tags must obey XML rules for nesting and end-tags. For example, use <br/>.
  • <br/> must occur within a div, p, etc.
  • All images need an alt= text alternative.
  • To avoid a border on clickable images, add style="border-width:&nbsp;0" to the <img> tag.
  • To set text color, the style value is e.g. color: green.
  • Tables accept the good old border="1" attribute.
  • A table will be aligned as a block, unless you give it a style display: inline.
  • Since <p> elements can't contain other structuring constructs such as <blockquote>, it may be good to avoid them in pages that organize free-flowing chunks of information. An alternative approach is to put everything in <div>s and use double <br>s when there's a need to put a paragraph-like gap between chunks of text.
  • Test at the W3C MarkUp Validation Service. WDG also has a validator
  • Zvon's XHTML 1.0 reference is excellent.
  • Zvon's CSS1 reference is good when you're looking for a style attribute.
  • CSS2 supports the vertical-style attribute on cells of a table.
  • A <ul> element can have a style="margin-top:0em;margin-bottom:0em", which will cause it not to be separated from what precedes/follows it.
  • To make a local change to text style, use <span>.

Support open standards!  
Valid XHTML 1.0!