CSS custom numbered list styling

I'm a full-stack developer from South Africa 🇿🇦. I love writing about JavaScript, HTML and CSS.
Search for a command to run...

I'm a full-stack developer from South Africa 🇿🇦. I love writing about JavaScript, HTML and CSS.
No comments yet. Be the first to comment.
Most of you know me for my consistency, a golden arrow in my blog series. I've written 1000 articles in 1008 days! Almost an article a day, and my honeymoon was the only holiday I ever took. I'm super proud of this achievement; it has been a fantasti...

It's not the first time I'll be talking about community. I think it's an essential aspect of any successful tool. This shows in my previous explorations of Astro, Medusa, and now Vendure as well. All these products thrive in a super open, welcoming, ...

The cool part about Vendure is how easy it is to set up and how abstract each layer is. Basically, we get the following elements: External database Server Worker Admin UI Frontend While this is amazing, it also brings a bit of complexity when it co...

The previous article looked at customizing Vendure on a data and process level. In this article, we'll look at customizing emails, as they are often a big part of a webshop system. We'll be looking at two different layers of customization for customi...

Even though Vendure is a pretty significant project out of the box, in some cases, we might want to go in and modify some elements to work to our specific use case. In this article, I'll take a high-level look at some elements we can customize within...

The other day we made an emoji list. And I wanted to include another powerful CSS property called CSS Counters.
This is the end result in Codepen.
They are variables controlled by CSS, whose values can increment by certain CSS rules.
We can use the following properties in CSS.
content -> Used to place the counter() property.counter-reset -> Creates or resets an countercounter-increment -> Increment a specific countercounter() -> Adds the value to an elementLet's create a very simple example using two lists, we want each list to re-start the counter.
<div>
<ol>
<li>Item #1</li>
<li>Item #2</li>
<li>Item #3</li>
<li>Item #4</li>
<li>Item #5</li>
</ol>
</div>
<div>
<ol>
<li>Item #1</li>
<li>Item #2</li>
<li>Item #3</li>
<li>Item #4</li>
<li>Item #5</li>
</ol>
</div>
So how do we now use CSS counters?
Let's start with the <ol> element.
ol {
counter-reset: custom;
list-style-type: none;
padding: 0;
margin: 0px 20px;
}
We start by resetting the list counter called custom.
Then we remove the default list-style since we are going to add this custom one.
Now we can move on to the <li> styling.
ol li {
counter-increment: custom;
padding: 15px 0;
display: flex;
align-items: center;
}
Here we increment the custom counter and add some basic padding and alignment.
Now we need to actually use this counter in a before pseudo element.
ol li:before {
content: counters(custom,".") " ";
width: 30px;
height: 30px;
margin-right: 10px;
background: purple;
color: #fff;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
}
As you can see, we place our custom counter in the content element. We then add some basic styling to make it look a little bit nicer.
I'm using a lot of flex options to style everything centered.
Now that you have seen my introduction check what these amazing people made with this cool CSS property.
Check this cool gradient one made by Mattia Astorino
Or this section layout one made by Jonathan Snook
Or even this absurdly good Tic-Tac-Toe with counters by Sαwsαn
And the good news?
CSS Counters are fully supported! 🎉

Thank you for reading my blog. Feel free to subscribe to my email newsletter and connect on Facebook or Twitter