Is it better to put the id attribute in the tag "a" or in the tag "h1 / h2"?

I learn html on the w3 school website and I am in the "html link" chapter. I don’t understand why they suggest using the id attribute in the link tag instead of the title tag.

Example:

<p> 
<a href="#C4">See also Chapter 4.</a>
</p>

<h2><a id="C4">Chapter 4</a></h2> 
<p>This chapter explains ba bla bla</p>

My attempt:

<p>
<a href="#C4">See also Chapter 4.</a>
</p>

<h2 id="C4">Chapter 4</h2>
<p>This chapter explains ba bla bla</p>

Both work the same when I try them, but my attempt will take less time. Something is wrong in my attempt that I do not understand.

+4
source share
4 answers

Before it was possible to associate it with any element id, you could reference the elements <a>on them name.

id name . , Netscape 4 ( , id, , , - ).

W3Schools ( ).

id ( (<section> ?), ).

+3

, - , , , , a name. , , , a tag .

, .

W3Shools, , , , , . - W3C, -.

, head * er * head * ing *; , . .

+4

W3Schools ( . http://www.w3fools.com/).

id , w3 HTML4.01 .

+2

, () W3Schools, :

-, MDN, Mozilla. , Firefox, , , . , , , , , , <a>, name:

: HTML5, .

MDN , W3Schools.

-, WebPlatform.org, , W3Schools, W3C, , , , .

HTML-, :

id <a>, .
[...]
, , ,
[...]
, .

+2
source

Source: https://habr.com/ru/post/1534168/


All Articles