sgds-components-toast
SGDS Toast Component Skill
<sgds-toast> is a brief, non-blocking notification. <sgds-toast-container> positions one or more toasts on the screen. Toasts must contain both a title and a message, and optionally an icon and an action link.
Prerequisites
See sgds-components-setup for installation and framework integration (React 19+ vs React ≤18, Vue, Angular).
No CSS styling modifications — custom properties and CSS parts are not exposed on this component.
Quick Decision Guide
Variant?
- Informational →
variant="info"(default) - Confirmation →
variant="success" - Error →
variant="danger" - Caution →
variant="warning" - Theme-neutral →
variant="neutral"
Auto-dismiss? → Add autohide and optionally delay (ms, default 5000)
User can dismiss? → Add dismissible
Position on screen?
- Bottom right →
position="bottom-end"on<sgds-toast-container>(common default) - Use
"top-end","top-center","bottom-center","bottom-start"etc.
Show/hide a toast via JS? → Use showToast() / hideToast() methods
<!-- Basic toast (already shown) -->
<sgds-toast-container position="bottom-end">
<sgds-toast show variant="info" title="Info" dismissible>
<sgds-icon slot="icon" name="info-circle-fill"></sgds-icon>
Your changes have been saved.
<sgds-link slot="action"><a href="#" target="_blank">Undo</a></sgds-link>
</sgds-toast>
</sgds-toast-container>
<!-- Auto-dismissing toast after 3 seconds -->
<sgds-toast-container position="top-end">
<sgds-toast show variant="success" title="Success" autohide delay="3000">
<sgds-icon slot="icon" name="check-circle-fill"></sgds-icon>
Item added to cart.
</sgds-toast>
</sgds-toast-container>
<!-- Trigger toast via JS -->
<sgds-button id="trigger-toast">Show Toast</sgds-button>
<sgds-toast-container position="bottom-end">
<sgds-toast id="my-toast" variant="danger" title="Error" dismissible>
<sgds-icon slot="icon" name="exclamation-circle-fill"></sgds-icon>
Something went wrong. Please try again.
</sgds-toast>
</sgds-toast-container>
<script>
document.getElementById("trigger-toast").addEventListener("click", () => {
document.getElementById("my-toast").showToast();
});
</script>
<!-- Multiple toasts stacked -->
<sgds-toast-container position="bottom-end">
<sgds-toast show variant="success" title="Saved">
<sgds-icon slot="icon" name="check-circle-fill"></sgds-icon>
Document saved.
</sgds-toast>
<sgds-toast show variant="warning" title="Warning">
<sgds-icon slot="icon" name="exclamation-triangle-fill"></sgds-icon>
Storage almost full.
</sgds-toast>
</sgds-toast-container>
API Summary
<sgds-toast>
| Attribute | Type | Default | Purpose |
|---|---|---|---|
show |
boolean | false |
Controls toast visibility |
title |
string | "Title" |
Toast heading (required for accessibility) |
variant |
info | success | danger | warning | neutral |
info |
Visual style and semantic meaning |
dismissible |
boolean | false |
Shows a close button for user dismissal |
autohide |
boolean | false |
Auto-hides the toast after delay ms |
delay |
number | 5000 |
Milliseconds before auto-hide (requires autohide) |
noAnimation |
boolean | false |
Disables show/hide animations |
<sgds-toast-container>
| Attribute | Type | Default | Purpose |
|---|---|---|---|
position |
ToastPosition | — | Screen position for the toast stack |
ToastPosition values (current)
top-center, top-end, bottom-start, bottom-center, bottom-end
top-start,middle-start,middle-center,middle-endare deprecated since 3.7.1 — avoid these positions.
Slots (<sgds-toast>)
| Slot | Purpose |
|---|---|
icon |
Icon displayed on the left (use <sgds-icon>) |
| (default) | Toast message body text |
action |
Action link on the right (use <sgds-link>) |
Events (<sgds-toast>)
| Event | Cancelable | When |
|---|---|---|
sgds-show |
No | Toast begins showing |
sgds-after-show |
No | Toast fully visible (animation complete) |
sgds-hide |
No | Toast begins hiding |
sgds-after-hide |
No | Toast fully hidden (animation complete) |
Public Methods (<sgds-toast>)
| Method | Description |
|---|---|
showToast() |
Shows the toast (sets show = true with animation) |
hideToast() |
Hides the toast (sets show = false with animation) |
For AI agents:
- Always set
titleon<sgds-toast>— it is required for accessibility. showmust be set on the toast for it to be visible on page load;showToast()/hideToast()are the programmatic API.- Always wrap
<sgds-toast>inside<sgds-toast-container>— the container handles positioning. - Multiple
<sgds-toast>elements inside one container stack vertically automatically. - Avoid deprecated position values (
top-start,middle-*); usebottom-endas the default position. - Icon slot accepts
<sgds-icon>, action slot accepts<sgds-link>wrapping an<a>tag.
More from govtechsg/sgds-web-component
sgds-theming
Customising the visual theme of an SGDS application — product brand colours, day/night mode, and font. Use when users ask about changing the primary colour, theming their app, enabling dark mode, night mode, overriding CSS tokens, or customising the font. Apply this skill whenever theming, branding, or CSS token overrides are mentioned.
55sgds-getting-started
Starting point for any new application built with the SGDS web component library. Apply this skill first whenever a user is bootstrapping a new SGDS project, setting up a new app, or asking where to begin with SGDS. Covers font setup, foundation CSS, utilities, components, and app layout in the correct order.
53sgds-utilities
Complete reference for all SGDS utility classes with the sgds: prefix. Use when users ask about setup, background-color, text-color, border-color, border-width, border-radius, typography, spacing, grid, dimension, opacity, color-semantics, or any sgds: Tailwind utility class. Also covers Tailwind v4 imports, theme switching, and framework integration for utilities.
53sgds-writing
Writing style guide for the Singapore Government Design System (SGDS). Use when writing or reviewing UI copy, documentation, labels, error messages, tooltips, or any content that accompanies SGDS components. Covers tone, grammar, spelling, casing, punctuation, and plain language principles.
19token-workflow
Maintains SGDS design token architecture across three layers (primitive tokens in root.css, semantic mappings in day.css/night.css, and Tailwind utilities in utility.css). Use when adding/modifying design tokens, creating new utilities, updating Storybook documentation, or ensuring token consistency across theme files. IMPORTANT - whenever new tokens are requested, ALWAYS complete all three deliverables - (1) utility.css mapping, (2) playground HTML demo in playground/utility/, (3) Storybook story in stories/utilities/. Never do just one without the others.
2sgds-components-radio
Use sgds-radio-group and sgds-radio to display a group of mutually exclusive radio buttons with label, validation, and hint text. Apply this skill whenever a user asks about radio buttons, radio groups, single-choice selectors, mutually exclusive options, or boolean choice fields in SGDS.
1