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
& to replace any
& characters in the URL string.
The web and modern browsers allow several code shortcuts for remote links:
- the protocol part of the URL (http:) may be dropped, so long as the // remains;
- the www at the start of the URL can usually be dropped.
- 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).