Classes and ids
Styling p changes every paragraph. Usually you want to style only some elements. That is what classes and ids are for.
class
Add a class attribute in HTML, then select it in CSS with a dot:
<p class="warning">Mind the step.</p>
.warning {
color: crimson;
}
Many elements can share a class, and one element can have several classes, separated by spaces: class="warning big".
id
An id names one unique element on the page. Select it with a hash:
<h1 id="title">Welcome</h1>
#title {
color: navy;
}
Use classes for styling (they are reusable) and ids for the few elements that are truly unique, like the main title or a section people can link to (page.html#contact).
Your task
- Give the second paragraph the class
highlight, and make.highlighthave ayellowbackground. - Give the heading the id
title, and make#titlenavy.
Write the CSS in style.css.