- CSS Tutorial
- CSS - Home
- CSS - Introduction
- CSS - Syntax
- CSS - Selectors
- CSS - Inclusion
- CSS - Measurement Units
- CSS - Colors
- CSS - Backgrounds
- CSS - Fonts
- CSS - Text
- CSS - Images
- CSS - Links
- CSS - Tables
- CSS - Borders
- CSS - Border Block
- CSS - Border Inline
- CSS - Margins
- CSS - Lists
- CSS - Padding
- CSS - Cursor
- CSS - Outlines
- CSS - Dimension
- CSS - Scrollbars
- CSS - Inline Block
- CSS - Dropdowns
- CSS - Visibility
- CSS - Overflow
- CSS - Clearfix
- CSS - Float
- CSS - Arrows
- CSS - Resize
- CSS - Quotes
- CSS - Order
- CSS - Position
- CSS - Hyphens
- CSS - Hover
- CSS - Display
- CSS - Focus
- CSS - Zoom
- CSS - Translate
- CSS - Height
- CSS - Hyphenate Character
- CSS - Width
- CSS - Opacity
- CSS - Z-Index
- CSS - Bottom
- CSS - Navbar
- CSS - Overlay
- CSS - Forms
- CSS - Align
- CSS - Icons
- CSS - Image Gallery
- CSS - Comments
- CSS - Loaders
- CSS - Attr Selectors
- CSS - Combinators
- CSS - Root
- CSS - Box Model
- CSS - Counters
- CSS - Clip
- CSS - Writing Mode
- CSS - Unicode-bidi
- CSS - min-content
- CSS - All
- CSS - Inset
- CSS - Isolation
- CSS - Overscroll
- CSS - Justify Items
- CSS - Justify Self
- CSS - Tab Size
- CSS - Pointer Events
- CSS - Place Content
- CSS - Place Items
- CSS - Place Self
- CSS - Max Block Size
- CSS - Min Block Size
- CSS - Mix Blend Mode
- CSS - Max Inline Size
- CSS - Min Inline Size
- CSS - Offset
- CSS - Accent Color
- CSS - User Select
- CSS Advanced
- CSS - Grid
- CSS - Grid Layout
- CSS - Flexbox
- CSS - Visibility
- CSS - Positioning
- CSS - Layers
- CSS - Pseudo Classes
- CSS - Pseudo Elements
- CSS - @ Rules
- CSS - Text Effects
- CSS - Paged Media
- CSS - Printing
- CSS - Layouts
- CSS - Validations
- CSS - Image Sprites
- CSS - Important
- CSS - Data Types
- CSS3 Tutorial
- CSS3 - Tutorial
- CSS - Rounded Corner
- CSS - Border Images
- CSS - Multi Background
- CSS - Color
- CSS - Gradients
- CSS - Box Shadow
- CSS - Box Decoration Break
- CSS - Caret Color
- CSS - Text Shadow
- CSS - Text
- CSS - 2d transform
- CSS - 3d transform
- CSS - Transition
- CSS - Animation
- CSS - Multi columns
- CSS - Box Sizing
- CSS - Tooltips
- CSS - Buttons
- CSS - Pagination
- CSS - Variables
- CSS - Media Queries
- CSS - Functions
- CSS - Math Functions
- CSS - Masking
- CSS - Shapes
- CSS - Style Images
- CSS - Specificity
- CSS - Custom Properties
- CSS Responsive
- CSS RWD - Introduction
- CSS RWD - Viewport
- CSS RWD - Grid View
- CSS RWD - Media Queries
- CSS RWD - Images
- CSS RWD - Videos
- CSS RWD - Frameworks
- CSS References
- CSS - Questions and Answers
- CSS - Quick Guide
- CSS - References
- CSS - Color References
- CSS - Web browser References
- CSS - Web safe fonts
- CSS - Units
- CSS - Animation
- CSS Resources
- CSS - Useful Resources
- CSS - Discussion
CSS - @counter-styles
The @counter-styles CSS at-rule allows authors to create custom counter styles that aren't included in the standard styles. A @counter-styles rule outlines how to change a counter value into a string representation.
Syntax
@counter-style = @counter-style <counter-style-name> { <declaration-list> }
Every @counter-style has a name and a set of descriptors associated with it. All the descriptors are listed at the end of this topic.
CSS @counter-styles - Symbols Counter Style
This program demonstrates the usage of the @counter-styles property using symbols. In this code, we define a custom counter style named cyclic-counter using the @counter-style rule. We specify the cyclic system, which cycles through the symbols Ⓐ, Ⓑ, Ⓒ, and Ⓓ. We also set a space as the suffix for the counter.
<html> <head> <style> /* Define the counter style */ @counter-style cyclic-counter { system: cyclic; symbols: Ⓐ Ⓑ Ⓒ Ⓓ ; suffix: " "; } /* Apply the counter style to the elements */ .democounter { counter-reset: my-counter; } .democounter-item::before { counter-increment: my-counter; content: counter(my-counter, cyclic-counter); color: red; } </style> </head> <body> <div class="democounter"> <div class="democounter-item">Item 1</div> <div class="democounter-item">Item 2</div> <div class="democounter-item">Item 3</div> <div class="democounter-item">Item 4</div> <div class="democounter-item">Item 5</div> <div class="democounter-item">Item 6</div> <div class="democounter-item">Item 7</div> <div class="democounter-item">Item 8</div> <div class="democounter-item">Item 9</div> <div class="democounter-item">Item 10</div> </div> </body> </html>
CSS @counter-styles - Alphabetic Counter Styles
Following example demonstrates usage of the @counter-styles property using alphabets.
The @counter-style rule is used to define a new counter style named alphabetic.
The system property is set to alphabetic to specify that the counter should use alphabetic characters.
The symbols property is used to define the list of alphabetic characters from 'a' to 'c'.
The ul element is styled with the list-style property set to alphabetic, which applies the alphabetic counter style to the list.
<html> <head> <style> @counter-style alphabetic { system: alphabetic; symbols: 'a' 'b' 'c'; } ul { list-style: alphabetic; } </style> </head> <body> <ul> <li>Item 1</li> <li>Item 2</li> <li>Item 3</li> <li>Item 4</li> <li>Item 5</li> <li>Item 6</li> <li>Item 7</li> <li>Item 8</li> <li>Item 9</li> </ul> </body> </html>
Descriptors
The table given below lists all the descriptors related to @counter-styles
Descriptor | Description |
---|---|
system | Specifies the method for turning the integer value of a counter into a string form. |
additive-symbols | Used to define counter symbols when the @counter-style system descriptor value is configured as additive. |
negative | Allows the author to add symbols at the start or end of the counter representation if the value is negative. |
prefix | Defines a symbol to be added at the beginning of the marker representation. |
suffix | Defines a symbol to be added after the marker representation. |
range | Specifies the range of values for which the counter style is valid. |
pad | This is used when you want marker representations to have a minimum length. |
fallback | Specifies a fallback system to use if the defined system can't create the representation of a counter value or if the value is beyond the specified range. |
speak-as | This descriptor explains how to interpret the counter style for speech synthesizers like screen readers. |
symbols | Defines the symbols used for marker representations. |
The descriptors symbols and speak-as are not supported by most of the browsers.