Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does // mean in an <a> tag

Tags:

html

I'm writing a web crawler and I'm testing it out by starting at Wikipedia. However, I noticed that many of wikipedia's links are prefaced with //, so the link from wikipedia.org to en.wikipedia.org is a link to //en.wikipedia.org. What exactly does this // mean in practice? Does it say "use whatever scheme you were using before and then redirect to this url?" or does it mean something entirely different?

like image 296
Jonathan Avatar asked Dec 07 '25 20:12

Jonathan


2 Answers

The link will use protocol (http or https) same as page which contain that link. For example if https://stackoverflow.com/ contain <a href="//en.wikipedia.org"></a> it will directed to https://en.wikipedia.org

like image 170
iPao Avatar answered Dec 09 '25 14:12

iPao


It maintains the protocol that is being used for the webpage. HTTP/HTTPS.

It's particulaly useful for external scripts and css tags, in which you don't know in which protocol your site will be working on.

That's why on Google libraries (https://developers.google.com/speed/libraries/devguide#jquery) you have like this:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

Just while writing this I found a duplicate: Two forward slashes in a url/src/href attribute

Take a look at it.

like image 28
digao_mb Avatar answered Dec 09 '25 15:12

digao_mb