HTML gives a page its structure while CSS controls how it looks. A stylesheet link in the HTML tells the browser where to load the CSS file so it can apply the file's rules to the page.

Several pages can share one stylesheet. Changing a rule in that file can update the look of matching elements across all the pages that link to it.

A relative stylesheet path normally starts from the HTML page's location. The link can stay the same when the two files move together and keep the same folder layout.

  1. Save this starter markup as index.html in a new test folder with no files.
    index.html
    <!doctype html>
    <html lang="en">
    <head>
      <meta charset="utf-8">
      <title>Trail Notes</title>
    </head>
    <body>
      <h1>Trail Notes</h1>
      <p>Weekend routes.</p>
    </body>
    </html>
  2. Enter this rule in a new stylesheet in your text editor.
    styles.css
    h1 {
      background-color: #dbeafe;
      color: #17365d;
      padding: 0.5em;
    }
  3. Save the untitled stylesheet as styles.css in the same test folder.
  4. Insert this stylesheet link just before </head> in index.html.
    <link rel="stylesheet"
      href="styles.css">

    rel=“stylesheet” identifies the resource as a stylesheet. href holds its path. If your file is inside a css subfolder, for example, its path from index.html is css/styles.css.

  5. Save your changes to index.html in the same test folder.
  6. Open the saved index.html at its local file URL in your browser.

    If the file is already open in the browser, reload the page to pick up the saved edit.

  7. Check that the Trail Notes heading appears on a light blue band.

    If the band is missing, check that href matches the stylesheet's name and folder and that the file has the .css extension. After a path or filename correction, reload the page to check the heading again.

Share this guide