Protocol relative URLs

Protocol relative URLs

Many times we have seen warnings similar to “This page contains both secure and nonsecure items” or “This page has insecure content.”. This happens when we are viewing a HTTPS site and some content on the site is loaded from HTTP. So when we try to view a site say and we get this warning, that means some content on the site is getting loaded from a non https site, like These warning messages can be fixed by using protocol relative URLs.

What are protocol relative URLs?

A URL is usually similar to or Both these URLs specify what protocol to be used (HTTP or HTTPS respectively). A protocol relative URL will be something similar to // In protocol relative URLs we do not specify the protocol which should be used to connect to the URL. When the protocol is not specified the browser uses the current protocol of the website. Hence, when you visit the site in HTTPS mode, the link will use HTTPS protocol and if you are using HTTP mode, it will take the HTTP protocol.

When to use?

The protocol relative URLs can be used in following cases, so that the users don’t get warnings on HTTPS protocol for non HTTPS resources. Also, make sure the resources you are using in the page are served over both HTTP and HTTPS protocol. They can be used in HTML, CSS, or JavaScript.

<img src="//">
#logo { background: url(//; }
<script src="//"></script>

When not to use?

They should not be used the following cases:


Some email clients (e.g. Outlook) won’t try to use HTTP or HTTPs as the protocol, but will use the file:// protocol. the file:// protocol assumes that the resource referred is on the local machine, which won’t be the case.

Links or Canonical URLs

If we use protocol relative URLs in these cases, they can cause duplicate content issues between the http and https versions of the website.


You should use protocol relative URLs for your CSS, JavaScript, custom fonts etc on your website if your site can be accessed from both http and https protocols. You should never use it for any of the resources in your emails, links, canonical URLs.

  1. @FYI: The stylesheet will be loaded twice times if using protocal-relative-urls with IE7, IE8.

  2. Hi, I am working on Drupal 6, Is there any way that we can protocol Relative URLs in drupal 6

Leave a Reply