3.11 External CSS Files

Overview

In general, splitting up a big thing into smaller parts makes the thing easier to understand. To improve understandability, you should consider moving your CSS rules to an external file. There are two steps necessary to tie a web page to an external file that contains CSS rules. First, for the external file to be recognized as a CSS file, the external file must be named with a .css extension. For example, in an upcoming web page, we’ll use the filename pumpkinPatch.css. Second, for the web page to access a CSS file’s CSS rules, the web page must use a link element in the web page’s head container. The link element is a void element, so it’s comprised of just one tag, with no end tag. Here’s the syntax:

Get Web Programming with HTML5, CSS, and JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.