Cover by Jennifer Niederst Robbins

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

O'Reilly logo

Chapter 6. Adding Links

If you’re creating a page for the Web, chances are you’ll want it to point to other web pages and resources, whether on your own site or someone else’s. Linking, after all, is what the Web is all about. In this chapter, we’ll look at the markup that makes links work—links to other sites, to your own site, and within a page. There is one element that makes linking possible: the anchor (a).

HTML Element

<a>...</a>

Anchor element (hypertext link)

To make a selection of text a link, simply wrap it in opening and closing <a>...</a> tags and use the href attribute to provide the URL of the target page. The content of the anchor element becomes the hypertext link. Here is an example that creates a link to the O’Reilly Media website:

<a href="http://www.oreilly.com">Go to the O'Reilly Media site</a>

To make an image a link, simply put the img element in the anchor element:

<a href="http://www.oreilly.com"><img src="orm.gif" alt="O'Reilly tarsier logo"></a>

Nearly all graphical browsers display linked text as blue and underlined by default. Some older browsers put a blue border around linked images, but most current ones do not. Visited links generally display in purple. Users can change these colors in their browser preferences, and, of course, you can change the appearance of links for your sites using style sheets. I’ll show ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required