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

553

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

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

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

CSS Customization

/* Custom color scheme */
.counter-card {
  background: rgba(your-color, 0.1);
  border-color: rgba(your-color, 0.2);
}

/* Custom animation duration */
.counter-number {
  transition: all 0.5s ease;
}

/* Custom hover effects */
.counter-card:hover {
  transform: translateY(-15px) scale(1.02);
}

API Methods

const counter = new AnimatedCounter();

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

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

// Performance monitoring
const metrics = counter.getPerformanceMetrics();

// Cleanup
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

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

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

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

HTML

58

lines

CSS

248

lines

JavaScript

247

lines


                <div class="counter-container">
  <div class="counter-grid">
    <!-- Counter 1: Basic Number -->
    <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>
    
    <!-- Counter 2: Percentage -->
    <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>
    
    <!-- Counter 3: Large Number with K -->
    <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>
    
    <!-- Counter 4: Years of Experience -->
    <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>
    
    <!-- Counter 5: Revenue with Currency -->
    <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>
    
    <!-- Counter 6: Downloads -->
    <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>
  
  <!-- Control Buttons -->
  <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
2258characters
HTMLLanguage

Related Code Snippets

Explore template packs

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

Open HTML Template Library β†’