Structure and Formatting of a CSS Rule
For ease of readability, keep all declarations indented one level from their selector, and the closing curly brace on its own line. Add a single space after selectors and colons, and always place a semicolon after the final declaration.
If there are only one or two declarations, you might get away with this one. Not recommended for most cases. Always be consistent when possible.
When you group CSS selectors, you apply the same styles to several different elements without repeating the styles in your style sheet. Use a comma to separate multiple grouped selectors.
So the blue color applies to all
<div> elements and all
<p> elements. Without the comma only
<p> elements that are a child of a
<div> would be red.
This also applies to all types of selectors.
This rule applies to:
- elements of the
- element with the ID
<span>inside of a
Some properties can take multiple values, collectively known as a property list.
Rules, Selectors, and Declaration Blocks
A CSS rule consists of a selector (e.g.
h1) and declaration block (