A low sun shining through a gap in a loose pyramid of piled, snow-covered rocks

On the web you can link to absolutely anything, but let's say that you want to create a link to the front page of CNN.com. Obviously CNN is not under your control. In this case you must provide the full and complete URL - a simple www.something.com is not sufficient.

Read this article on <a href="http://www.cnn.com">CNN</a>

Note that the easiest way to guarantee that you have the URL correct is to navigate to the site, page, or resource using your browser, highlight all the text in the URL bar (ALT+D), copy it (CTRL / CMD + C) and paste it into the appropriate href value in your page.

Also note that some longer URLs, particularly (but not exclusively) those that contain GET information, may cause the W3C to claim it is invalid. This is not your fault. You will simply need to replace some characters in the URL with their HTML entity equivalents: for example, writing &amp; to replace any & characters in the URL string.

The web and modern browsers allow several code shortcuts for remote links:

  1. the protocol part of the URL (http:) may be dropped, so long as the // remains;
  2. the www at the start of the URL can usually be dropped.
  3. quotes around the URL are optional so long as it does not contain any "weird" characters.

Under those conditions, our link could become:

<a href=//cnn.com>Go to CNN</a>

As a general rule, the first and last shortcut should be avoided, especially by beginners: protocol-free links can carry a security risk, while quote-free URL values can be more difficult to read (and are sometimes colored strangely in editors).

Photograph by Filip Stoyanov, used under a Creative Commons Attribution-NonCommercial-NoDerivs 2.0 Generic license

Enjoy this piece? I invite you to follow me at twitter.com/dudleystorey to learn more.