Im interested in what does changing link in href to # (hash symbol) do exactly?
Usually it is to link to part of a page (
'#about'). If it is just there instead of being empty(
''), it prevents the page form being reloaded on click.
So does that mean if # is alone link wont work and wont load? I read it just gets you back to top of page if you click on it, nothing else happens, right? And this part of the page? How do we define it in href with #? (A href=’ ‘#blabla’ '>blabla example)
in order for your href to have a clickable link ie a web address, by placing the hashtag symbol, you refer the element (image,text, video etc) as a href if the website link is either not yet available or if it’s in the same page you can use the hashtag followed by the id name.
So from my understanding we only put # symbol to href while we find or make to which site to link it to? Like link is there but it wont direct you to that link untill you put the link (web adress) to href?
‘#’ is helpfull when you don’t have anything yet to put in the link. It’s just for code design. Exactly like Lorem greek thing
There seems to still be some misunderstanding, so let me give you an example:
The first link does not have a hashtag in it. It is a completely dead link. When you click it, it reloads the page (in this case the window - you will see it flash).
The second link is a dead link, but it has a hashtag in it. It is a dead link, but it does not refresh the page.
The third link takes you to a section at the bottom of the page.
I am not sure what you mean, did my example clarify this?
That is correct, and that it is why it does not refresh the page. If you don’t have the hashtag in there, the link will reload the whole page, but if you do put it in there, it will link to the top and not reload page. If you want a more specific answer, an empty string is not a URI, and according to the spec:
A URI reference [i.e. href] that does not contain a URI [an empty string is not a URI] is a reference to the current document. In other words, an empty URI reference within a document is interpreted as a reference to the start of that document, and a reference containing only a fragment identifier is a reference to the identified fragment of that document.
Here is more information if you want to read:
Basically, both are valid for dead links. Using a hashtag is preferred however as it lets you style the link, as
a:linkwill not work for an anchor element that does not have a URI.
Normally, you define it like this:
<a href="#about"></a> <div id="about"></a>
And the hash links to the id section you specify.
Correct. You can leave the href blank, but putting a # is common practice. Putting the hash prevents the page from reloading and let’s you style the link with css.