Grouping Selectors

Quite often, you may end up having elements with the same style definitions, like this:

HTML file: Displayed by browser:
<style>
h1 {
   text-align: center;
   color: purple;
}
h2 {
   text-align: center;
   color: purple;
}
p {
   text-align: center;
   color: purple;
}
</style>
<body>
  <h1>Hello World!</h1>
  <h2>Smaller Heading.</h2>
  <p>This is a paragraph.</p>
</body>

Hello World!

Smaller Heading.

This is a paragraph.

We can group these selectors, to minimize the code. In other words, just type the declarations once, instead of three times...

Back buttonTable of ContentsNext button