Why using href="// instead of href="http:// in HTML?

DasCodes picture DasCodes · Jan 22, 2014 · Viewed 10.3k times · Source

Why using <link href="//something.com/style.css" rel="stylesheet"> instead of using http:// or https:// before the domain name?

If we use href=// does it changes with link? Like while in SSL mode will it automatically be changed to https://?

Answer

SilverlightFox picture SilverlightFox · Jan 22, 2014

Yes, it will use the current protocol.

i.e. if the current page is https it will access the href using https.

If http then the link is accessed over plain http.

This will prevent browser warnings if the hosting page is https and will be more secure than a plain http link.