Snackbar
A brief message bar for user feedback with dismiss action and auto-hide animation.
Quick implementation
/* HTML: <div class="snackbar" role="status" aria-live="polite">
<p class="snackbar-message">Your message</p>
<button class="snackbar-action">Dismiss</button>
</div> */
.snackbar {
position: fixed;
bottom: 1.5rem;
left: 50%;
transform: translateX(-50%);
display: flex;
align-items: center;
gap: 1rem;
padding: 0.875rem 1rem;
background: var(--card);
border: 1px solid var(--card-border);
border-radius: 0.5rem;
box-shadow: 0 4px 24px oklch(0 0 0 / 0.12);
font-size: 0.875rem;
color: var(--text);
z-index: 1000;
animation: snackbar-in 0.3s ease-out, snackbar-out 0.3s ease-in 3s;
}
.snackbar::before {
content: "";
position: absolute;
left: 0;
top: 0;
bottom: 0;
width: 4px;
background: var(--accent);
border-radius: 0.5rem 0 0 0.5rem;
}
.snackbar-message {
flex: 1;
margin: 0;
font-weight: 500;
}
.snackbar-action {
background: transparent;
border: none;
color: var(--accent);
font-weight: 600;
font-size: 0.8rem;
cursor: pointer;
padding: 0.25rem 0.5rem;
border-radius: 0.5rem;
transition: background 0.15s ease;
}
.snackbar-action:hover {
background: oklch(0.93 0.01 260 / 0.1);
}
.snackbar-action:focus-visible {
outline: 2px solid var(--accent);
outline-offset: 2px;
}
@keyframes snackbar-in {
from {
opacity: 0;
transform: translateX(-50%) translateY(1rem);
}
to {
opacity: 1;
transform: translateX(-50%) translateY(0);
}
}
@keyframes snackbar-out {
from {
opacity: 1;
transform: translateX(-50%) translateY(0);
}
to {
opacity: 0;
transform: translateX(-50%) translateY(1rem);
pointer-events: none;
}
}
@media (prefers-reduced-motion: reduce) {
.snackbar {
animation: none;
}
}
Prompt this to your LLM
Includes role, constraints, two framework variants, and edge cases to handle.
You are a senior frontend engineer building a notification system.
Goal: A snackbar component that displays brief feedback messages with a dismiss action and optional auto-hide.
Technical constraints:
- Fixed position at bottom-center of viewport, z-index: 1000.
- Entry animation: slide up from bottom with fade-in using transform + opacity.
- Auto-hide after 3-5 seconds with exit animation (reverse of entry).
- Use oklch() for all colors, not hex or rgba().
- Include prefers-reduced-motion: reduce to disable animations.
- Keyboard accessible: dismiss button must be focusable with visible focus ring.
Framework variant (pick one):
A) Vanilla HTML + CSS only — no JavaScript for animations (use CSS animation delay).
B) React component — accept message, actionLabel, duration (ms), and onDismiss props.
Edge cases to handle:
- Multiple snackbars should stack vertically or queue (not overlap).
- Screen readers should announce via role="status" and aria-live="polite".
- Auto-hide should pause when user hovers over the snackbar.
Return HTML + CSS.
Why this matters in 2026
Snackbar components replaced modal dialogs for non-critical feedback — they're less intrusive and don't block interaction. Modern CSS animates the entry and exit without JavaScript, keeping the component lightweight. The dismiss action and auto-hide timing are the only parts requiring JS, making it a progressive enhancement pattern.
The logic
The snackbar uses position: fixed to stay anchored at the bottom of the viewport. Two @keyframes animations handle the lifecycle: snackbar-in for entry (translateY + opacity) and snackbar-out for exit after a 3-second delay. The accent-colored left border (via ::before) provides visual hierarchy. The dismiss button uses focus-visible for keyboard accessibility.
Accessibility & performance
Use role="status" and aria-live="polite" so screen readers announce the message without interrupting. The prefers-reduced-motion query removes animations for users who prefer stability. Performance-wise, the animations only transform and fade — no layout thrashing. Auto-hide timers should be generous (3-5 seconds minimum) and pause on hover to let users read at their own pace.
flex-direction: column and gap in a container, or queue them with JavaScript.