How to Create an Empty Link in HTML
Hi! In this guide, you’ll learn how to handle empty links in HTML and choose the right element for each situation.
An empty link may appear when a page is planned but has not been built yet — for example, a “Catalog” item in a menu whose destination page is still in development.
Another common case is a UI element that looks like a link but triggers a JavaScript action, such as opening a modal, menu, tooltip, or other interactive component.
- What Is an Empty Link?
-
<a href="">— a link to the current page -
<a href="#">— a popular but imperfect placeholder - Why is this option still used?
-
<a href="##">or<a href="#!"> -
A non-existent anchor:
<a href="#no-scroll"> -
<a href="javascript:void(0);"> -
<a href="something" onclick="return false;"> -
<a>withouthref -
The best option for JavaScript is
<button> - If there is no page yet
- Why You Should Avoid Overusing “Empty” Links
- URL Changes
- Browser History Issues
- Accessibility
- Keyboard Support and Accessibility
-
When to use
<a>, and when to use<button> -
What If You Really Need an Empty
<a>? - Which Approach Should You Choose?
- Conclusion
- FAQ
- What is an empty link in HTML?
- How do you create an empty link in HTML?
- What does a hash-only href value do?
-
Can you use
<a>withouthref? - When should you use a button instead of an anchor?
-
Should you use
javascript:void(0)?
At first glance, you might think this is all you need:
<a href="#">Page</a>
However, “empty” links can be created in several ways, and each behaves differently.
Let’s look at the main options and decide which approach works best.
What Is an Empty Link?
An “empty link” usually refers to an <a> element that temporarily or intentionally does not point to another page.
For example:
<a href="">Page</a>
or:
<a href="#">Page</a>
It’s important to distinguish between a real link and an interactive control.
If the click should take the user to another URL, you should use <a href="...">.
If the click only triggers an action on the current page — for example, opens a menu or a modal window — it is semantically more correct to use <button>.
This is one of the key principles of modern HTML development.
<a href=""> — a link to the current page
The simplest option:
<a href="">Page</a>
It may look like an empty link, but an empty href does not mean “do nothing.”
An empty href value points to the current document. Clicking it may reload the page.
For that reason, this is generally not a good placeholder link.
Avoid it especially for elements that are only meant to run JavaScript.
<a href="#"> — a popular but imperfect placeholder
A very common option:
<a href="#">Page</a>
The # symbol represents a URL fragment.
If the current address is:
https://site.com/page/
after clicking, it may become:
https://site.com/page/#
In addition to changing the URL, the browser usually scrolls to the top of the document.
That is why a user might click a link near the bottom of the page and suddenly be taken back to the top.
This can be especially frustrating for menus, footers, and other elements positioned far down the page.
Why is this option still used?
The reason is simple: it’s short and familiar to developers.
For example:
<a href="#" class="open-modal">Open</a>
and then JavaScript intercepts the click.
However, there are better ways today.
<a href="##"> or <a href="#!">
You may sometimes come across patterns like these:
<a href="##">Page</a>
or:
<a href="#!">Page</a>
The idea is that the browser sees a URL fragment, but does not find the corresponding element on the page.
For example:
<a href="#!">Page</a>
after clicking changes the address to:
https://site.com/page/#!
The page usually does not scroll to the top in this case.
Still, this is not a recommended solution.
#! was once widely used in older JavaScript applications for navigation, but it offers little benefit in ordinary HTML markup.
Also, the URL changes anyway.
A non-existent anchor: <a href="#no-scroll">
Another option is to specify a URL fragment that does not match any element on the page:
<a href="#no-scroll">Page</a>
If the page does not have:
id="no-scroll"
then the browser will not find the target element.
This means that the page should not scroll to a specific element.
The URL will still change:
https://site.com/page/#no-scroll
This method is much more predictable than href="#", but the problem with changing URLs still persists.
So using a random id as a way to make an "empty" link is also not a good practice.
<a href="javascript:void(0);">
An old but still common approach:
<a href="javascript:void(0);">Page</a>
javascript: allows you to execute JavaScript directly from the href attribute.
void(0) returns undefined, so no navigation takes place.
As a result, clicking this link does not change the URL or scroll the page.
But today this method is considered outdated.
It is better not to put the JavaScript code in href, but to handle the event separately.
For example:
<a href="/catalog/" class="catalog-link">Catalog</a>
document.querySelector('.catalog-link').addEventListener('click', function (event) {
event.preventDefault();
// JavaScript logic
});
In this case, the HTML remains clear and the JavaScript is separate.
<a href="something" onclick="return false;">
Another way:
<a href="something" onclick="return false;">Page</a>
return false cancels the default link action.
Therefore, the browser does not go to the address with href.
The advantage of this approach is that you can specify a real address:
<a href="/catalog/" onclick="return false;">
Catalog
</a>
and then intercept the click with JavaScript code.
However, embedding JavaScript in HTML via onclick is also not recommended.
It is better to use addEventListener():
<a href="/catalog/" class="catalog-link">
Catalog
</a>
document.querySelector('.catalog-link').addEventListener('click', function (event) {
event.preventDefault();
// the action to perform
});
This code is easier to maintain, test, and scale.
<a> without href
HTML allows you to create an <a> element without an href attribute:
<a>Page</a>
But there is an important nuance here.
Such an element is not a link.
Without href, the <a> element does not have the behavior of a regular link: it does not point to a URL and does not have the same semantics as an interactive link.
For example:
<a href="/catalog/">Catalog</a>
is a link.
Whereas:
<a>Catalog</a>
— this is simply an anchor element with no defined purpose.
An <a> without href may be useful for specific styling or markup needs, but it is not a substitute for <button>.
The best option for JavaScript is <button>
If an element should perform an action rather than navigate to another page, use a button:
<button type="button">Open menu</button>
For example, to open a modal:
<button type="button" class="open-modal">
Open window
</button>
JavaScript:
document.querySelector('.open-modal').addEventListener('click', function () {
// Open the modal
});
This is semantically more correct than:
<a href="#">Open window</a>
A button means “perform an action”.
A link means “go to this URL”.
If there is no page yet
What if a page is planned but has not been created yet?
For example, the menu may contain:
<a href="/catalog/">Catalog</a>
but /catalog/ does not exist yet.
In this situation, if the URL is known, it’s better to keep the future URL:
<a href="/catalog/">Catalog</a>
It's better than:
<a href="#">Catalog</a>
or:
<a href="javascript:void(0);">Catalog</a>
Once the page is created, the HTML will no longer need to be changed.
If the page is temporarily unavailable and users should not be able to open it, define a clear menu state or use an appropriate disabled control.
Why You Should Avoid Overusing “Empty” Links
An empty link can cause more than just scrolling problems.
URL Changes
Options with #, #!, or #no-scroll change the page address.
This may be a problem if the URL is used for:
- copying the address;
- analytics;
- browser navigation;
- bookmarks;
- JavaScript interaction with
location.hash.
Browser History Issues
Changing the URL fragment can affect browser history.
As a result, the Back button may behave unexpectedly.
Accessibility
Links and buttons serve different purposes.
If an element opens a menu, modal, or performs another action, using <a> instead of <button> can make it less accessible to keyboard users and people using assistive technologies.
Keyboard Support and Accessibility
When creating interactive elements, it is not enough to simply make them respond to a mouse click.
Button:
<button type="button">Open menu</button>
already has the correct keyboard behavior.
Users can reach it with Tab and activate it with Enter or Space.
If you create a pseudo-button based on the usual <div>:
<div class="open-menu">Menu</div>
you will have to implement much of that behavior yourself.
So use <button> for actions and <a href> for navigation.
When to use <a>, and when to use <button>
You can remember a very simple rule.
Go to another URL?
Use:
<a href="/catalog/">Catalog</a>
Do an action on the current page?
Use:
<button type="button">Open</button>
For example:
What If You Really Need an Empty <a>?
In some projects, you may need to keep an <a> temporarily — for example, to match an existing design or CMS structure.
In this case, you can use:
<a href="#">Page</a>
and prevent its default action with JavaScript:
document.querySelector('.link').addEventListener('click', function (event) {
event.preventDefault();
});
Still, avoid this pattern unless you have a specific reason.
If this is a placeholder for a future page, use its planned URL:
<a href="/catalog/">Catalog</a>
If it is an interactive element, use:
<button type="button">Catalog</button>
Which Approach Should You Choose?
Use this quick table to choose the right element.
Conclusion
There are several ways to create an “empty” link:
<a href="">...</a>
<a href="#">...</a>
<a href="#!">...</a>
<a href="#no-scroll">...</a>
<a href="javascript:void(0);">...</a>
<a href="something" onclick="return false;">...</a>
<a>...</a>
Most are outdated approaches or compromises.
In modern development, focus not on how to make <a> do nothing, but on which HTML element matches the purpose of the component.
If the element is for navigation, use:
<a href="/page/">Page</a>
If it performs an action without navigation, use:
<button type="button">Open</button>
If the page does not exist yet but its URL is known, specify the planned URL from the start:
<a href="/catalog/">Catalog</a>
This keeps your HTML semantic, predictable, and easier to maintain.
FAQ
What is an empty link in HTML?
An empty link usually refers to an <a> element that does not point to a separate page or is used as a temporary placeholder. For interactive elements, an <button> is often the better choice.
How do you create an empty link in HTML?
A common placeholder is an anchor with an empty hash, but it changes the URL and may scroll the page to the top. If the element performs an action, use <button> instead.
What does a hash-only href value do?
A hash-only href value sets a URL fragment with no matching identifier. The browser may change the URL and scroll to the top of the document.
Can you use <a> without href?
Yes. An <a> without href is valid HTML, but it does not behave like a regular link. If it performs an action, use <button> instead.
When should you use a button instead of an anchor?
Use <button> for actions on the current page. An <a> element is intended for navigation to a URL.
Should you use javascript:void(0)?
This pattern is outdated. Attach JavaScript with event handlers, and use <button> for actions that do not navigate.
