Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what does link href="#" do? [duplicate]

Tags:

I stumbled upon the following snippet in a source code of a web site.

<link href="#" id="colour-scheme" rel="stylesheet">

What does this do?

like image 803
DarthVader Avatar asked Jun 05 '13 07:06

DarthVader


People also ask

Why href is used in HTML?

The HTML <a> href Attribute is used to specify the URL of the page that the link goes to. When the href attribute is not present in the <a> an element that it will not be a hyperlink. This attribute is used to specify a link to any address.

What does link tag mean?

The <link> tag in HTML is used to define a link between a document and an external resource. The link tag is mainly used to link to external style sheets. This element can appear multiple times but it goes only in the head section. The link element is empty, it contains attributes only.

What does link mean in HTML?

A link (short for hyperlink) is an HTML object that allows you to jump to a new location when you click or tap it. Links are found on almost every webpage and provide a simple means of navigating between pages on the web. Links can be attached to text, images, or other HTML elements.


2 Answers

Without a base element, it does not do anything, except consume the browser’s resources a little. By URL specifications, # as a URL is a reference to the start of the document at the current base URL. Since the tag would have to be in an HTML document, it would fail (either because the document is served with an HTML media type or after the browser has in vain tried to parse HTML with a CSS parser).

If you use a base tag that sets the base URL to one that refers to a CSS document, it would technically work, e.g.

<!doctype html>
<title>Demo</title>
<base href="http://www.cs.tut.fi/~jkorpela/basic.css">
<link href="#" id="colour-scheme" rel="stylesheet">
<h1>Hello world</h1>

This would be rather abnormal, really, and it would effectively prevent you from using relative URLs otherwise in the document. So this is just a theoretical possibility, rather than what’s really going on.

Probably href="#" is just a placeholder here, to be overwritten by JavaScript code, or something. It’s bad coding style for several reasons. It would be better to omit the href attribute (even though this is technically invalid in HTML5) and have one inserted dynamically.

like image 176
Jukka K. Korpela Avatar answered Sep 22 '22 14:09

Jukka K. Korpela


This does actually absolutely nothing except staying on the same page.

This comes from the Anchors that allow to jump on a part of a page (More specifically, on an id).

This is usually written to say that some link should be introduced here, because of its no-effectness. When you're coding a website, it's often useful to show links, even if the page the link refers to isn't yet existing. This is very often meant to be a temporary solution.

As specified in Ryan's and Tom's answers, it could also be to be used to load dynamically the CSS files.

like image 45
Jerska Avatar answered Sep 24 '22 14:09

Jerska