# Island pill toast

> A small black pill stretches open to show the message and then shrinks back, like the iPhone's Dynamic Island.

- Category: [Toasts](https://library.aimran.es/components/toasts)
- Built with: HTML + CSS
- Live editor: https://library.aimran.es/blocks/uv-toast-island
- Library: AIMRAN Library (https://library.aimran.es), free, no sign-up, by Aimran Oukham

## Where to use it

It fits mobile-first products that want to feel native. In a restaurant booking app, the moment someone confirms a table, the pill grows out of a dot with “Booking confirmed” and closes again a few seconds later. If you were looking for a Dynamic Island style notification in CSS, this is it.

Keep the text to a title and one short line, since the pill only opens so far. It works best at the top of the screen on phones; at the bottom of a desktop page, the nod to the iPhone gets lost.

## Code

### HTML

```html
<div class="uv-zi"><button class="fire">Confirm</button><div class="toast"><i>✓</i><span><b>Booking confirmed</b><small>You’re all set</small></span></div></div>
```

### CSS

```css
.uv-zi {
  --c1: #0071e3;
  --c2: #8ec5ff;
  --s: 16px;
  /* tamaño */
  --k: 1;
  /* velocidad */
  --fg: #1d1d1f;
  /* texto */
  --bg: #f5f5f7;
  /* fondo */
}

.uv-zi {
  font-family: -apple-system,BlinkMacSystemFont,"SF Pro Text","Inter",system-ui,sans-serif;
  position: relative;
  width: 20em;
  height: 14em;
  font-size: var(--s);
}

.uv-zi>.fire {
  position: absolute;
  left: 50%;
  top: 50%;
  translate: -50% -50%;
  padding: .8em 1.25em;
  border: 0;
  border-radius: 999px;
  font: inherit;
  font-weight: 600;
  color: #fff;
  background: var(--c1);
  cursor: pointer;
  transition: transform calc(0.25s / var(--k)) cubic-bezier(.34,1.56,.64,1);
}

.uv-zi .toast {
  position: absolute;
  z-index: 2;
  left: 50%;
  bottom: .5em;
  display: flex;
  align-items: center;
  gap: .75em;
  width: 18em;
  padding: .85em;
  border-radius: 1em;
  color: var(--fg);
  background: var(--bg);
  box-shadow: inset 0 0 0 1px color-mix(in srgb,var(--fg) 10%,transparent),0 18px 45px rgba(0,0,0,.18);
  opacity: 0;
  pointer-events: none;
  left: 50%;
  bottom: 1em;
  width: 3em;
  height: 3em;
  padding: .45em;
  border-radius: 999px;
  color: #fff;
  background: #09090b;
  transform: translateX(-50%);
  overflow: hidden;
}

.uv-zi .toast i {
  display: grid;
  place-items: center;
  min-width: 2.1em;
  height: 2.1em;
  border-radius: 50%;
  font-style: normal;
  background: #30a46c;
}

.uv-zi .toast span {
  display: grid;
  min-width: 12em;
  opacity: 0;
}

.uv-zi .toast small {
  opacity: .55;
}

.uv-zi .toast.show {
  animation: uv-zi calc(4s / var(--k)) cubic-bezier(.34,1.56,.64,1);
}

@keyframes uv-zi {
  0% {
    opacity: 1;
    width: 3em;
  }
  12%,82% {
    opacity: 1;
    width: 18em;
    pointer-events: auto;
  }
  90% {
    opacity: 1;
    width: 3em;
  }
  100% {
    opacity: 0;
    width: 3em;
  }
}

.uv-zi .toast.show span {
  animation: uv-zi-t calc(4s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

@keyframes uv-zi-t {
  0%,8%,90%,100% {
    opacity: 0;
    transform: translateX(-.5em);
  }
  15%,82% {
    opacity: 1;
    transform: none;
  }
}
```

### JavaScript

```js
document.querySelectorAll(".uv-zi").forEach(el => {
  const b=el.querySelector(".fire"),t=el.querySelector(".toast");b.addEventListener("click",()=>{t.classList.remove("show");void t.offsetWidth;t.classList.add("show")});
});
```

### React

```tsx
// @ts-nocheck: setup() es JavaScript del DOM sin tipos, el mismo de la pestaña JS.
import { useEffect, useRef, type CSSProperties } from "react";

const css = `
.uv-zi {
  font-family: -apple-system,BlinkMacSystemFont,"SF Pro Text","Inter",system-ui,sans-serif;
  position: relative;
  width: 20em;
  height: 14em;
  font-size: var(--s);
}

.uv-zi>.fire {
  position: absolute;
  left: 50%;
  top: 50%;
  translate: -50% -50%;
  padding: .8em 1.25em;
  border: 0;
  border-radius: 999px;
  font: inherit;
  font-weight: 600;
  color: #fff;
  background: var(--c1);
  cursor: pointer;
  transition: transform calc(0.25s / var(--k)) cubic-bezier(.34,1.56,.64,1);
}

.uv-zi .toast {
  position: absolute;
  z-index: 2;
  left: 50%;
  bottom: .5em;
  display: flex;
  align-items: center;
  gap: .75em;
  width: 18em;
  padding: .85em;
  border-radius: 1em;
  color: var(--fg);
  background: var(--bg);
  box-shadow: inset 0 0 0 1px color-mix(in srgb,var(--fg) 10%,transparent),0 18px 45px rgba(0,0,0,.18);
  opacity: 0;
  pointer-events: none;
  left: 50%;
  bottom: 1em;
  width: 3em;
  height: 3em;
  padding: .45em;
  border-radius: 999px;
  color: #fff;
  background: #09090b;
  transform: translateX(-50%);
  overflow: hidden;
}

.uv-zi .toast i {
  display: grid;
  place-items: center;
  min-width: 2.1em;
  height: 2.1em;
  border-radius: 50%;
  font-style: normal;
  background: #30a46c;
}

.uv-zi .toast span {
  display: grid;
  min-width: 12em;
  opacity: 0;
}

.uv-zi .toast small {
  opacity: .55;
}

.uv-zi .toast.show {
  animation: uv-zi calc(4s / var(--k)) cubic-bezier(.34,1.56,.64,1);
}

@keyframes uv-zi {
  0% {
    opacity: 1;
    width: 3em;
  }
  12%,82% {
    opacity: 1;
    width: 18em;
    pointer-events: auto;
  }
  90% {
    opacity: 1;
    width: 3em;
  }
  100% {
    opacity: 0;
    width: 3em;
  }
}

.uv-zi .toast.show span {
  animation: uv-zi-t calc(4s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

@keyframes uv-zi-t {
  0%,8%,90%,100% {
    opacity: 0;
    transform: translateX(-.5em);
  }
  15%,82% {
    opacity: 1;
    transform: none;
  }
}
`;

// Interacción en JavaScript del DOM: la misma que en la pestaña JS.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function setup(el: any) {
  const b=el.querySelector(".fire"),t=el.querySelector(".toast");b.addEventListener("click",()=>{t.classList.remove("show");void t.offsetWidth;t.classList.add("show")});
}

export default function ToastIsland() {
  const ref = useRef<HTMLDivElement>(null);

  useEffect(() => {
    const el = ref.current?.firstElementChild;
    return el ? setup(el) : undefined;
  }, []);

  return (
    <>
      <style>{css}</style>
      <div
        ref={ref} style={{
          "--c1": "#0071e3",
          "--c2": "#8ec5ff",
          "--s": "16px",
          "--k": "1",
          "--fg": "#1d1d1f",
          "--bg": "#f5f5f7",
        } as CSSProperties}
      >
        <div className="uv-zi"><button className="fire">Confirm</button><div className="toast"><i>✓</i><span><b>Booking confirmed</b><small>You’re all set</small></span></div></div>
      </div>
    </>
  );
}
```

## Prompt for AI assistants

Paste this into ChatGPT, Claude, Cursor, v0 or Lovable to adapt the block to your stack (Tailwind, Vue, Svelte…):

````text
I want to add the “Island pill toast” block (Toasts) from AIMRAN Library to my project.

## What it is
A small black pill stretches open to show the message and then shrinks back, like the iPhone's Dynamic Island.

## Chosen settings
- Main color: #0071e3
- Secondary color: #8ec5ff
- Size: 16px (from 12 to 24px)
- Speed: 1x (from 0.5 to 2x)
- Text: "Booking confirmed"

## What I need
1. Add it to my project with the same look and animation as the reference code: same sizes, colours, radii, shadows, timings and easing.
2. It is built with plain HTML and CSS (the reference wraps it in a React component with its CSS). If my project uses something else (Vue, Svelte, Astro, plain HTML…), translate it without losing any behaviour. If I use Tailwind, turn the styles into classes; if not, keep the CSS in its own file.
3. Expose the settings above as props (or CSS variables) with those values as defaults.
4. Make it work well on phones: nothing that depends only on hover, touch targets of at least 44 px and no overflow on 320 px screens.
5. Make it look right in light and dark mode.
6. Keep it accessible: semantic HTML, roles and aria-* where needed, visible focus and keyboard support.
7. Respect prefers-reduced-motion: with reduced motion, no big animations but the same end result.

## Reference code
```tsx
// @ts-nocheck: setup() es JavaScript del DOM sin tipos, el mismo de la pestaña JS.
import { useEffect, useRef, type CSSProperties } from "react";

const css = `
.uv-zi {
  font-family: -apple-system,BlinkMacSystemFont,"SF Pro Text","Inter",system-ui,sans-serif;
  position: relative;
  width: 20em;
  height: 14em;
  font-size: var(--s);
}

.uv-zi>.fire {
  position: absolute;
  left: 50%;
  top: 50%;
  translate: -50% -50%;
  padding: .8em 1.25em;
  border: 0;
  border-radius: 999px;
  font: inherit;
  font-weight: 600;
  color: #fff;
  background: var(--c1);
  cursor: pointer;
  transition: transform calc(0.25s / var(--k)) cubic-bezier(.34,1.56,.64,1);
}

.uv-zi .toast {
  position: absolute;
  z-index: 2;
  left: 50%;
  bottom: .5em;
  display: flex;
  align-items: center;
  gap: .75em;
  width: 18em;
  padding: .85em;
  border-radius: 1em;
  color: var(--fg);
  background: var(--bg);
  box-shadow: inset 0 0 0 1px color-mix(in srgb,var(--fg) 10%,transparent),0 18px 45px rgba(0,0,0,.18);
  opacity: 0;
  pointer-events: none;
  left: 50%;
  bottom: 1em;
  width: 3em;
  height: 3em;
  padding: .45em;
  border-radius: 999px;
  color: #fff;
  background: #09090b;
  transform: translateX(-50%);
  overflow: hidden;
}

.uv-zi .toast i {
  display: grid;
  place-items: center;
  min-width: 2.1em;
  height: 2.1em;
  border-radius: 50%;
  font-style: normal;
  background: #30a46c;
}

.uv-zi .toast span {
  display: grid;
  min-width: 12em;
  opacity: 0;
}

.uv-zi .toast small {
  opacity: .55;
}

.uv-zi .toast.show {
  animation: uv-zi calc(4s / var(--k)) cubic-bezier(.34,1.56,.64,1);
}

@keyframes uv-zi {
  0% {
    opacity: 1;
    width: 3em;
  }
  12%,82% {
    opacity: 1;
    width: 18em;
    pointer-events: auto;
  }
  90% {
    opacity: 1;
    width: 3em;
  }
  100% {
    opacity: 0;
    width: 3em;
  }
}

.uv-zi .toast.show span {
  animation: uv-zi-t calc(4s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

@keyframes uv-zi-t {
  0%,8%,90%,100% {
    opacity: 0;
    transform: translateX(-.5em);
  }
  15%,82% {
    opacity: 1;
    transform: none;
  }
}
`;

// Interacción en JavaScript del DOM: la misma que en la pestaña JS.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function setup(el: any) {
  const b=el.querySelector(".fire"),t=el.querySelector(".toast");b.addEventListener("click",()=>{t.classList.remove("show");void t.offsetWidth;t.classList.add("show")});
}

export default function ToastIsland() {
  const ref = useRef<HTMLDivElement>(null);

  useEffect(() => {
    const el = ref.current?.firstElementChild;
    return el ? setup(el) : undefined;
  }, []);

  return (
    <>
      <style>{css}</style>
      <div
        ref={ref} style={{
          "--c1": "#0071e3",
          "--c2": "#8ec5ff",
          "--s": "16px",
          "--k": "1",
          "--fg": "#1d1d1f",
          "--bg": "#f5f5f7",
        } as CSSProperties}
      >
        <div className="uv-zi"><button className="fire">Confirm</button><div className="toast"><i>✓</i><span><b>Booking confirmed</b><small>You’re all set</small></span></div></div>
      </div>
    </>
  );
}
```

Give me the complete final code, ready to paste, and tell me in one line where to put it in my project.
````
