Magnetic Field Card
The card is a field of iron filings on a white surface. A hidden magnet beneath the surface aligns the filings to form text and shapes. Hover introduces a second, weaker magnetic field that distorts and bends the filings near the cursor. Clicking flips the polarity, scattering everything into chaos before it reforms into a different layout. A granular shimmering accompanies the filings' movement.
by FreeCsStyles Dev's
Embed this component
Paste this snippet into any site — the design renders in a sandboxed iframe served from /embed/magnetic-field-card.
<iframe src="/embed/magnetic-field-card" sandbox="allow-scripts" loading="lazy" title="Magnetic Field Card" style="border:0;width:100%;height:480px;overflow:hidden"></iframe>Implementation code
Copy the HTML and CSS for Magnetic Field Card, or grab a framework-specific implementation. The HTML and CSS variants are self-contained; framework variants assume that framework's project setup.
HTML
<div class="magnetic-card" onclick="flipPolarity(this)">
<div class="magnetic-field" id="magnetic-field"></div>
<div class="magnetic-content">
<div class="magnetic-header">
<div><div class="magnetic-title">Magnetic Field</div><div class="magnetic-sub">Ferromagnetic</div></div>
<div class="magnetic-status" id="magnetic-status">STABLE</div>
</div>
<div class="magnetic-divider"></div>
<div class="magnetic-grid">
<div class="magnetic-stat"><div class="magnetic-stat-val">N→S</div><div class="magnetic-stat-lbl">Polarity</div></div>
<div class="magnetic-stat"><div class="magnetic-stat-val">60</div><div class="magnetic-stat-lbl">Filings</div></div>
</div>
<div class="magnetic-hint" id="magnetic-hint">[▼ click to flip]</div>
</div>
</div>
<script>
let flipped = false;
function flipPolarity(el) {
flipped = !flipped;
el.classList.toggle('flipped');
document.getElementById('magnetic-status').textContent = flipped ? 'REVERSED' : 'STABLE';
}
</script>CSS
.magnetic-card {
position: relative;
width: 220px;
min-height: 300px;
border-radius: 16px;
overflow: hidden;
background: linear-gradient(160deg, #f5f3f0, #e8e5e0);
border: 1.5px solid rgba(100,100,100,0.15);
box-shadow: 0 10px 30px rgba(0,0,0,0.1);
cursor: pointer;
transition: all 0.4s ease;
}
.magnetic-card:hover {
box-shadow: 0 20px 50px rgba(0,0,0,0.15), inset 0 0 30px rgba(100,100,100,0.03);
}
.magnetic-field {
position: absolute;
inset: 0;
z-index: 2;
pointer-events: none;
}
.magnetic-content {
position: absolute;
inset-x: 0;
bottom: 0;
z-index: 10;
padding: 20px;
display: flex;
flex-direction: column;
gap: 8px;
background: linear-gradient(0deg, rgba(245,243,240,0.95), transparent);
}
.magnetic-header { display: flex; justify-content: space-between; align-items: center; }
.magnetic-title { font-size: 14px; font-weight: 700; color: rgba(60,60,60,0.85); }
.magnetic-sub { font-size: 9px; color: rgba(60,60,60,0.4); }
.magnetic-status { padding: 2px 8px; border-radius: 2px; font-size: 7px; font-weight: 700; letter-spacing: 0.1em; color: #ef4444; background: rgba(60,60,60,0.04); border: 1px solid rgba(60,60,60,0.1); }
.magnetic-divider { height: 1px; background: linear-gradient(90deg, transparent, rgba(60,60,60,0.06), transparent); }
.magnetic-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.magnetic-stat { text-align: center; padding: 6px 4px; border-radius: 8px; background: rgba(60,60,60,0.02); border: 1px solid rgba(60,60,60,0.04); }
.magnetic-stat-val { font-size: 10px; font-weight: 600; color: rgba(60,60,60,0.6); }
.magnetic-stat-lbl { font-size: 7px; margin-top: 2px; color: rgba(100,100,100,0.3); }
.magnetic-hint { text-align: center; font-size: 7px; font-family: monospace; color: rgba(60,60,60,0.2); }
@media (prefers-reduced-motion: reduce) {
.magnetic-card { transition: none; }
}Tailwind CSS
<div class="group relative w-[220px] min-h-[300px] rounded-2xl overflow-hidden border border-neutral-400/20 shadow-lg group-hover:shadow-[0_20px_50px_rgba(0,0,0,0.15)] bg-gradient-to-br from-[#f5f3f0] to-[#e8e5e0] cursor-pointer">
<div class="absolute inset-0 z-2 pointer-events-none"></div>
<div class="absolute inset-x-0 bottom-0 z-10 p-5 space-y-2 bg-gradient-to-t from-[#f5f3f0]/95 to-transparent">
<div class="flex items-center justify-between">
<div><p class="text-sm font-bold text-neutral-800/85">Magnetic Field</p><p class="text-[9px] text-neutral-600/50">Ferromagnetic</p></div>
<div class="px-2 py-0.5 rounded-sm text-[7px] font-bold tracking-widest text-red-500 bg-neutral-800/10 border border-neutral-800/20">STABLE</div>
</div>
<div class="h-px bg-gradient-to-r from-transparent via-neutral-800/20 to-transparent"></div>
<div class="grid grid-cols-2 gap-2">
<div class="text-center py-1.5 rounded-lg bg-neutral-800/10 border border-neutral-800/20"><p class="text-[10px] font-semibold text-neutral-800/60">N→S</p><p class="text-[7px] mt-0.5 text-neutral-600/40">Polarity</p></div>
<div class="text-center py-1.5 rounded-lg bg-neutral-800/10 border border-neutral-800/20"><p class="text-[10px] font-semibold text-neutral-800/60">60</p><p class="text-[7px] mt-0.5 text-neutral-600/40">Filings</p></div>
</div>
<div class="text-center"><span class="text-[7px] font-mono text-neutral-800/30">[▼ click to flip]</span></div>
</div>
</div>React
import React, { useState, useRef, useCallback } from 'react';
import { motion, useMotionValue, useSpring, AnimatePresence } from 'framer-motion';
export function MagneticFieldCard() {
const [isHovered, setIsHovered] = useState(false);
const [isFlipped, setIsFlipped] = useState(false);
const [isChaos, setIsChaos] = useState(false);
const [cursorPos, setCursorPos] = useState({ x: 50, y: 50 });
const ref = useRef(null);
const x = useMotionValue(0);
const y = useMotionValue(0);
const rotateX = useSpring(y, { damping: 25, stiffness: 250 });
const rotateY = useSpring(x, { damping: 25, stiffness: 250 });
const filings = Array.from({ length: 60 }, (_, i) => ({ id: i, x: 5 + Math.random() * 90, y: 5 + Math.random() * 90, angle: Math.random() * 360, length: 3 + Math.random() * 6, group: Math.floor(Math.random() * 4) }));
const handleMouseMove = (e) => {
if (!ref.current) return;
const rect = ref.current.getBoundingClientRect();
const cx = rect.left + rect.width / 2;
const cy = rect.top + rect.height / 2;
x.set(-((e.clientX - cx) / (rect.width / 2)) * 8);
y.set(((e.clientY - cy) / (rect.height / 2)) * 8);
setCursorPos({ x: Math.max(5, Math.min(95, ((e.clientX - rect.left) / rect.width) * 100)), y: Math.max(5, Math.min(95, ((e.clientY - rect.top) / rect.height) * 100)) });
};
const handleClick = () => {
setIsChaos(true);
setTimeout(() => { setIsFlipped((p) => !p); setTimeout(() => setIsChaos(false), 400); }, 600);
};
return (
<div onMouseEnter={() => setIsHovered(true)} onMouseLeave={() => { setIsHovered(false); x.set(0); y.set(0); }}>
<motion.div ref={ref} onMouseMove={handleMouseMove} onClick={handleClick} style={{ rotateX, rotateY, transformStyle: 'preserve-3d', cursor: 'pointer' }}>
<motion.div className="relative overflow-hidden rounded-2xl" style={{ width: 220, minHeight: 300, background: 'linear-gradient(160deg, #f5f3f0, #e8e5e0)', border: '1.5px solid rgba(100,100,100,0.15)' }}
animate={{ boxShadow: isHovered ? '0 20px 50px rgba(0,0,0,0.15)' : '0 10px 30px rgba(0,0,0,0.1)' }} transition={{ type: 'spring', stiffness: 280, damping: 20 }}>
<div className="absolute inset-x-0 bottom-0 z-10 p-5 space-y-2" style={{ background: 'linear-gradient(0deg, rgba(245,243,240,0.95), transparent)' }}>
<div className="flex items-center justify-between">
<div><p className="text-sm font-bold" style={{ color: 'rgba(60,60,60,0.85)' }}>Magnetic Field</p><p className="text-[9px]" style={{ color: 'rgba(60,60,60,0.4)' }}>Ferromagnetic</p></div>
<motion.div className="px-2 py-0.5 rounded-sm text-[7px] font-bold tracking-widest" style={{ background: 'rgba(60,60,60,0.04)', border: '1px solid rgba(60,60,60,0.1)', color: isFlipped ? '#3b82f6' : '#ef4444' }}>{isChaos ? '⚡ FLUX' : isFlipped ? 'REVERSED' : 'STABLE'}</motion.div>
</div>
<div className="h-px" style={{ background: 'linear-gradient(90deg, transparent, rgba(60,60,60,0.06), transparent)' }} />
<div className="grid grid-cols-2 gap-2">
<div className="text-center py-1.5 rounded-lg" style={{ background: 'rgba(60,60,60,0.02)', border: '1px solid rgba(60,60,60,0.04)' }}><p className="text-[10px] font-semibold" style={{ color: 'rgba(60,60,60,0.6)' }}>{isFlipped ? 'S→N' : 'N→S'}</p><p className="text-[7px] mt-0.5 text-white/20">Polarity</p></div>
<div className="text-center py-1.5 rounded-lg" style={{ background: 'rgba(60,60,60,0.02)', border: '1px solid rgba(60,60,60,0.04)' }}><p className="text-[10px] font-semibold" style={{ color: 'rgba(60,60,60,0.6)' }}>60</p><p className="text-[7px] mt-0.5 text-white/20">Filings</p></div>
</div>
<motion.div className="text-center" animate={isHovered ? { y: [0, -1, 0] } : {}} transition={{ duration: 1.5, repeat: isHovered ? Infinity : 0, ease: 'easeInOut' }}>
<span className="text-[7px] font-mono" style={{ color: 'rgba(60,60,60,0.2)' }}>{isChaos ? '⚡ FLUXING' : isFlipped ? '[▼ flip again]' : '[▼ click to flip]'}</span>
</motion.div>
</div>
</motion.div>
</motion.div>
</div>
);
}Where Magnetic Field Card fits
- Physics Education
- Interactive Demos
- Data Visualization
- Science Museums
- Creative Tools
Interaction states & animations
- Particle alignment
- Magnetic distortion
- Chaos scatter
- Field lines
- Spring settling
Topics
- #magnetic
- #filings
- #physics
- #field
- #polarity
- #particles
- #iron
- #science
- #interactive
- #shimmer
Accessibility notes
The visual effect relies on fine moving lines which may be triggering for photosensitive users. Provide static fallback. Ensure text content is readable against light background.
Browser support
- Chrome 90+
- Firefox 105+
- Safari 15+
- Edge 90+