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.
Steps to link a CSS file in HTML:
- Enter this rule in a new stylesheet in your text editor.
- styles.css
h1 { background-color: #dbeafe; color: #17365d; padding: 0.5em; }
- Save the untitled stylesheet as
styles.cssin the same test folder. - Insert this stylesheet link just before </head> in
index.html.<link rel="stylesheet" href="styles.css">
rel=“stylesheet”identifies the resource as a stylesheet.hrefholds its path. If your file is inside acsssubfolder, for example, its path fromindex.htmliscss/styles.css. - Save your changes to
index.htmlin the same test folder. - Open the saved
index.htmlat 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.
- Check that the
Trail Notesheading appears on a light blue band.
If the band is missing, check that
hrefmatches the stylesheet's name and folder and that the file has the.cssextension. After a path or filename correction, reload the page to check the heading again.