Should I make HTML Anchors with 'name' or 'id'?

前端 未结 14 1239
旧巷少年郎
旧巷少年郎 2020-11-22 00:49

When one wants to refer to some part of a webpage with the \"http://example.com/#foo\" method, should one use

F

14条回答
  •  情话喂你
    2020-11-22 01:30

    There's no semantic difference; the trend in the standards is toward the use of id rather than name. However, there are differences that may lead one to prefer name in some cases. The HTML 4.01 specification offers the following hints:

    Use id or name? Authors should consider the following issues when deciding whether to use id or name for an anchor name:

    • The id attribute can act as more than just an anchor name (e.g., style sheet selector, processing identifier, etc.).
    • Some older user agents don't support anchors created with the id attribute.
    • The name attribute allows richer anchor names (with entities).

提交回复
热议问题