Don't use
for address

2019-09-22 10:48发布

Here is what the HTML5 spec says:

  1. The address element represents the contact information […]
  2. The address element must not be used to represent arbitrary addresses […]

Isn't it ridiculous? They say "Don't use <address> for address". Why would they name that element address then? Maybe they had to name it <contacts>?

They say: "The p element is the appropriate element for marking up postal addresses in general" but hey, the <p> element is appropriate for anything then. It can be a piece of novel …

If you want to markup a company postal address in their site's footer what do you use? Just <p>? I don't think it's a paragraph there, do you?

2条回答
我想做一个坏孩纸
2楼-- · 2019-09-22 11:29

Hum... when you quote the specs, don't remove the relevant parts (emphasis is mine):

The address element represents the contact information for its nearest article or body element ancestor.

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.

As I understand this :

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 for the nearest article or body element ancestor.

Is it still unclear ?

Regarding company address in footer : it is ok to use the <address> tag if the nearest article or body element ancestor is about the company.

You must use the <p> tag for addresses that are not related to the nearest article or body element ancestor.

查看更多
聊天终结者
3楼-- · 2019-09-22 11:38

The basic markup for postal addresses is a p element with br elements for separating the lines.

The address element conveys additional information, namely, that this postal address is (part of) the contact information for an article (if there is one) or the body (if there is no parent article).

So in both cases you should have the same markup for postal addresses, either with or without address container (depending on the purpose of the postal address).

In your specific example (company address in the footer of the company’s website), you should use the address element, because your company is the relevant contact for the webpage. Note that this address could also contain your company’s email address, telephone number etc.

Why the element is named address instead of contacts?

Probably because the element name was adopted from previous non-HTML specifications (and maybe its purpose/meaning was redefined at some point discussing HTML).
On Early History of HTML it says in the "Pre-1990: GMLguide and GML" section that the "Waterloo SCRIPT GML User's Guide" (some kind of predecessor to SGML) from 1988 mentions several tags that are now used in HTML, too, and among them is ADDRESS.

But it doesn’t really matter. While descriptive element names are helpful, they are not required. The semantics are defined by the HTML specification, not by the element names.

Looking at the various HTML versions, we can see that it was never intended to be used for every kind of postal address:

查看更多
登录 后发表回答