LoginSignup
81
69

More than 5 years have passed since last update.

<a href="#top">がHTML5で正式仕様になってた件

Last updated at Posted at 2014-03-06

これなんだけども:

仕様についてあんまり書いてなかったので自分で読んでみたまとめ書く。

href="#top"を指定すると自動的にページの先頭へのリンクになる ……というブラウザーの独自仕様があったわけなんだけども、これが正式に仕様として明記されたとの事。

MDNの説明が一発で分かる。

href

これは、ハイパーリンクのソースを定義するアンカー要素で唯一必須の属性です。(中略)

補足: 特別なフラグメントである "top" を使用すると、ページの最上部に戻るリンクを作成できます。例: <a href="#top">ページ上部へ戻る</a>この動作は HTML5 で明記されました。

じゃあってんでリンク先を見てみると、ちょい先に書いてあった。

6.6.9 Navigating to a fragment identifier

(snip)

The indicated part of the document is the one that the fragment identifier, if any, identifies.

(snip)

  • 7. If fragid is an ASCII case-insensitive match for the string top, then the indicated part of the document is the top of the document; stop the algorithm here.

つまりhref="#xxx"xxxをfragidと呼ぶとして、 「fragidがtopと完全一致する場合、ページ内リンクの指示先はドキュメントの先頭とする」 という事らしい。

へえー。

※普通に飛び先の#topがあればそっちに行きます。

  • 5. If there is an element in the DOM that has an ID exactly equal to decoded fragid, then the first such element in tree order is the indicated part of the document
81
69
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
81
69