Make a four-pointed star (two crossed rectangles clipped at 45°, or a tiny inline SVG), place it at a random coordinate, and animate scale and opacity from 0 to 1 back to 0 — that's one twinkle. Spawn a new one on an interval and remove it from the DOM once its animation ends, so nothing accumulates.
Randomness is the whole point — size, position, and blink speed should differ every time, or the effect reads as mechanical instead of the "something magical just happened" feeling it's usually going for. If every sparkle pulses on the same rhythm, it becomes background noise that pulls attention away from the text it's meant to highlight.
Meteors trace a path across the screen; sparkles pop in place and vanish — that's the distinction.
When to use
Use for AI-generated output, a "new" badge, or a completion/celebration state. Keep it brief — running constantly around body content is just distracting.