Using CSS Counter, counter-reset, and counter-increment.
<h1>Testing the Counter</h1>
<ul>
<li>ITEM 1</li>
<li class="invalid">ITEM 2 - is invalid</li>
<li>ITEM 3</li>
<li class="invalid">ITEM 4 - is invalid</li>
<li class="invalid">ITEM 5 - is invalid</li>
<li class="invalid">ITEM 6 - is invalid</li>
</ul>
<p>DETAILS: </p>
<style>
body {
counter-reset: invalidCount;
}
.invalid {
background-color: pink;
counter-increment: invalidCount;
}
p:after {
content: "You have " counter(invalidCount) " invalid entries";
}
</style>
EMBED: