Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it ok to create anchors without href attributes?

If you take this example, <a name="xxx"></a> ... is this ok when creating an anchor? I have always preferred to use an already created tag for my destinations.

like image 213
marcus Avatar asked Nov 22 '25 04:11

marcus


2 Answers

If you are using this for in page navigation you can just just the id of the element rather than having to set up the anchor tag e.g.

<a href="#stuff">link to stuff</a>

<div id="stuff"></div>

I personally would not use an empty anchor tag.

like image 186
matpol Avatar answered Nov 23 '25 19:11

matpol


For navigational purposes within one page, it's perfectly fine. Though that style of navigation is usually related to some kind of headings or titles, so usually most people end up surrounding the appropriate heading/title with the anchor. I guess it's better from a readability and maintenance point of view.

like image 25
Wim Avatar answered Nov 23 '25 21:11

Wim



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!