# Toast
## Usage This component ships `toaster()` and `toast()` macros for Jinja and Nunjucks. Import Tailwind and one full Basecoat style bundle. ```css @import "tailwindcss"; @import "basecoat-css/vega.css"; ``` Or import only the base CSS, Toast component CSS, and one style pack. ```css @import "tailwindcss"; @import "basecoat-css/base.css"; @import "basecoat-css/components/toast.css"; @import "basecoat-css/styles/vega.css"; ``` Using CDN or bundler imports? See the [Installation page](/installation). Copy or serve the full Basecoat JavaScript bundle. ```html ``` Or copy or serve the Basecoat runtime and Toast script. ```html ``` Using CDN or bundler imports? See the [Installation page](/installation). Add one toaster near the end of your page body: ```html
``` Set `data-align="start"`, `data-align="center"`, or `data-align="end"` on the toaster to change placement.
Append server-rendered toast markup to the toaster, or create one from JavaScript with `toaster.toast(config)`. ```html

Success

A success toast called from the front-end.

``` ```html ```
### HTML structure
<div id="toaster" class="toaster">
Toast container. Optional data-align values are start, center, and end.
<div class="toast">
Toast item. Use data-category="success|info|warning|error" for category styling and data-duration to override the timeout in milliseconds. Use data-duration="-1" to keep it open.
<div class="toast-content">
Content wrapper.
<svg aria-hidden="true"> Optional
Icon.
<section>
Message region.
<h2>
Title.
<p> Optional
Description.
<footer> Optional
Action buttons or links. Clicking a footer button or link closes the toast.
### JavaScript API | API | Type | Description | | --- | --- | --- | | `toaster.toast(config)` | Method | Creates a toast from a config object and returns the inserted `.toast` element. [See "Config object" below](#config-object). | | `toaster.closeAll()` | Method | Closes every toast inside the toaster. | | `toast.close()` | Method | Closes one initialized toast element. | ### Config object `title`, `description`, and action labels are inserted as plain text. With `html: true` they are inserted as HTML, so never pass untrusted user input with it. `onclick` is JavaScript code and must never contain user input. `icon` is always inserted as raw HTML (it is meant for SVG markup).
duration Optional
Timeout in milliseconds. Defaults to 3000, or 5000 for error toasts. Use -1 to keep it open.
category Optional
Category of the toast, either success, info, warning, or error.
title
The title of the toast.
description Optional
The description of the toast.
action Optional
Primary action. Supports label with either href or onclick.
cancel Optional
Secondary action. Supports label and optional onclick.
icon Optional
Custom icon markup, usually an SVG. Inserted as raw HTML. Defaults to the category icon.
html Optional
Set to true to insert title, description, and action labels as HTML instead of plain text. Defaults to false. Only use it with trusted content.
The Jinja and Nunjucks `toast()` macros render on your server, so your template engine's autoescaping applies to `title`, `description`, and labels there when it is enabled. Nunjucks enables it by default. With Jinja, make sure your environment's `autoescape` setting covers the Basecoat template files (for example `.html.jinja`). `icon` is output with `safe`, and `onclick` is output as an attribute, so neither should contain user input.