Feedback & overlays
Toast Notification
A button that triggers a temporary slide in notification in the corner, which can be dismissed or auto hides.
<div class="toast-demo">
<button class="toast-trigger">Show Toast</button>
<div class="toast-box" role="status">
<span class="toast-message">Your changes have been saved.</span>
<button class="toast-close" aria-label="Close notification">
<svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="#ffffff" stroke-width="2.5"><line x1="6" y1="6" x2="18" y2="18"></line><line x1="6" y1="18" x2="18" y2="6"></line></svg>
</button>
</div>
</div>
.toast-demo {
box-sizing: border-box;
position: relative;
min-height: 120px;
font-family: system-ui, -apple-system, sans-serif;
}
.toast-trigger {
background-color: #3b82f6;
color: #ffffff;
border: none;
padding: 11px 22px;
border-radius: 8px;
font-size: 14px;
font-weight: 600;
cursor: pointer;
transition: background-color 0.2s ease;
}
.toast-trigger:hover {
background-color: #2f6fe0;
}
.toast-box {
position: fixed;
right: 24px;
bottom: 24px;
display: flex;
align-items: center;
gap: 14px;
background-color: #111827;
color: #ffffff;
padding: 14px 16px;
border-radius: 10px;
box-shadow: 0 10px 24px rgba(17, 24, 39, 0.3);
transform: translateX(140%);
opacity: 0;
transition: transform 0.3s ease, opacity 0.3s ease;
}
.toast-box-show {
transform: translateX(0);
opacity: 1;
}
.toast-message {
font-size: 13px;
font-weight: 500;
}
.toast-close {
background: none;
border: none;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
padding: 2px;
}
var toastTrigger = document.querySelector('.toast-trigger');
var toastBox = document.querySelector('.toast-box');
var toastClose = document.querySelector('.toast-close');
var toastTimer = null;
function toastShow() {
toastBox.classList.add('toast-box-show');
if (toastTimer) { clearTimeout(toastTimer); }
toastTimer = setTimeout(toastHide, 3500);
}
function toastHide() {
toastBox.classList.remove('toast-box-show');
}
toastTrigger.addEventListener('click', toastShow);
toastClose.addEventListener('click', toastHide);