SitePoint Sponsor

User Tag List

Results 1 to 12 of 12
  1. #1
    SitePoint Member
    Join Date
    Sep 2009
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    What does href="#" mean?

    I've seen the code snippet href="#" on a number of sites, used in anchors, links, navigation li lists. It looks like a named-anchor definition but without the name?! Does it mean "this page", "the top of this page", a dummy to satisfy syntax requirements? What does it do?
    Thanks,
    John

  2. #2
    SitePoint Enthusiast ChrisXPPro's Avatar
    Join Date
    Apr 2010
    Location
    PA 15521
    Posts
    41
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is just a ''null'' value - which means the anchor will be seen as live (and would also enable use of the <title> tag), and should produce a hand pointer on hover - but it's use will take the user back to the same page he is on. Sometimes a better option for a ''live'' link but one which goes nowhere is -

    <a href="javascript: void(0)">I am a useless link</a>

    A named anchor of course would be something like - <a name="marker"></a> - that then called by a suitable link on the page to scroll down to the named anchor target <a href="marker"></a> - or at the end of a full link - <a href="http://www.mysite.com/apage.htm#marker">Target page and target content position</a> In this case the pound sign is used other than on its own, as we saw in the ''null'' link example.

  3. #3
    SitePoint Member
    Join Date
    Sep 2009
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks ChrisXPPro, your full, clearly expressed & prompt explanation is very much appreciated.
    John

  4. #4
    SitePoint Enthusiast ChrisXPPro's Avatar
    Join Date
    Apr 2010
    Location
    PA 15521
    Posts
    41
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Glad it may have helped John.

  5. #5
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,595
    Mentioned
    24 Post(s)
    Tagged
    1 Thread(s)
    # represents the start of a hash value. Strictly speaking it should have something following it (eg. #xx will link to the spot in the page that has id="xx"). With most browsers if you don't specify a value following it defaults to the top of the page.

    It most certainly does NOT represent NULL in any way whatsoever. Anyone who thinks that is misusing the value.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  6. #6
    SitePoint Wizard bronze trophy Black Max's Avatar
    Join Date
    Apr 2007
    Posts
    4,029
    Mentioned
    12 Post(s)
    Tagged
    0 Thread(s)
    Stu Phillips uses this in his offerings:

    Code:
    <a href="#nogo">
    Always wondered why he added the "nogo" wording. Stephen, I think you've answered that question.

  7. #7
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,595
    Mentioned
    24 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by Black Max View Post
    Stu Phillips uses this in his offerings:

    Code:
    <a href="#nogo">
    Always wondered why he added the "nogo" wording. Stephen, I think you've answered that question.
    Just to make sure that the question is fully answered - that link goes to the <div id="nogo"> tag in the same page.

    You can also link to that spot in the page from another page by specifying the page in front of the hash - eg. <a href="nextpage.html#nogo">
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  8. #8
    Follow: @AlexDawsonUK silver trophybronze trophy AlexDawson's Avatar
    Join Date
    Feb 2009
    Location
    England, UK
    Posts
    8,111
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    I always use the practice of having an ID of "top" at the first element occurrence in the visual hierarchy, that way I can link to the top of the page if required without depending on the hash alone (as it's more semantic). Though no-one should use that horrible JavaScript: void pseudo.

  9. #9
    Non-Member
    Join Date
    Apr 2010
    Posts
    76
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello,

    href="#" is used to active/enable the link on your page.

  10. #10
    Robert Wellock silver trophybronze trophy xhtmlcoder's Avatar
    Join Date
    Apr 2002
    Location
    A Maze of Twisty Little Passages
    Posts
    6,316
    Mentioned
    60 Post(s)
    Tagged
    0 Thread(s)
    The anchor identifier also known as (Fragment ID) is supposed to have a UNIQUE value and follow the ending "#"; not be the lone hash "#" on its own (i.e. the Fragment ID omitted completely), or it is basically writing poppycock and shouldn't do anything sensible at all.

  11. #11
    SitePoint Enthusiast ChrisXPPro's Avatar
    Join Date
    Apr 2010
    Location
    PA 15521
    Posts
    41
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It most certainly does NOT represent NULL in any way whatsoever. Anyone who thinks that is misusing the value.
    felgall - I am suitable admonished! I guess I have just been regarding the # alone as a null for practical purposes in an anchor ....... your point sir is taken.

  12. #12
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,595
    Mentioned
    24 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by casius View Post
    Hello,

    href="#" is used to active/enable the link on your page.
    Why didn't you read the thread first before posting incorrect information. There is a correct description of what the # means above your incorrect one.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •