Styles in the Document
Inline styles work, but imagine you want all the paragraphs on a page to be green. You would have to add the same style attribute to every paragraph, and if you changed your mind, you would have to change each of them again.
That’s why CSS has rules. A rule says which elements to style and how. It starts with a selector, which selects the elements, followed by declarations in curly braces:
li {
color: orange;
text-align: center;
}The selector li selects all li elements on the page, so this rule makes all list items orange and centered. The declarations are the same as in the style attribute. It is customary to write each declaration on its own line, indented, and to end each one with a semicolon, even the last one.
The second way to add CSS to a page is to write rules in the style element. It goes into head, because it isn’t part of the content of the page, but information about how to display it:
<head>
<meta charset="utf-8">
<title>Domestic Cat</title>
<style>
li {
color: orange;
}
</style>
</head>Instructions
- 1
In
head, below thetitleelement, add an emptystyleelement:<style></style>. - 2
In the
styleelement, create a rule forpwith the declarationcolor: green. Both paragraphs will turn green at once.