For AI agents: the complete documentation index is available at https://a3s-lab.github.io/UI/v0.2.0/en/llms.txt, the full documentation bundle is available at https://a3s-lab.github.io/UI/v0.2.0/en/llms-full.txt, and this page is available as Markdown at https://a3s-lab.github.io/UI/v0.2.0/en/components/toast.md.
  • English
  • v0.2.0
  • Toast

    Live previewHTML · CSS · JavaScript

    Usage

    Include CSS

    Import Tailwind and one full A3S UI style bundle.

    @import "tailwindcss";
    @import "@a3s-lab/ui/a3s.css";

    Or import only the base CSS, Toast component CSS, and one style pack.

    @import "tailwindcss";
    @import "@a3s-lab/ui/base.css";
    @import "@a3s-lab/ui/components/toast.css";
    @import "@a3s-lab/ui/styles/a3s.css";

    Using CDN or bundler imports? See the Installation page.

    Include JavaScript

    Copy or serve the full A3S UI JavaScript bundle.

    <script src="/assets/js/all.min.js" defer></script>

    Or copy or serve the A3S UI runtime and Toast script.

    <script src="/assets/js/runtime.min.js" defer></script>
    <script src="/assets/js/toast.min.js" defer></script>

    Using CDN or bundler imports? See the Installation page.

    Add the toaster HTML

    Add one toaster near the end of your page body:

    <div id="toaster" class="toaster"></div>

    Set data-align="start", data-align="center", or data-align="end" on the toaster to change placement.

    Add your toasts

    Append server-rendered toast markup to the toaster, or create one from JavaScript with toaster.toast(config).

    <div id="toaster" class="toaster">
      <div class="toast" role="status" aria-atomic="true" aria-hidden="false" data-category="success">
        <div class="toast-content"><svg aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10" /><path d="m9 12 2 2 4-4" /></svg>
          <section>
            <h2>Success</h2>
            <p>A success toast called from the front-end.</p>
          </section>
          <footer>
            <button type="button" class="btn" data-toast-action>Dismiss</button>
          </footer>
        </div>
      </div>
    </div>
    <button
      class="btn" data-variant="outline"
      onclick="document.getElementById('toaster').toast({
        category: 'success',
        title: 'Success',
        description: 'A success toast called from the front-end.',
        cancel: {
          label: 'Dismiss'
        }
      })">Toast from front-end</button>

    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

    APITypeDescription
    toaster.toast(config)MethodCreates a toast from a config object and returns the inserted .toast element. See "Config object" below.
    toaster.closeAll()MethodCloses every toast inside the toaster.
    toast.close()MethodCloses one initialized toast element.

    Config object

    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. It is rendered as text, not HTML.
    description Optional
    The description of the toast. It is rendered as text, not HTML.
    action Optional
    Primary action. Supports label, optional href, and an optional onClick(event) callback.
    cancel Optional
    Secondary action. Supports label and an optional onClick(event) callback.