Welcome to WebHeadStart.org

Web Technologies

Sponsored By

WebHeadStart.org is currently in beta.
Please pardon our appearance as we work to provide you with the most comprehensive reference on today's web technologies.

Interested in advertising on WebHeadStart? Become an advertising partner today!

HTML Attributes and Values

Some HTML elements can contain one or more attributes, which serve to further describe the purpose or content of an element. Attributes tend to contain information about the underlying document, as opposed to being a that data itself, for example, filename (or URL's), alignment, color, size, etc. - are all examples of information that is typically expressed as attributes. HTML attributes take the for, of name-value pairs, and are always located inside an element's opening tag. Take for example, the <tr> tag, which is used for displaying a table row, as illustrated here:

Code Sample:
<tr width="640"/>
view code in new window.
render sample in browser.
Download code sample on your computer.
  • The HTML attribute starts with an attribute name, for example "width"
  • Next comes the "=" equals symbol
  • Followed by the attribute value, for example "640"

An HTML element may contain any number of attributes, for example, the <img> tag, for displaying images often has more then one attribute present, as shown here:

Code Sample:
<img src="/images/html/emptyelement.gif" alt="An empty HTML element" border="0"/>
view code in new window.
render sample in browser.
Download code sample on your computer.

HTML Attribute Syntax Tip

In HTML, attribute values need not be enclosed by quotation marks, however in XHTML, they are required. We think it's good practice to remember to use them anyway.

Each attribute name-value pair must be separated by a space. The attribute names must be unique, and the order in which they appear within an element's opening tag is irrelevant. Some attributes can accept any value at all, others are more limited. The most common limitation is know as an ennumeration, in which an attribute's value must correspond to a list of predefined values, for example, a list of colors "blue", "red", "green", etc.

Many attributes require a number or percentage for their value, particularly for those describing dimensions like width and height. A numeric value never includes units. Where units are applicable, as in the "width" attribute example presented earlier, the units are understood to be pixels.

HTML Attributes: Summary

In this tutorial, we reviewed several examples which covered:

  • What are HTML attributes used for and why you need them
  • How to create an HTML attribute
  • Enumerated attribute values
Start Of Section: Learn HTML Start of Section:
Learn HTML
Previous Page: HTML Elements Previous Page:
HTML Elements
Next Page:
HTML FAQs
Next Page: HTML FAQs
Valid XHTML 1.0! Valid CSS! Site Map | Privacy Policy | Terms of Use | WebHeadStart.org © 2005 All Rights Reserved.