Picking Apart The Doctype

The HTML 4.01 Strict Document Type Declaration
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<!
Starts the Doctype. This is different from the way most tags are started, but the Doctype isn't really a tag.
DOCTYPE
Keyword that tells the browser This is a Document Type Declaration
html
The name of the root element
PUBLIC
The Document Type Definition (DTD) is freely available for download, as opposed to SYSTEM, where the DTD is bound to a specific server or the like.
"-//W3C//DTD HTML 4.01//EN"
This string is used as a signature of the Doctype. If the browser recognizes the signature, it's already downloaded a copy of the rules (also known as the DTD). This is used only for public DTDs.
"http://www.w3.org/TR/html4/strict.dtd"
The URI of the DTD, just in case the browser hasn't downloaded it yet.
>
Ends the Doctype.

Make Your Own Character Entity References

In Special Characters, I mentioned character entity references, or CERs. With XML-based languages such as XHTML, you can alter the Doctype to create your own. For example, say you're doing a page on chess, and you'd like to use the symbols for chess pieces, which are:

Chess Symbols
Piece White Black
Code Symbol Code Symbol
Pawn &#x2659; &#x265F;
Knight &#x2658; &#x265E;
Bishop &#x2657; &#x265D;
Rook &#x2656; &#x265C;
Queen &#x2655; &#x265B;
King &#x2654; &#x265A;

So far as I know, there are no CERs for chess symbols; you have to type their respective Numerical Character References. But if you are using XHTML or any other XML-based language, you can creäte them. Suddenly, the Doctype isn't just for validation purposes. So let's assign the following CERs to the symbols.

Character Entity References for Chess Symbols
White Black
CER Symbol CER Symbol
&cswp; &csbp;
&cswn; &csbn;
&cswb; &csbb;
&cswr; &csbr;
&cswq; &csbq;
&cswk; &csbk;

Now, remember: this only works when you're using an XML-based language. If the browser is told to treat XHTML as HTML, this won't work. First, create a section in the Doctype that can hold some extra information.

Doctype Extension Added
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" [
]>

Your custom CERs go between those square brackets; this is basically extending the DTD. Remember the simplified entity I showed in Special Characters? That's how you create these.

Doctype Extension Added
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" [
<!ENTITY cswp "&#x2659;"> <!-- White Pawn -->
<!ENTITY csbp "&#x265F;"> <!-- Black Pawn -->
<!ENTITY cswn "&#x2658;"> <!-- White Knight -->
<!ENTITY csbn "&#x265E;"> <!-- Black Knight -->
<!ENTITY cswb "&#x2657;"> <!-- White Bishop -->
<!ENTITY csbb "&#x265D;"> <!-- Black Bishop -->
<!ENTITY cswr "&#x2656;"> <!-- White Rook -->
<!ENTITY csbr "&#x265C;"> <!-- Black Rook -->
<!ENTITY cswq "&#x2655;"> <!-- White Queen -->
<!ENTITY csbq "&#x265B;"> <!-- Black Queen -->
<!ENTITY cswk "&#x2654;"> <!-- White King -->
<!ENTITY csbk "&#x265A;"> <!-- Black King -->
]>

Yes, you can put comments in the Doctype. The document will still be valid XHTML 1.0 Strict—valid altered XHTML 1.0 Strict, but valid nonetheless as the new CERs are a part of the extended DTD. The drawback to this is you have to add these to every document you use them in.

So, with all those character entities in place, you can now use the specified references. For example, here's the tbody of a table showing the various chess symbols:

Custom CERs Used
<tbody>
<tr>
<th>Pawn</th> <td>&cswp;</td> <td>&csbp;</td>
<th>Rook</th> <td>&cswr;</td> <td>&csbr;</td>
</tr>
<tr>
<th>Knight</th> <td>&cswn;</td> <td>&csbn;</td>
<th>Queen</th> <td>&cswq;</td> <td>&csbq;</td>
</tr>
<tr>
<th>Bishop</th> <td>&cswb;</td> <td>&csbb;</td>
<th>King</th> <td>&cswk;</td> <td>&csbk;</td>
</tr>
</tbody>

The result is below:

A webpage with the custom Character Entity References (This is an XHTML webpage)

Just a note—if you use the name of an already-defined CER, the one you write will override what's defined in the DTD.