Glossary
HTML
CSS
JavaScript
Python

CSS

Class attribute in CSS

If we want to select one or more elements, we can set a class attribute for the exact elements we want to change.

In the stylesheet, we can set a new class rule with a . followed by the name of the class. Like here with .gray-element.

 <head>
  <link rel="stylesheet" href="style.css">
 </head>
 <body>
  <ol> TO DO: <li class="gray-element">Floss</li>
   <li>Feed Cat</li>
   <li class="gray-element">Nap</li>
   <li>Plan holiday</li>
   <li class="gray-element">Order tea</li>
  </ol>
 </body>

.gray-element {
 background-color: lightgrey;
}
Learn to Code in Python for Free
Start learning now
To advance beyond this tutorial and learn Python by doing, try the interactive experience of Mimo. Whether you're starting from scratch or brushing up your coding skills, Mimo helps you take your coding journey above and beyond.

Sign up or download Mimo from the App Store or Google Play to enhance your programming skills and prepare for a career in tech.

You can code, too.

© 2023 Mimo GmbH