liveBook · Manning

Link element

As explained in Web Design Playground, Second Edition

The HTML link element declares a relationship between the current document and an external resource such as a style sheet or hosted font resource.

The link element connects an HTML page to an external resource. Most commonly, it attaches a separate CSS file, keeping presentation rules out of the page and making shared styling much easier. section 7.4

Place the tag in the page’s head section. Its href points to the resource, while rel="stylesheet" tells the browser what relationship that resource has to the page. The href can name a nearby file, describe a subdirectory path, use a root-based path, or contain a full remote URL. section 7.4

Common external stylesheet locations include:

Attach a stylesheet

Add this inside <head>: <link href="styles.css" rel="stylesheet">. Several pages can link to the same file, so one CSS change updates their shared look. The old type="text/css" attribute may appear in examples, but HTML5 does not require it. section 7.4

The same element can load hosted web fonts. Font services such as Google Fonts provide generated link tags; paste those tags into <head>, before the link to your own CSS file. Then use the chosen family in CSS, such as font-family: Lato, sans-serif. Hosted services handle font licensing and hosting, though remote files and multiple font links can add loading time. section 18.3

<link href="styles.css" rel="stylesheet">

Inspect a minimal stylesheet link, then compare it with the generated Google Fonts links for a more complete head-section example. section 7.4 section 18.3

How Web Design Playground, Second Edition covers it

How deep it goes
Explains relationship and path attributes, placement, several URL forms, shared CSS benefits, and hosted-font trade-offs.
Examples
Uses local CSS paths, a remote stylesheet URL, and Google Fonts links for the Lato typeface.
What it assumes
Assumes basic HTML head placement and CSS usage while teaching external resource paths from the ground up.
What you can do after
Apply it via HTML to attach shared CSS files and hosted fonts in a page head.
How it connects
Connects HTML head sections with external style sheets, CSS, web fonts, and font hosting services.

Also explained in

Compare how 3 books explain link element →

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.