Counter Widget

The Counter Widget animates a number counting up from 0 to a target value with smooth interpolation. It's perfect for displaying statistics, metrics, achievements, and any numerical data that needs to make an impact.

Basic Usage

<div data-type="counter" 
     data-end-number="1000" 
     data-decimal="false" 
     data-duration-animation="4" 
     data-start="1"
     class="text-6xl font-bold text-purple-600">
</div>

Attributes

Attribute
Type
Default
Description

data-type

string

-

Must be "counter"

data-end-number

number

1000

Final number to count to

data-decimal

string

"false"

Show decimal places: "true" or "false"

data-duration-animation

number

4

How long counting takes in seconds

data-start

number

0

When counting starts in seconds

Animation Behavior

Counting Animation

The counter widget creates a smooth counting animation:

  • Before start: Shows 0

  • During animation: Smoothly counts up with cubic easing

  • After animation: Shows final number

Number Formatting

  • Integers: Uses toLocaleString() for comma separation (e.g., "1,000,000")

  • Decimals: Shows 2 decimal places (e.g., "1,234.56")

Examples

Simple Counter

Multiple Counters

Decimal Counter

Styling Options

Text Sizes

Font Weights

Colors

Animation Timing

Fast Counter (2 seconds)

Slow Counter (8 seconds)

Delayed Start

Common Use Cases

Statistics Dashboard

Achievement Counter

Performance Metrics

Best Practices

Number Selection

Number Range
Recommended Duration
Use Case

1-100

2-3 seconds

Small metrics

100-10,000

3-4 seconds

Medium statistics

10,000+

4-6 seconds

Large numbers

Decimals

3-5 seconds

Percentages, rates

Visual Design

  • Large numbers: Use big font sizes (text-6xl to text-9xl) for impact

  • High contrast: Ensure good readability with contrasting colors

  • Bold fonts: Use bold or black font weights for emphasis

  • Supporting text: Add labels and descriptions below counters

Timing

  • Build anticipation: Start counter after other elements have appeared

  • Appropriate speed: Match counting speed to the number size

  • Smooth transitions: Use longer durations for large numbers

Advanced Techniques

Sequential Counters

Mixed with Other Widgets

Troubleshooting

Counter Not Animating

Problem: Number doesn't count up

Solutions:

  • Check that data-type="counter" is set correctly

  • Verify data-end-number is a valid number

  • Make sure data-start time is reasonable

  • Ensure data-duration-animation is set

Number Formatting Issues

Problem: Numbers don't display correctly

Solutions:

  • For integers: use data-decimal="false" or omit the attribute

  • For decimals: use data-decimal="true"

  • Large numbers automatically get comma separators

  • Check that data-end-number is a valid number

Animation Too Fast/Slow

Problem: Counting speed doesn't feel right

Solutions:

  • Adjust data-duration-animation value

  • Longer duration = slower counting

  • Shorter duration = faster counting

  • Consider the size of your target number

Counter Overlapping

Problem: Multiple counters overlap

Solutions:

  • Use different positioning classes

  • Space out the data-start times

  • Use different vertical positions

  • Add margins between elements


Last updated