Introduction to @counter-style in CSS

css counter style introduction
01 December 2024

If you are looking for a fun and creative way to display ordered lists on your website, using the @counter-style directive in CSS is an excellent option. This directive helps you customize the appearance and feel of counters to match your personal style. Now why is this topic great? Well, you can easily start from zero and design your own counters - something that adheres to your standards and can be used for creating lists that are unique to individuals.

For example, if you like lists that display letters or specific characters instead of numbers, @counter-style is exactly the tool you need. Real-world applications of this feature can combine seamlessly with other CSS features to design responsive and user-friendly pages.

Another appealing capability of this feature is the ability to define prefixes and suffixes for counters that allow you to create a more complex user experience. Suppose you want the prefix "Season" and the suffix "Page" to automatically be added next to the numeric values of seasons and your own page. This feature makes it very simple for you.

Despite its simplicity in definition and use, the power of this capability is quite extensive and can be used in various projects, from designing news sites to culturally literary blogs that require more personalized customization. It is enough to try this feature once to understand how you can implement your creative ideas effortlessly.

Example Code for Using @counter-style


@counter-style example-style {
system: numeric;
symbols: ''👍' '👎';
prefix: "(";
suffix: ")";
}

ul {
list-style: example-style;
}

Line-by-Line Explanation of the Code

@counter-style example-style
This line creates a new counter style named example-style.

system: numeric;
This line indicates that the counter is numerical.

symbols: '👍' '👎';
This line defines the symbols that will be used to display the numbers.

prefix: "(";
This line specifies a prefix that appears before each displayed number.

suffix: ")";
This line specifies a suffix that appears after each displayed number.

ul { list-style: example-style; }
This line indicates that all ordered lists will use this counter style.

FAQ

?

How can I use @counter-style?

?

Can I use special symbols in @counter-style?