Responsive Breakpoints
ParticleText.js includes a sophisticated responsive breakpoint system that automatically adapts particle configurations based on screen size. With 9 breakpoints covering everything from tiny mobile screens to 4K displays, you can create experiences that look perfect on any device without writing media queries.
Understanding Breakpoints
Section titled “Understanding Breakpoints”Breakpoints are screen width thresholds that trigger different configuration values. The library continuously monitors the window width and applies the appropriate values from your configuration.
The 9 Breakpoints
Section titled “The 9 Breakpoints”| Breakpoint | Width Range | Typical Devices | Example Sizes |
|---|---|---|---|
| XXXS | 0px - 319px | Very small phones | Old phones, minimal viewports |
| XXS | 320px - 374px | Small phones | iPhone SE (1st gen) |
| XS | 375px - 767px | Standard phones | iPhone 12/13/14, most Android phones |
| SM | 768px - 1023px | Tablets (portrait) | iPad portrait, small tablets |
| MD | 1024px - 1439px | Tablets (landscape), small laptops | iPad landscape, 13” laptops |
| LG | 1440px - 2559px | Desktop monitors | 15-27” monitors, most desktops |
| XL | 2560px - 3439px | Large monitors | 27-32” QHD/4K monitors |
| XXL | 3440px - 3839px | Ultra-wide monitors | 34” ultra-wide, triple monitor setups |
| XXXL | 3840px+ | 4K+ displays | 4K monitors, 5K displays, multi-monitor |
Live Responsive Demo
Section titled “Live Responsive Demo”Responsive Particle Configuration
Try it: Resize your browser window and watch how the particles adapt to different screen sizes!
initParticleJS('#canvas', {text: 'RESPONSIVE',colors: ['#695aa6', '#8b7bb8'],
// Particles grow on larger screensparticleRadius: { xxxs: { base: 1, rand: 0.5 }, // Tiny: 1-1.5px xs: { base: 1.5, rand: 1 }, // Small: 1.5-2.5px md: { base: 2, rand: 1 }, // Medium: 2-3px lg: { base: 3, rand: 2 }, // Large: 3-5px xxxl: { base: 4, rand: 2 } // Huge: 4-6px},
// Explosion radius grows proportionallyexplosionRadius: { xxxs: 30, // Touch-friendly on tiny screens xs: 50, // Phone-optimized md: 75, // Tablet size lg: 150, // Desktop with mouse xxxl: 250 // Dramatic on 4K}});How Breakpoint Inheritance Works
Section titled “How Breakpoint Inheritance Works”One of the most powerful features is breakpoint inheritance - you don’t need to specify all 9 breakpoints. Values cascade upward:
Cascade Rules
Section titled “Cascade Rules”- If a breakpoint isn’t specified, it inherits from the nearest smaller breakpoint
- If no smaller breakpoint exists, it uses the library default
- Once you specify a breakpoint, all larger breakpoints inherit that value
- You can override at any breakpoint to change the cascade
Inheritance Examples
Section titled “Inheritance Examples”// Example 1: Minimal specificationparticleRadius: {xs: { base: 2, rand: 1 }}// Result:// xxxs/xxs → Default values// xs/sm/md/lg/xl/xxl/xxxl → 2-3px (all inherit from xs)
// Example 2: Mobile and desktopparticleRadius: {xs: { base: 1, rand: 1 }, // Mobile: 1-2pxlg: { base: 3, rand: 2 } // Desktop: 3-5px}// Result:// xxxs/xxs → Default// xs/sm/md → 1-2px (inherit from xs)// lg/xl/xxl/xxxl → 3-5px (inherit from lg)
// Example 3: Full controlparticleRadius: {xxxs: { base: 0.5, rand: 0.5 }, // Tiny screensxs: { base: 1, rand: 1 }, // Phonessm: { base: 1.5, rand: 1 }, // Tablets portraitmd: { base: 2, rand: 1 }, // Tablets landscapelg: { base: 3, rand: 2 }, // Desktopxl: { base: 4, rand: 2 }, // Large monitorsxxxl: { base: 5, rand: 3 } // 4K displays}// Each breakpoint explicitly definedResponsive Configuration Patterns
Section titled “Responsive Configuration Patterns”Mobile-First Approach (Recommended)
Section titled “Mobile-First Approach (Recommended)”Start with mobile configuration and enhance for larger screens:
{// Mobile base (xs)particleRadius: { xs: { base: 1, rand: 1 } },explosionRadius: { xs: 40 },friction: { base: 0.92, rand: 0.04 },
// Enhance for desktop (lg)particleRadius: { lg: { base: 2, rand: 2 } },explosionRadius: { lg: 120 },friction: { lg: { base: 0.88, rand: 0.06 } }}// xxxs/xxs inherit defaults// xs/sm/md get mobile values// lg/xl/xxl/xxxl get desktop valuesDesktop-First Approach
Section titled “Desktop-First Approach”Start with desktop and optimize for mobile:
{// Desktop base (lg)particleRadius: { lg: { base: 3, rand: 2 } },explosionRadius: { lg: 150 },
// Optimize for mobile (xs)particleRadius: { xs: { base: 1, rand: 0.5 } },explosionRadius: { xs: 40 }}// xxxs/xxs inherit defaults// xs/sm/md get mobile values// lg+ get desktop valuesThree-Tier Approach
Section titled “Three-Tier Approach”Mobile, tablet, and desktop:
{// Mobile (xs)particleRadius: { xs: { base: 1, rand: 1 } },explosionRadius: { xs: 40 },
// Tablet (sm)particleRadius: { sm: { base: 2, rand: 1 } },explosionRadius: { sm: 70 },
// Desktop (lg)particleRadius: { lg: { base: 3, rand: 2 } },explosionRadius: { lg: 150 }}Responsive Properties
Section titled “Responsive Properties”All responsive-capable properties support breakpoint configuration:
particleRadius
Section titled “particleRadius”particleRadius: {xs: { base: 1, rand: 0.5 }, // Mobile: small, denselg: { base: 3, rand: 2 } // Desktop: larger, more visible}explosionRadius
Section titled “explosionRadius”explosionRadius: {xxxs: 30, // Touch-friendly minimumxs: 50, // Standard mobilesm: 70, // Tabletlg: 120, // Desktop mousexxxl: 250 // Large displays}fontSize
Section titled “fontSize”fontSize: {xs: 40, // Readable on phonesm: 60, // Larger on tabletmd: 80, // Even largerlg: 120, // Desktop hero sizexxxl: 200 // Massive on 4K}Real-World Examples
Section titled “Real-World Examples”Professional Portfolio
Section titled “Professional Portfolio”initParticleJS('#canvas', {text: 'PORTFOLIO',colors: ['#2C3E50'],
// Small, dense particles on all devicesparticleRadius: { xs: { base: 1, rand: 1 }, lg: { base: 1.5, rand: 1 }},
// Conservative explosion radiusexplosionRadius: { xs: 40, lg: 80},
// Smooth friction everywherefriction: { base: 0.94, rand: 0.03 }});Creative Agency
Section titled “Creative Agency”initParticleJS('#canvas', {text: 'CREATIVE',colors: [ { color: '#E74C3C', weight: 5 }, { color: '#9B59B6', weight: 2 }, { color: '#F39C12', weight: 1 }],
// Medium particles, larger on desktopparticleRadius: { xs: { base: 2, rand: 1 }, sm: { base: 2, rand: 2 }, lg: { base: 3, rand: 3 }},
// Wide explosion on desktopexplosionRadius: { xs: 60, sm: 90, lg: 180, xxxl: 300},
// More bounce on desktopfriction: { xs: { base: 0.90, rand: 0.05 }, lg: { base: 0.85, rand: 0.08 }}});Gaming/Entertainment
Section titled “Gaming/Entertainment”initParticleJS('#canvas', {text: 'PLAY',colors: ['#FF6B6B', '#4ECDC4', '#FFD93D'],
// Large, playful particlesparticleRadius: { xs: { base: 3, rand: 2 }, // Big even on mobile lg: { base: 5, rand: 3 } // Huge on desktop},
// Generous explosionexplosionRadius: { xs: 80, lg: 200, xxxl: 400},
// Bouncy movementfriction: { base: 0.78, rand: 0.12 }});Minimal/Clean
Section titled “Minimal/Clean”initParticleJS('#canvas', {text: 'MINIMAL',colors: ['#000000'],
// Ultra-fine particlesparticleRadius: { xs: { base: 0.5, rand: 0.5 }, lg: { base: 1, rand: 0.5 }},
// Subtle interactionexplosionRadius: { xs: 30, lg: 50},
// Very smoothfriction: { base: 0.96, rand: 0.02 }});Getting Current Breakpoint
Section titled “Getting Current Breakpoint”Access the current breakpoint programmatically:
const instance = initParticleJS('#canvas', {text: 'HELLO',colors: ['#695aa6']});
// Get current breakpointconst breakpoint = instance.getCurrentBreakpoint();console.log(breakpoint); // 'xs', 'lg', etc.
// React to breakpoint changeswindow.addEventListener('resize', () => {const newBreakpoint = instance.getCurrentBreakpoint();console.log('Breakpoint changed to:', newBreakpoint);
// Trigger custom logic based on breakpointif (newBreakpoint === 'xs' || newBreakpoint === 'sm') { console.log('Mobile view detected');} else { console.log('Desktop view detected');}});Custom Breakpoints
Section titled “Custom Breakpoints”Override the default breakpoint detection:
const instance = initParticleJS('#canvas', {text: 'CUSTOM',colors: ['#695aa6']});
// Override with custom logicinstance.getCurrentBreakpoint = function() {const width = window.innerWidth;
// Your custom breakpoint logicif (width < 480) return 'mobile';if (width < 1024) return 'tablet';return 'desktop';};
// Now the library uses your custom breakpoints// Note: Your config should use these custom keys:// particleRadius: {// mobile: { base: 1, rand: 1 },// tablet: { base: 2, rand: 1 },// desktop: { base: 3, rand: 2 }// }Performance Optimization
Section titled “Performance Optimization”Use breakpoints to optimize performance on different devices:
{// Mobile: optimize for performanceparticleRadius: { xs: { base: 2, rand: 1 } // Larger particles = fewer total},maxParticles: 2000,supportSlowBrowsers: true,
// Desktop: can handle moreparticleRadius: { lg: { base: 1.5, rand: 1 } // Smaller = more particles}
// Note: maxParticles applies globally, but larger// particles on mobile means fewer will be rendered}Best Practices
Section titled “Best Practices”1. Mobile-First Design
Section titled “1. Mobile-First Design”Always consider mobile users first:
// ✅ Good: Mobile-optimized{particleRadius: { xs: { base: 1, rand: 1 } },explosionRadius: { xs: 40 },// Then enhance for desktopexplosionRadius: { lg: 120 }}
// ❌ Bad: Desktop-only thinking{explosionRadius: { lg: 150 }// Mobile users get defaults which might not be optimized}2. Test on Real Devices
Section titled “2. Test on Real Devices”Don’t just resize your browser:
- Use actual phones and tablets
- Test touch interactions
- Check performance on older devices
3. Specify Key Breakpoints
Section titled “3. Specify Key Breakpoints”You don’t need all 9, but specify the important ones:
// Minimum recommended{particleRadius: { xs: { base: 1, rand: 1 }, // Mobile lg: { base: 2, rand: 2 } // Desktop}}
// Better coverage{particleRadius: { xs: { base: 1, rand: 1 }, // Mobile sm: { base: 1.5, rand: 1 }, // Tablet lg: { base: 2, rand: 2 }, // Desktop xl: { base: 3, rand: 2 } // Large monitors}}4. Touch vs Mouse Considerations
Section titled “4. Touch vs Mouse Considerations”// Touch screens need larger interaction zonesexplosionRadius: {xs: 60, // Larger for fingerssm: 70, // Still touch-focusedlg: 100 // Mouse is more precise}
// Friction can be higher on mobile (smoother)friction: {xs: { base: 0.92, rand: 0.04 }, // Smooth on mobilelg: { base: 0.88, rand: 0.06 } // Bouncier on desktop}5. Proportional Scaling
Section titled “5. Proportional Scaling”Keep properties proportional to screen size:
// Particles, explosion, and font scale together{fontSize: { xs: 40, lg: 100, xxxl: 200},particleRadius: { xs: { base: 1, rand: 1 }, lg: { base: 2, rand: 2 }, xxxl: { base: 4, rand: 2 }},explosionRadius: { xs: 40, lg: 120, xxxl: 250}// Everything scales together harmoniously}Common Mistakes
Section titled “Common Mistakes”Mistake 1: Not Testing Mobile
Section titled “Mistake 1: Not Testing Mobile”// ❌ Works on desktop, terrible on mobile{explosionRadius: { lg: 200 }// Mobile gets default, might be too large/small}
// ✅ Tested on mobile{explosionRadius: { xs: 50, // Tested on actual phone lg: 200}}Mistake 2: Too Many Particles on Mobile
Section titled “Mistake 2: Too Many Particles on Mobile”// ❌ Performance issues on mobile{particleRadius: { xs: { base: 0.5, rand: 0.5 } // Tiny = many particles}}
// ✅ Optimized for mobile{particleRadius: { xs: { base: 2, rand: 1 }, // Larger = fewer particles lg: { base: 1, rand: 1 } // Desktop can handle smaller}}Mistake 3: Ignoring Tablet
Section titled “Mistake 3: Ignoring Tablet”// ❌ Binary mobile/desktop split{particleRadius: { xs: { base: 1, rand: 1 }, lg: { base: 3, rand: 2 }}// Tablets (sm/md) jump from 1-2px to 3-5px abruptly}
// ✅ Smooth progression{particleRadius: { xs: { base: 1, rand: 1 }, sm: { base: 1.5, rand: 1.5 }, // Tablet middle ground lg: { base: 3, rand: 2 }}}Troubleshooting
Section titled “Troubleshooting”Breakpoints not updating when resizing?
- The library automatically detects resize
- Check browser console for errors
- Verify you’re specifying breakpoint keys correctly (lowercase)
Configuration not applying to certain screens?
- Check your cascade logic
- Use
instance.getCurrentBreakpoint()to debug - Make sure you specified the right breakpoint keys
Particles look wrong on mobile?
- Test on actual device, not just browser resize
- Check if default values are being used
- Specify at least
xsbreakpoint for mobile
Performance issues on specific devices?
- Increase
particleRadiuson mobile (fewer particles) - Set
maxParticleslimit - Enable
supportSlowBrowsers: true
Related Documentation
Section titled “Related Documentation”- Breakpoint System Guide - Deep dive into breakpoint mechanics
- Particle Density - Control particle size
- Explosion Radius - Touch vs mouse optimization
- Performance Optimization - Mobile performance tips
- API Reference - Configuration - All responsive properties