The address element has been around for a good few years now. In fact, it’s been around since HTML3, remember that? However since the elements creation there have always been problems; knowledge and implementation. So with it once again being incorporated into the HTML5 specification how should we be using it? A quick look at the spec will tell you
The address element provides contact information for a document or part of a document. Information provided by address may include the names of the document’s maintainers, links to the maintainers’ Web pages, e-mail addresses for feedback, postal addresses, phone numbers, and so on. The address element is not appropriate for all postal and e-mail addresses; it should be reserved for providing such information about the contact people for the document.
Well, if we follow the above advice we could do something like this:
The HTML5 Doctor is run by the following group of volunteers: <address> <a href="https://stevefaulkner.github.io/html5doctored/author/jacko">Jack Osborne</a>, <a href="https://stevefaulkner.github.io/html5doctored/author/richc">Rich Clark</a>, <a href="https://stevefaulkner.github.io/html5doctored/author/miker">Mike Robinson</a>, <a href="https://stevefaulkner.github.io/html5doctored/author/toml">Tom Leadbetter</a>, <a href="https://stevefaulkner.github.io/html5doctored/author/brucel">Bruce Lawson</a>, <a href="https://stevefaulkner.github.io/html5doctored/author/remys">Remy Sharp</a> </address>
Another example that we have implemented on this very site is
<footer>
<div class="vcard"> by
<address class="author">
<em class="fn"><a title="Posts by Jack Osborne" href="#">Jack Osborne</a></em>
</address> on
<time datetime="2009-11-04" class="published updated">November 4th, 2009</time>
</div>
</footer>
If you view the source code on our home page you will see that we have used the address element, which has been nested within the footer of the articles, several times throughout the page. This is useful should the information be aggregated.
The worrying thing about the address element is that it is not as straight forward as it may initially appear. Thankfully many of you will be familiar with the incorrect implementation of the address element and the way that people have been abusing it for years but for those of you who are not, let me show you an example.
<address> Dr. Jack Osborne HTML5 Hospital, Doctorville, Great Britain Tel: +44 (0)XXXX XXXXXX </address>
I’m sure to some of you will be looking at the above code snippet and be wondering what exactly is wrong. It’s all very simple, the address element was not created for postal addresses and to reinforce this, the latest spec stipulates that the address element must not be used to represent arbitrary addresses (e.g. postal addresses), unless those addresses are in fact the relevant contact information.
When you are marking up an address that is not relevant we can use the p element to mark up this information and take advantage of the elements versatility by marking up addresses using the hCard microformat. Lets take a look at our example from above and show what it will look like with the addition of microformats.
<div class="vcard"> <p class="fn"><a class="url" href="#">Dr. Jack Osborne</a><p> <p class="adr" > <span class="street-address">HTML5 Hospital</span> <span class="region">Doctorville</span> <span class="postal-code">Postal Code</span> <span class="country-name">Great Britain</span> </p> <p class="tel">+44 (0)XXXX XXXXXX</p> </div>
As you can see, I have attached the vCard class to a div but you can append them to any block element and I have then gone about attaching the appropriate classes to the p and span elements within.
Unfortunately going into the hCard microformat goes beyond the scope of this article. The only reason I have decided to include it is to show the readers that you are not supposed to use the address element for postal addresses (its for providing contact information for a whole document or section of a document) but if you want to maximise the semantic value of that information you can do so with the addition of a couple of simple classes. However, if you don’t feel comfortable implementing these microformats on your own then visit the hCard generator which will do all of the heavy lifting for you.
15 Responses to “ The Address Element ”
Comment by Aaron Bassett at
I might be missing something but why shouldn’t you use it for a postal address? I understand that it should only be used to mark-up the contact details for the document (or document section) maintainer and not every address that appears on a site. But if the maintainer’s contact details include a postal address, why shouldn’t you use the address element? The spec actually says that in that case it should be used:
The emphasis is mine.
I always understood it that you should not use the address element when you were referring to a entity who is not the document owner/maintainer. For example in a business directory, like Yell.com the businesses listed in search results should not be marked up using the address tag. If an address tag is to be used on that site it should only be used to mark up Yell.com’s contact details.
However if this contains a Postal address, that’s fine. Or am I way off the mark?
Comment by Jonas at
I have been using the address element for a postal address in my imprint. As I understand it, this would be a correct use?
Comment by zcorpan at
Actually, it’s been around since the first draft of HTML, HTML Tags.
I’d include the “The HTML5 Doctor is run by the following group of volunteers:” text inside the address element.
Shouldn’t the postal address examples include br elements so that it makes sense without CSS? (The spec says br is appropriate for postal addresses.)
Comment by Steve Rose at
Interesting. I had not known that.
However, I’ve used it to indicate addresses of business, etc., and found it to work very well with Google. One little boutique with a common name jumped right to the top of the Google listings, where Google showed a map to the boutique.
Isn’t this a bit like arguing English language usage based on old text books, and ignoring common usage?
Comment by John Faulds at
Even though I agree with Aaron’s approach to how to use <address>, I stopped using it a while back when I began using Microformats instead.
Comment by Andrew Vit at
As I understand it, the address element doesn’t limit what kind of contact details it should contain, just that it should be a contact for the page. In any case, postal address should be acceptable!
And, for that matter, why didn’t html5 consider semantic tags for marking up postal addresses and phone numbers? (I mean native elements, not post-facto conventions like hCard.)
Comment by Sarven Capadisli at
This is not an either or situation. Do both.
Postal code in
addressis totally fine if in fact the owner of the document should be reached using that bit of information. This is plain ol’ HTML.Mark up the entity (document owner) using hCard because there is that added benefit of identifying specific bits.
Comment by Tweets that mention The Address Element | HTML5 Doctor -- Topsy.com at
[...] This post was mentioned on Twitter by Simon Bingham, ilya alexander , Jack Osborne, Rafael de Almeida, Mike Robinson and others. Mike Robinson said: Dr @jackosborne takes a look at <address> http://bit.ly/2Fo7OR Maybe time for a @html5doctor house call service? #html5 [...]
Comment by Links for November 4th | jonathan stegall: creative tension at
[...] The Address Element | HTML5 Doctor [...]
Comment by Aaron Bassett at
Why not use both? You could easily use <address> as the contain element for your hCard rather than a div. Giving you the benefits of the Microformat & the semantics of using the correct element
Comment by Rich Clark at
@aaron, you’re right you could use both.
@zcorpan, yes the
<br>tags should be in there.Jacks now away for a few days at Build Conference so give him a shout if you’re there and he’ll update the article with some of your suggestions just as soon as he gets back.
Thanks
Rich
Comment by Philip Jägenstedt at
No love for HTML5 microdata?
Comment by Bruce Lawson at
Philip – we’d love someone to write a guest column showing how to use microdata. Up for it?
Comment by Philip Jägenstedt at
Bruce, maybe I’ll spend this weekend updating my JavaScript implementation to make that possible…
Comment by Jordan Rothstein at
W3C.org recommends using the Address element for any type of contact information: name, email, IM, phone, postal mail, URL, VOIP and new media as they emerge. Examples of this from the specs for HTML2, HTML3 and HTML4 are given below. (Please note that the address element has been part of HTML since HTML2, not HTML3 as you claimed.)
Address element is for:
Contact information for the contact person(s) for the page.
Address element is not for:
Contact information for anyone other than the contact person(s) for the page.
When to use the Address element:
If I make a page urging readers to contact their elected representative about climate change, my contact info should be in address tags on my page. The representative’s info should not be in address tags on my page. If the elected representative has a page about climate change, their contact info should be in address tags on their page.
Examples from W3C.org:
HTML2
http://www.w3.org/MarkUp/html-spec/html-spec_5.html#SEC5.5.3
The ADDRESS element contains such information as address, signature and authorship, often at the beginning or end of the body of a document.
Typically, the ADDRESS element is rendered in an italic typeface and may be indented.
Example of use:
Newsletter editor
J.R. Brown
JimquickPost News, Jimquick, CT 01234
Tel (123) 456 7890
HTML3
http://www.w3.org/MarkUp/html3/address.html
The ADDRESS element specifies such information as address, signature and authorship for the current document, and typically placed at the top or bottom of the document. When used with %text, the element acts similar to a paragraph with breaks before and after.
Example:
Newsletter editor
J.R. Brown
8723 Buena Vista, Smallville, CT 01234&t;BR>
Tel: +1 (123) 456 7890
HTML3.2
http://www.w3.org/TR/REC-html32#address
The ADDRESS element requires start and end tags, and specifies information such as authorship and contact details for the current document. User agents should render the content with paragraph-breaks before and after. Note that the content is restricted to paragraphs, plain text and text-like elements as defined by the %text entity.
Example:
Newsletter editor
J.R. Brown
8723 Buena Vista, Smallville, CT 01234
Tel: +1 (123) 456 7890
HTML4
http://www.w3.org/TR/WD-html40-970917/struct/global.html#h-8.4.4
For lack of a better place, we include the definition of the ADDRESS here. This element adds author and contact information to a document, e.g.,
Newsletter editor
J. R. Brown
8723 Buena Vista, Smallville, CT 01234
Tel: +1 (123) 456 7890