loading-animations
intermediate
counter
animation
statistics
numbers
scroll
Category · Loading Animations Difficulty Level · Intermediate Published on · January 22, 2024

Animated Counter

Smooth animated counter component with customizable easing, multiple number formats, and intersection observer for performance. Perfect for statistics and achievements sections.

#counter #animation #statistics #numbers #scroll

Responsive Design

Yes

Dark Mode Support

Yes

lines

523

Browser Compatibility

No

Live Preview

Interact with the component without leaving the page.

400px

Animated Counter

A sophisticated animated counter component with smooth easing animations, multiple number formats, and intersection observer for performance optimization. Perfect for displaying statistics, achievements, and key metrics with visual impact.

Features

  • Smooth Animations: Cubic easing with customizable duration
  • Multiple Formats: Regular numbers, currency, percentages, and compact notation
  • Auto-trigger: Intersection Observer for scroll-based animation
  • Staggered Animation: Sequential counter animations for visual appeal
  • Performance Optimized: RequestAnimationFrame for 60fps animations
  • Responsive Design: Adaptive grid layout for all screen sizes
  • Accessibility: Screen reader friendly with proper ARIA labels
  • Customizable: Easy to configure targets, durations, and formats

Number Formats

  • Regular: Standard number formatting with locale support
  • Currency: Automatic K/M suffixes for large amounts
  • Compact: Abbreviated notation (1.5K, 2.3M)
  • Percentage: Decimal precision control
  • Custom Prefixes/Suffixes: Dollar signs, plus symbols, etc.

Animation Features

  • Easing Functions: Smooth cubic-bezier transitions
  • Visual Feedback: Glow effects during animation
  • Completion States: Pulse animation when target reached
  • Progress Indicators: Optional loading rings
  • Stagger Control: Customizable delay between counters

Performance Optimizations

  • Intersection Observer for viewport detection
  • RequestAnimationFrame for smooth animations
  • Efficient DOM manipulation
  • Memory leak prevention with cleanup methods
  • Throttled scroll events

Customization Options


const config = {
  target: 1500,
  duration: 3000,
  decimals: 1,
  format: 'compact',
  icon: '🎯',
  label: 'Goals Achieved',
  suffix: '+'
};

const grid = document.querySelector('.counter-grid');
const counter = createCounter(grid, config);

CSS Customization

.counter-card {
  background: rgba(your-color, 0.1);
  border-color: rgba(your-color, 0.2);
}.counter-number {
  transition: all 0.5s ease;
}.counter-card:hover {
  transform: translateY(-15px) scale(1.02);
}

API Methods

const counter = new AnimatedCounter();

counter.startAllCounters();     // Start all animations
counter.resetAllCounters();     // Reset all counters
counter.startCounter(0);        // Start specific counter
counter.resetCounter(0);        // Reset specific counter

counter.addCounter(element, 1000, 2000, {
  decimals: 2,
  format: 'currency'
});

const metrics = counter.getPerformanceMetrics();

counter.destroy();

Browser Support

  • Chrome 51+ (full support)
  • Firefox 55+ (full support)
  • Safari 12.1+ (full support)
  • Edge 15+ (full support)
  • iOS Safari 12.2+ (full support)

Accessibility Features

  • Semantic HTML structure
  • ARIA labels for screen readers
  • Keyboard navigation support
  • High contrast mode compatibility
  • Reduced motion support

Use Cases

  • Statistics Sections: Company achievements and metrics
  • Dashboard Widgets: Real-time data visualization
  • Landing Pages: Key performance indicators
  • Portfolio Sites: Project counts and success rates
  • E-commerce: Sales figures and customer counts
  • Analytics: User engagement metrics

Integration Examples


<div class="counter-number" data-target="1000" data-duration="2000">0</div>


<div class="counter-number" 
     data-target="2500000" 
     data-duration="3000" 
     data-format="currency">0</div>


<div class="counter-number" 
     data-target="98.5" 
     data-duration="2500" 
     data-decimals="1">0</div>

HTML

58

lines

CSS

236

lines

JavaScript

229

lines


                <div class="counter-container">
  <div class="counter-grid">
    
    <div class="counter-card">
      <div class="counter-icon">πŸ‘₯</div>
      <div class="counter-number" data-target="1250" data-duration="2000">0</div>
      <div class="counter-label">Happy Customers</div>
      <div class="counter-suffix">+</div>
    </div>
    
    
    <div class="counter-card">
      <div class="counter-icon">πŸ“ˆ</div>
      <div class="counter-number" data-target="98.5" data-duration="2500" data-decimals="1">0</div>
      <div class="counter-label">Success Rate</div>
      <div class="counter-suffix">%</div>
    </div>
    
    
    <div class="counter-card">
      <div class="counter-icon">πŸ’Ό</div>
      <div class="counter-number" data-target="15000" data-duration="3000" data-format="compact">0</div>
      <div class="counter-label">Projects Completed</div>
      <div class="counter-suffix"></div>
    </div>
    
    
    <div class="counter-card">
      <div class="counter-icon">πŸ†</div>
      <div class="counter-number" data-target="12" data-duration="1500">0</div>
      <div class="counter-label">Years Experience</div>
      <div class="counter-suffix"></div>
    </div>
    
    
    <div class="counter-card">
      <div class="counter-icon">πŸ’°</div>
      <div class="counter-prefix">\$</div>
      <div class="counter-number" data-target="2500000" data-duration="3500" data-format="currency">0</div>
      <div class="counter-label">Revenue Generated</div>
      <div class="counter-suffix"></div>
    </div>
    
    
    <div class="counter-card">
      <div class="counter-icon">⬇️</div>
      <div class="counter-number" data-target="500000" data-duration="2800" data-format="compact">0</div>
      <div class="counter-label">Total Downloads</div>
      <div class="counter-suffix">+</div>
    </div>
  </div>
  
  
  <div class="counter-controls">
    <button class="control-btn" id="startBtn">Start Animation</button>
    <button class="control-btn" id="resetBtn">Reset Counters</button>
  </div>
</div>

              
58lines
2024characters
HTMLLanguage

Related Code Snippets

Explore template packs

Need larger building blocks? Browse responsive landing pages and component bundles.

Open HTML Template Library ->