<ul>
  <li>Item 1</li>
  <li>Item 2</li>
  <li>Item 3</li>
  <li>Item 4</li>
  <li>Item 5</li>
</ul>
// Read an explanation of how this works in the related tutorial:
// @link https://moderncss.dev/guide-to-advanced-css-selectors-part-two/

li:nth-child(3n + 1) {
  background-color: rebeccapurple;
}

li:nth-child(3n + 2) {
  background-color: darkcyan;
}

li:nth-child(3n + 3) {
  background-color: lightskyblue;
  color: rgba(0, 0, 0, 0.7);
}

ul {
  list-style: none;
  padding: 0;
  margin: 0;
  min-height: 100vh;
  display: grid;
}

li {
  display: grid;
  place-content: center;
  padding: 1rem 0.5rem;
  text-align: center;
  color: rgba(255, 255, 255, 0.95);
  font-weight: bold;
  font-size: 2rem;
}
View Compiled

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.