Attributes to HTML tags enable us to change the default values for a particular tag. If you're happy with the default values, then using an attribute is a waste of space and effort.
For example, <P> text is displayed in a default font of Times in the major browsers. So there's no need to specify <FONT FACE=Times> unless you're trying to override a personal preference setting that someone might have made within his or her browser.
Here are some common default values that you probably never need to include in your HTML:
- <BASEFONT FACE=Times SIZE=3 COLOR=black>
- <BODY TEXT=black>
- <BR CLEAR=none>
- <DIV ALIGN=left>
- <FONT FACE=Times SIZE=3 COLOR=black> (SIZE=3 is the default only on regular body text, not headers.)
- <Hx ALIGN=left> (<H1>, <H2>, etc.)
- <IMG ALIGN=left HSPACE=0 VSPACE=0>
- <P ALIGN=left>
- <TABLE BORDER=0 CELLPADDING=1 CELLSPACING=2>
- <TD ALIGN=left VALIGN=middle COLSPAN=1 ROWSPAN=1>
Be careful about assuming these default values if you're targeting users that aren't using Netscape Navigator or Communicator or Internet Explorer. As always, test on the platforms your audience is using.
Sometimes an attribute isn't even relevant for a particular tag. When this is the case, including it causes a wasteful increase of file size. Let's say you insert an image into a page, and that image is not a link. What part of the code below is unnecessary?
<IMG SRC="emma.jpg" HEIGHT=150 WIDTH=100 BORDER=0 ALIGN=left ALT="Emma Thompson">
If you guessed BORDER=0, you're correct! The image isn't a link, so it won't have a border anyway.
next page»