3 ms·
Hard disagree on the first point. Anchors are perfectly fine for jumping to a specific point on a page. Nearly all documentation websites do it, wikipedia does
by KoenDG 6y ago
Hard disagree on the first point.
Anchors are perfectly fine for jumping to a specific point on a page. Nearly all documentation websites do it, wikipedia does it, etc...
It's literally in the texts from back in 1995: https://www.w3.org/MarkUp/1995-archive/Elements/A.html https://www.w3.org/MarkUp/1995-archive/Elements/A.html
"This allows for the form HREF="#identifier" to refer to another anchor in the same document."
As Linus Torvalds says with Linux: don't break userspace. If userspace has made something work, don't break that.
- reificator 6y ago> Hard disagree on the first point. > Anchors are perfectly fine for jumping to a specific point on a page. Nearly all documentation websites do it, wikipedia does it, etc... I don't think that point says to not use anchors for in-page navigation. They're not objecting to `href="#my_anchor"`, they're objecting to `href="#" onclick="doStuff()"`, which is increasingly common on the web today.
- asddubs 6y agoincidentally if you must do this, it's better to use href="javascript:;" rather than href="#" because it won't cause jumps in position for noscript users/when scripts break
- 7786655 6y agohref="javascript:;" is also bad. It doesn't work if you try to open it in a new tab. Just use a real url!
- reificator 6y agoThere isn't a situation where you must do this. Don't do this. Quick heuristic: if you have a clickable link and I can't open it in a new tab, you should be using a button instead.
- paul_f 6y agohref="javascript:..." is just as bad. I want to hover over a link and see where it goes before I click. That makes navigation fair to the user, as opposed to "guess what's behind door number 3"
- dan-robertson 6y agoThe first point is that anchor elements should not be used as buttons by adding event listeners that don’t do something akin to following a link. It isn’t really related to the usage you are describing.
- mfontani 6y agoI think the author was talking about a literal "href='#'" which ought to have no use aside from a poor man's "back to the top", rather than an anchor pointing to another id on the page, which can be useful.
- gostsamo 6y agoThose are a same-page links and they are perfectly okay when pointing to an identificator on the same page. However, people put no identificator after the "#" and attach a listener instead where the behavior turns undefined and everything is possible.