Summary
Use styles to change the look of your content. Collect styles for a page in a stylesheet. Link the stylesheet to your page.
Situation
You want to change the look of content on a page. For example, you want to change the font and background color of the entire page, the font color of headings, etc.
Action
- Create a new file with a .css extension. That's the stylesheet.
- Add rules to the stylesheet defining the look you want.
- Link the .css file to your page.
Example HTML:
- <!doctype html>
- <html lang="en">
- <head>
- <title>Doggos</title>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
- <link rel="stylesheet" href="styles.css">
- </head>
- <body>
- <h1>True facts about doggos</h1>
- <h2>Happiness</h2>
- <p>Doggos make humans happy. They do.</p>
- <p>It's a fact.</p>
- <h2>Love</h2>
- <p>Your doggo loves you.</p>
- </body>
- </html>
Line 7 tells the browser to look in the file styles.css to find out how to style the HTML.
Here's the stylesheet, styles.css:
- body {
- font-family: sans-serif;
- background-color: antiquewhite;
- }
- h1 {
- color: darkred;
- font-family: cursive
- }
- h2 {
- color: darkgreen;
- }
Where referenced