Flash
A CSS keyframe flash animation — rapid opacity blinks for alerts, notifications, and attention-grabbing UI moments.
Quick implementation
.flash-element {
animation: flash-anim 1s infinite;
}
@keyframes flash-anim {
0%, 100% { opacity: 1; }
50% { opacity: 0.3; }
}
@media (prefers-reduced-motion: reduce) {
.flash-element {
animation: none;
opacity: 1;
}
}Prompt this to your LLM
Includes role, constraints, two framework variants, and edge cases to handle.
Act as a senior CSS developer. Create a "Flash" animation effect that rapidly blinks an element's opacity to grab attention (e.g., for alerts).
Requirements:
1. Use @keyframes to alternate opacity between 1 and 0.3 rapidly (e.g., 0%, 50%, 100%).
2. Apply the animation to a class named .flash-element.
3. Include a @media (prefers-reduced-motion: reduce) query to disable the animation for users who prefer reduced motion.
4. Provide two variants:
- Vanilla CSS.
- Tailwind CSS utility classes (using arbitrary values if necessary).
5. Ensure the code is production-ready and accessible.
Output only the code blocks with brief explanations.Why this matters in 2026
The flash animation is a critical tool for drawing immediate attention to critical UI updates, such as form validation errors or system notifications, without relying on intrusive modals. In modern interfaces where users scan content quickly, a subtle flash ensures that important information is noticed instantly while maintaining a clean aesthetic.
The logic
This effect relies on @keyframes to interpolate the opacity property between full visibility and a semi-transparent state. By setting the animation to infinite, the element creates a rhythmic blinking pattern. The 50% keyframe acts as the "off" state, creating the flash effect when combined with the default 0% and 100% "on" states.
Accessibility & performance
Flash animations can trigger photosensitivity issues, so it is mandatory to respect the prefers-reduced-motion media query to disable the effect for sensitive users. From a performance standpoint, animating opacity is highly efficient as it is handled by the compositor thread, ensuring smooth 60fps playback even on lower-end devices.