CSS counter-increment प्रॉपर्टी का उपयोग करके CSS काउंटर के मान को बढ़ाया (increment) जाता है। यह आमतौर पर ::before या ::after स्यूडो-एलिमेंट के साथ counter-reset प्रॉपर्टी के संयोजन में उपयोग किया जाता है।
उदाहरण
नीचे दिए गए उदाहरण में, प्रत्येक <h2> तत्व के लिए काउंटर बढ़ाया जाता है और उसके सामने नंबर प्रदर्शित किया जाता है।
<!DOCTYPE html>
<html>
<head>
<style>
body {
counter-reset: section;
}
h2::before {
counter-increment: section;
content: "Fruit " counter(section) " - ";
}
</style>
</head>
<body>
<h1>Fruits</h1>
<h2>Mango</h2>
<h2>Kiwi</h2>
</body>
</html>
कैसे काम करता है:
counter-reset: section- पैरेंट (body) पर काउंटर "section" को 0 पर रीसेट करता हैcounter-increment: section- प्रत्येकh2के लिए काउंटर को 1 से बढ़ाता हैcontent: "Fruit " counter(section) " - "- काउंटर मान को कंटेंट में सम्मिलित करता है
उन्नत उपयोग: counter-increment: section 2 से 2 से बढ़ा सकते हैं, counter-increment: section -1 से घटा सकते हैं।