Should I make HTML Anchors with ‘name’ or ‘id’?

This might be a tricky one, But i have got you covered.I have done some research that have brought me to the conclusion below using the HTML 5 specifications.

According to the HTML 5 specification,

For HTML documents (and the text/html MIME type), the following processing model must be followed to determine what the indicated part of the document is.

  1. Parse the URL, and let fragid be the <fragment> component of the URL.
  2. If fragid is the empty string, then the indicated part of the document is the top of the document.
  3. If there is an element in the DOM that has an ID exactly equal to fragid, then the first such element in tree order is the indicated part of the document; stop the algorithm here.
  4. If there is an a element in the DOM that has a name attribute whose value is exactly equal to fragid, then the first such element in tree order is the indicated part of the document; stop the algorithm here.
  5. Otherwise, there is no indicated part of the document.

so, it will look for id="foo", and then will follow to name="foo"

Although in HTML5 the a element has no name attribute. However, the above rules still apply to other named elements.

I hope this was helpful 🙂 .