HTML Crib Sheet

I wrote this document to serve as a reminder for myself. This document isn't meant as a tutorial, though if you're familiar with markup languages then this may do fine. If you're just starting to learn about HTML, there are certainly better primers out there (htmlprimer.com looks ok, for example).

There are several different versions of HTML available. This document is written using HTML 3.2 which is now quite old (finalized in 1997); on the bright side, all browsers should have full support for HTML 3.2 by now. HTML 4.01 is the most current (as of 2009/04/14); the major changes from HTML 3.2 are specifications on handling multimedia, cascading style sheets, and scripting. But the web has begun moving to XHTML which reconstructs HTML as a form of XML.

All HTML 3.2 documents must begin with the following line:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">

<!-- is a comment -->

<BR> forces a line break. <P> begins a new paragraph; you can end it with </P>. <HR> produces a horizontal rule the width of the browser window.

To include inline images, use the <IMG> tag, as in <IMG SRC="blah.gif" ALIGN=BOTTOM>; the alignment is (by default) to the bottom. You can also specify MIDDLE and TOP. You can also give an ALT option for text to be displayed instead of the image (in case the browser can't retrieve/display the images). Extended HTML supports RIGHT, LEFT, and CENTER alignment options too.

You can now change the font with a <FONT></FONT> pair; they take SIZE and COLOR attributes.

Logical Styles

<STRONG></STRONG> produces text with strong emphasis.
<CITE></CITE> produces text for citations.
<DFN></DFN> produces text for definitions.
<CODE></CODE> produces text that looks like computer code.
<STRIKE></STRIKE> produces struck-through text.
<BIG></BIG> produces large text.
<SMALL></SMALL> produces small text.
<SUP></SUP> produces superscripted text.
<SUB></SUB> produces subscripted text.
<VAR></VAR> produces text for variable names.
<KBD></KBD> produces text that the user should enter
<PRE></PRE> produces
text that is preformatted

<BLOCKQUOTE></BLOCKQUOTE> produces
text like this

You should use the above codes in favour of these explicit codes:
<I></I> produces text like this.
<TT></TT> produces text like this.
<B></B> produces test like this.
<EM></EM> produces text like this.

Lists

There are several kinds of lists:

Unordered list
<UL>
<LI> element
</UL>
Menu lists
These are typically more compact that unordered lists.
<MENU>
<LI> element
</MENU>
Directory lists
These are for elements < 20 characters long, and may be arranged into columns.
<DIR>
<LI> element
</DIR>
Numbered or Ordered List
<OL>
<LI> element
</OL>
Definition List
The <DL> tag can take an optional COMPACT attribute.
<DL>
<DT>Term
<DD>Definition
</DL>
Lists may be nested.

Special characters

HTML Tag Description Actual character
&lt; less-than <
&gt; greater-than >
&amp; ampersand &
&quot; quotation mark "
&nbsp; non-breaking space " "
&ensp; en-space " "
&emsp; em-space " "
&ndash; en-dash "–"
&mdash; em-dash "—"
&shy; soft hyphen "­"
&para; para
&sect; section marker &sets;
&middot; middle dot ·
&copy; copyright ©
&reg; registered trademark ®
&sect; section marker &sets;
&sect; section marker &sets;

Note that &nbsp;, &ensp;, &emsp;, &ndash;, and &mdash; are not supported by X/Mosaic, and many other browsers.

Some other special symbols, taken from Netscape, are:
HTML Tag Description Actual character
&copy; copyright ©
&iexcl; inverse exclamation ¡
&iquest; inverted question ¿
&cent; cent sign ¢
&pound; pound sterling £
&curren; generic currency ¤
&brvbar; pipe ¦
&sect; section §
&ordf; (?) ª
&ordm; (?) º
&laquo; left angled quotations «
&raquo; right angled quotations »
&plusmn; plus-minus ±
&sup1; superscript 1 ¹
&sup2; superscript 2 ²
&sup3; superscript 3 ³
&acute; acute ´
&macr; macro ¯
&micro; micro µ
&para; paragraph marker
&middot; middle-dot ·
&frac14; 1/4 fraction ¼
&frac12; 1/2 fraction ½
&frac34; 3/4 fraction ¾
&times; times operator ×
&divide; division operator ÷
&thorn; thorn þ
&THORN; capital thorn Þ

The HTML 3.2 Specification has a section with other entities.

Miscellaneous

Use <A NAME="anchorname">anchor</A> to create an anchor to some text, and use <A HREF="document#anchorname>link</A> to go to it.

You should have a <HEAD></HEAD> and <BODY></BODY> section in your HTML document. Some servers (may) allow viewing only the headers of documents. <ADDRESS></ADDRESS> usually gives information on how to contact the author of the page.

You can create tables. (This is a new addition, and hasn't been well-researched) The table is started with a <TABLE ALIGN="CENTER" BORDER="1">. You can add a <CAPTION></CAPTION> pair too (which has an ALIGN attribute for placement relative to the table). Rows are defined with a <TR></TR> pair. Headers within a row are defined with a <TH></TH> pair. Cells within a row are defined with <TD></TD> pairs. The table is ended with a </TABLE> tag.

You may find these pages helpful too:


Brian de Alwis / bsd@cs.ubc.ca