Search code examples
htmlhyperlinkhref

Link without href, any use for that?


I was reading sscce.org/ and without any particular reason I checked its HTML source. I found there are many <a> links without href attribute, like this:

<h2><a id='eg' rel="nofollow">Example</a></h2>

Now from HTML 5 specification we know that this is allowed (for example if link is completed later through JavaScript code), it's also allwed in HTML 4.01 (thanks to this post for references). In short it's useful if a link may be placed there but for any reason it has not been (server side) or it has been removed (client side). OK it's clear as it's also well summarized here.

Another (kind of) subtle difference is styling: even if link isn't rendered as link (by default underline and hand cursor) it'll inherit custom CSS styles for links such as:

a {
    font-weight: bold;
}

Question: what I don't understand is the reason it's used in that page. There isn't any client-side JavaScript to add/remove href for that links and (more or less reasonably) I suppose such simple page is plain HTML and it's not generated server side. That said...why that links? Is there any other use I'm missing? Is it something related to SE?


Solution

  • Check http://sscce.org/#eg and you will now.

    It was an old way to create links to a specific part of the page. Back then, you couldn't reference any element on the page, just anchors. Now it works the same with divs having an id.