Specific Selections

You can also specify that only specific HTML elements should be affected by a class. In the example below, all <p> elements with class="center" will be made green and center-aligned:

HTML file: Displayed by browser:
<style>
p.center {
    text-align: center;
    color: green;
}
</style>
<body>
  <h1 class="center">Heading is unaffected.</h1>
  <p class="center">Green and center-aligned paragraph.</p>
</body>

Heading is unaffected.

Green and center-aligned paragraph.

Just as with the ID, NEVER start a class name with a number!

Back buttonTable of ContentsNext button