Beginning HTML5 and CSS3 For Dummies
Book image
Explore Book Buy On Amazon

Attributes introduce variety or specificity into how an element describes content or how that element works or behaves. Attributes let you use elements differently depending on the circumstances. For example, the

element uses the src attribute to specify a location for an image you want to display:

<img src="images/header.png" alt="header graphic" 
     width="800" height="160" title="banner graphic">

In this bit of HTML, the

element is a general flag to the browser that you want to include an image. The attributes handle all the fine details:

  • The src attribute provides the specifics for the image you want to use — header.png in this case.

  • The width and height attributes provide information about how to display that image on the page.

  • The alt attribute provides a text alternative to the image, which is useful because a text-only browser can display the text, or a text-to-speech reader can say it aloud for the visually impaired.

  • The title attribute creates a pop-up text message that appears over the image when a user moves the mouse inside its borders.

If you want to define attributes for any HTML element, they must appear inside the opening tag for that element, or inside the only tag for an empty element. They belong after the element name but before the closing angle bracket in that tag, like this:

<tag attribute1="value" attribute2="value">

HTML5 syntax rules decree that attribute values must always appear inside quotation marks, but you can include attributes and their values in any order you like within the opening tag or a single tag for an empty element.

Every HTML element has a collection of attributes that may be used with it, but you can’t mix and match attributes and elements however you please. Some attributes can take any text as a value because that value might be anything, such as the location of an image or a page to which you’d like to link.

Other attributes impose a specific list of values they can take, such as your options for aligning text in a table cell (left, right, center, and so on).

The various HTML specifications define exactly which attributes you can use with any given element, and which values (if explicitly defined) each attribute can take.

In HTML-speak, deprecated means that a tag or attribute should no longer be used, as it may become obsolete soon and will no longer be legal markup.

About This Article

This article is from the book:

About the book authors:

Ed Tittel is a 30-year veteran of the technology industry with more than 140 computing books to his credit, including the bestselling HTML For Dummies.

Chris Minnick runs Minnick Web Services. He teaches, speaks, and consults on web-related topics and has contributed to numerous books, including WebKit For Dummies.

This article can be found in the category: