liveBook · Manning

External style

As explained in Web Design Playground

A style sheet stored in a separate CSS file and linked to an HTML document instead of being written inline or in a style element.

An external style sheet is a second text file that holds CSS rules for a web page. Instead of placing those rules directly in HTML, save them in a file—traditionally with a .css name such as styles.css—and attach that file to the page. Think of it as one costume rack that several pages can use. section 7.7

This is especially handy once a site has more than one page. Copying an internal <style> element into every page creates repeated work; changing a shared rule then means changing it everywhere. A shared external file makes a consistent look much easier to maintain. section 7.6

Set up an external style sheet in three small steps:

  • Create a CSS file and write ordinary CSS rules in it. The rules use selectors, braces, properties, and values, but do not need a <style> element. section 7.7
  • Place a <link> element in the HTML page’s head section so the browser knows about the file. section 7.7
  • Give href the right location: a filename for the same directory, css/styles.css for a subdirectory, /css/styles.css from the site root, or a full URL for a remote file. section 7.7

A stylesheet beside the page

If styles.css sits in the same directory as an HTML page, link it like this: <link href="styles.css" rel="stylesheet"> The browser loads the CSS file and applies its rules to the page. In HTML5, type="text/css" is not needed on this link. section 7.7

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

Use this compact link as a starting point when the HTML file and CSS file live together. section 7.7

External style sheets are one source in the CSS cascade. When the same rule conflicts across style sources, external styles have more weight than browser default and user styles, but less weight than internal and inline styles. section 19.26

Try it: make a styles.css file, add one rule, link it from two HTML pages, then change the rule once. Both pages should reflect the change. section 7.6 section 7.7

How Web Design Playground covers it

How deep it goes
Explains file creation, CSS-rule syntax, link placement, four href locations, and cascade precedence; it does not detail stylesheet loading internals.
Examples
Demonstrates links to styles.css, css/styles.css, /css/styles.css, and a remote Google Fonts URL.
What it assumes
Builds on earlier CSS rule syntax and requires placing a link element in an HTML head section.
What you can do after
Apply it via the link element to attach a shared CSS file using local, root-relative, or remote URLs.
How it connects
Connects external style sheets with CSS rules, the link element, internal styles, inline styles, and the CSS cascade.

Also explained in

Compare how 2 books explain external style →

Related concepts

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