It's an interesting issue. You must put one at the beginning of every web page you create as its absence will cause some recent browsers to display your page oddly without it. It's also generally not advisable to put anything before the doctype declaration.
The basic format looks like this:
code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
But there are numerous variants depending on what kind of page it is and the type of code you are aiming at. Read up on these resources: