liveBook · Manning

Href

As explained in Web Design Playground, Second Edition

The href attribute is an HTML attribute that specifies the destination address of a hypertext link.

The href attribute tells a link where to go. Place it inside an <a> element, set it to an address, and wrap the clickable words between the opening and closing tags. href means “hypertext reference”—a fancy name for a destination address. section 2.15 section 2.2

Choose the href value according to the destination:

  • Local page: use the filename when the linked file is in the same directory, such as href="wordplay.html". section 2.15 section 2.16
  • Remote page: use the full URL, such as href="https://webdesignplayground.io/". section 2.2 section 2.16
  • Same-page location: point to an element’s id with a hash, such as href="#details". section 16.7

A complete link

<a href="wordplay.html">Explore wordplay</a> The browser displays “Explore wordplay” as clickable text. Clicking it opens wordplay.html. Keep the quotation marks around the address, and check capitalization carefully: a mismatched filename or directory letter can lead to a 404 Not Found error. section 2.15

Figure 2.7 The syntax to use for the <a> tag

Use the syntax figure to see how the <a> element, href attribute, destination address, and clickable link text fit together. section 2.15

How Web Design Playground, Second Edition covers it

How deep it goes
Defines the attribute, demonstrates syntax and address types, and notes case sensitivity; defers complex directory paths and anchor details.
Examples
Shows wordplay.html, a webdesignplayground.io URL, and links to “scofflaw” and “Frankenfood.”
What it assumes
Teaches attributes and URLs in plain language before applying href inside an anchor element.
What you can do after
Apply it via HTML to make clickable text open a local file, remote URL, or same-page target.
How it connects
Connects anchor elements, URLs, HTML attributes, local files, remote pages, and id attributes.

Also explained in

Compare how 3 books explain href →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Web Design Playground, Second Edition. The section links point to the parts of the book it draws on.