Question
Can classes be used as a page anchors in a similar way to ids? For example, can I use this anchor <a href=”.top”> ... </a>
to jump to the section of the page containing this paragraph <p class=”top”> … </p>
?
Answer
No. Page anchors are used to jump to a very specific region of a page. Specific regions of a page should be uniquely identified with id
attributes not class
attributes. What’s more, if we try to use a class name as the value of the href
attribute within a page anchor, users who click on that link will see a “file not found” error in their browser.
To learn more about page anchors, check out this HTML exercise.