There are various ways to create an empty link, but some options are more appropriate than others. One of the most common debates about it is if one should use
Generally, you want to avoid
With that out of the way, it's clear that
href="#" should be preferred in most cases. One key difference between the two is that
href="#" points to the top of the page whereas
href="" points to the current page. This can have unwanted side-effects, such as scrolling to the top of the page or issues with link styling respectively. To prevent either one of them from acting as links, you can use
Finally, when creating an empty link, one should always consider more semantically appropriate alternatives, such as a
A collection of quick tips and tricks to level up your coding skills one step at a time.
Adds multiple event listeners with the same handler to an element.
Creates an element from a string (without appending it to the document). If the given string contains multiple elements, only the first one will be returned.
Creates an object containing the parameters of the current URL.