Addresses are common elements in text documents, so there is a special tag that sets addresses apart from the rest of a document’s text. While this may seem a bit extravagant—addresses have few formatting peculiarities that would require a special tag—it is yet another example of content, not format, being the primary focus of HTML and XHTML markup.
By defining text that constitutes an address, the author lets the browser format that text in a different manner and process that text in ways helpful to users. It also makes the content readily accessible to automated readers and extractors. For instance, an online directory might include addresses the browser collects into a separate document or table, or automated tools might extract addresses from a collection of documents to build a separate database of addresses.
The <address>
tag and
its required end tag (</address>
) tell a browser that the
enclosed text is a contact address, typically snail mail or email. The
address may include other contact information, too. The browser may
format the text in a different manner from the rest of the document
text or use the address in some special way. You also have control
over the display properties through the style
and class
attributes for the tag (see Chapter 8).
The text within the <address>
tag may contain any element
normally found in the body of a document, excluding another <address>
tag. Style changes are
allowed, but they may conflict with the style the browser chose to
render the <address>
element.
We think that most, if not all, documents should have their authors’ addresses included somewhere convenient to the user, usually at the end. At the very least, the address should be the author or webmaster’s email address, along with a link to their home page. Street addresses and phone numbers are optional; personal ones usually are not included, for privacy reasons.
For example, the address for the webmaster responsible for a
collection of commercial web documents often appears in source
documents as follows, including the special mailto:
URL protocol that lets users
activate the browser’s email tool:
<address> <a href="mailto:webmaster@oreilly.com">Webmaster</a><br> O'Reilly<br> Cambridge, Massachusetts<br> </address>
Figure 4-20 displays the results, which are identical for all the popular browsers in that, by default, the body of the address gets displayed in italics.
Whether it is short and sweet or long and complete, make sure every document you create has an address attached to it. If something is worth creating and putting on the Web, it is worth comment and query by your readership. Anonymous documents carry little credibility on the Web.
The dir
attribute
lets you advise the browser in which direction the text within the
<address>
segment should be displayed, and lang
lets you specify the language used
within that tag. [The dir
attribute, 3.6.1.1] [The lang attribute,
3.6.1.2]
Use the style
attribute to
specify an inline style for the <address>
tag, or use the class
attribute to apply a predefined
style class to the tag. [Inline
Styles: The style Attribute, 8.1.1] [Style Classes, 8.3]
You may assign a unique ID to the <address>
tag, as well as a title,
using the respective attribute and accompanying quote-enclosed
string value. [The id
attribute, 4.1.1.4] [The title attribute,
4.1.1.5]
As with most other tagged segments of content, user-related
events can happen in and around the <address>
tag, such as when a user
clicks or double-clicks within its display space. The current
browsers recognize many of these events. With the respective
on
attribute and value, you may
react to those events by displaying a user dialog box or activating
some multimedia event. [JavaScript Event Handlers,
12.3.3]
Get HTML & XHTML: The Definitive Guide, 6th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.