Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

html - links without http protocol

Is there a reason we include the http / https protocol on the href attribute of links?

Would it be fine to just leave it off:

<a href="example.com">my site</a> 
like image 465
Web_Designer Avatar asked Jan 21 '12 07:01

Web_Designer


People also ask

How do I open a link without HTTP?

By using // , you can tell the browser that this is actually a new (full) link, and not a relative one (relative to your current link).

How do you make a link in HTML?

To make a hyperlink in an HTML page, use the <a> and </a> tags, which are the tags used to define the links. The <a> tag indicates where the hyperlink starts and the </a> tag indicates where it ends. Whatever text gets added inside these tags, will work as a hyperlink. Add the URL for the link in the <a href=” ”>.

Should I put HTTP?

Technically, the http:// (or https:// if the site is secured) is required but the browser will add it for you. This part of the address is known as the “protocol” (HTTP stands for Hypertext Transport Protocol) and it defines the communication rules that the web browser and the server use when exchanging web pages.

Is hyperlink a protocol?

The hyperlink is an active part of the document. It allows you to link to parts of the same page (when used in conjunction with target) and to files on the same computer or different computers across the Internet. The hyperlink support different kinds of protocols.


2 Answers

URLs in href are not restricted to only HTTP documents. They support all the protocols supported by browsers- ftp, mailto, file etc.

Also, you can preceed URL name with '#', to link to a html id internally in the page. You can give just the name or directory path, without a protocol, which will be taken as a relative URL.

like image 22
Ninja Avatar answered Sep 28 '22 03:09

Ninja


The inclusion of the “http:” or “https:” part is partly just a matter of tradition, partly a matter of actually specifying the protocol. If it is defaulted, the protocol of the current page is used; e.g., //www.example.com becomes http://www.example.com or https://www.example.com depending on the URL of the referring page. If a web page is saved on a local disk and then opened from there, it has no protocol (just the file: pseudo-protocol), so URLs like //www.example.com won’t work; so here’s one reason for including the “http:” or “https:” part.

Omitting also the “//” part is a completely different issue altogether, turning the URL to a relative URL that will be interpreted as relative to the current base URL.

The reason why www.example.com works when typed or pasted on a browser’s address line is that relative URLs would not make sense there (there is no base URL to relate to), so browser vendors decided to imply the “http://” prefix there.

like image 179
Jukka K. Korpela Avatar answered Sep 28 '22 05:09

Jukka K. Korpela