# Prompt Input

> A message box for AI products: a gradient border that turns while focused, example prompts that blur in and out, a box that grows as you type, and a send button that becomes a stop button.

Category: Inputs · Free · Updated 2026-11-10 · Live demo: https://www.motionkitui.com/components/prompt-input

## When to use it

AI assistants and copilots, search and command boxes, support chat, and any product where people describe what they want.

## How it works

The border is a conic gradient behind the box whose angle is a registered CSS custom property, so a keyframe can turn it smoothly while the box is focused, with a blurred copy behind for the glow. The textarea measures its scrollHeight on every change to grow up to a set number of rows. The placeholder is a separate element that swaps example prompts with a short blur-and-slide through AnimatePresence, hidden from screen readers. Sending shows a spinning ring round a stop square until your onSubmit promise settles.

## Installation

```bash
npx shadcn@latest add https://www.motionkitui.com/r/prompt-input.json
```

Or copy `components/motionkit/prompt-input.tsx` below. Requires react, motion and Tailwind CSS v4. Free for personal projects; commercial use needs MotionKit Plus (https://www.motionkitui.com/pricing).

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `placeholders` | `string[]` |  | Example prompts that take turns as the placeholder. |
| `suggestions` | `string[]` |  | Quick starts under the box; clicking one fills it in. |
| `models` | `string[]` | `["Fast", "Balanced", "Deep"]` | Options for the model picker. Empty hides it. |
| `onSubmit` | `(message, model?) => void \| Promise` |  | Called on send. Return a promise to keep the sending state until it settles. |
| `colors` | `[string, string, string]` | `teal, periwinkle, orchid` | Colours of the border's glow. |
| `label` | `string` | `"Message"` | Accessible name for the text box. |
| `maxRows` | `number` | `6` | Rows the box grows to before it scrolls. |

## Accessibility

- **Keyboard: Pass.** A real textarea, select and buttons: Enter sends, Shift+Enter adds a line, and every control has a visible focus ring.
- **Screen readers: Pass.** The text box is labelled, the send button says Send or Sending, and the animated placeholder is hidden so it isn't read on every change.
- **Reduced motion: Pass.** With reduced motion on, the border stops turning and placeholders swap with a plain fade.
- **Colour contrast: Pass.** Typed text measures 16.6:1 on the box and the example prompts 7.6:1; the send button's icon measures 17:1 once there's something to send.

## Source

```tsx
"use client";

import { useEffect, useId, useRef, useState, type FormEvent, type KeyboardEvent } from "react";
import { AnimatePresence, motion, useReducedMotion } from "motion/react";

type PromptInputProps = {
  /** Example prompts that take turns as the placeholder. */
  placeholders?: string[];
  /** Quick starts shown under the box; clicking one fills it in. */
  suggestions?: string[];
  /** Options for the model picker. Leave empty to hide it. */
  models?: string[];
  /** Called with the message and chosen model. Return a promise to show the sending state until it settles. */
  onSubmit?: (message: string, model?: string) => void | Promise<unknown>;
  /** Three colours for the border's glow. */
  colors?: [string, string, string];
  /** Accessible name for the text box. */
  label?: string;
  /** Rows the box grows to before it scrolls. */
  maxRows?: number;
  className?: string;
};

/**
 * A message box for AI products. A gradient border wakes up and turns while it's focused, example prompts blur in
 * and out as the placeholder, the box grows with what you type, and the send button turns into a stop button
 * while the reply is on its way. Enter sends; Shift+Enter adds a line.
 */
export function PromptInput({
  placeholders = ["Design a pricing page with three tiers…", "Animate a hero headline word by word…", "Make a glassy sign-up card…"],
  suggestions = ["Landing page", "Dashboard", "Onboarding flow"],
  models = ["Fast", "Balanced", "Deep"],
  onSubmit,
  colors = ["#5FAEB4", "#B9C7FF", "#D6A7CE"],
  label = "Message",
  maxRows = 6,
  className = "",
}: PromptInputProps) {
  const reduceMotion = useReducedMotion();
  const id = useId();
  const area = useRef<HTMLTextAreaElement>(null);
  const [value, setValue] = useState("");
  const [focused, setFocused] = useState(false);
  const [hint, setHint] = useState(0);
  const [model, setModel] = useState(models[1] ?? models[0]);
  const [sending, setSending] = useState(false);
  const [a, b, c] = colors;
  const empty = value.trim() === "";

  // take turns through the example prompts while the box is empty
  useEffect(() => {
    if (!empty || placeholders.length < 2) return;
    const timer = window.setInterval(() => setHint((current) => (current + 1) % placeholders.length), 3200);
    return () => window.clearInterval(timer);
  }, [empty, placeholders.length]);

  // grow with the text, up to maxRows
  useEffect(() => {
    const el = area.current;
    if (!el) return;
    el.style.height = "auto";
    const line = parseFloat(getComputedStyle(el).lineHeight) || 24;
    el.style.height = `${Math.min(el.scrollHeight, line * maxRows)}px`;
  }, [value, maxRows]);

  async function send(event?: FormEvent) {
    event?.preventDefault();
    if (empty || sending) return;
    const message = value.trim();
    setSending(true);
    try {
      await onSubmit?.(message, models.length ? model : undefined);
      setValue("");
    } finally {
      setSending(false);
      area.current?.focus();
    }
  }

  function onKeyDown(event: KeyboardEvent<HTMLTextAreaElement>) {
    if (event.key === "Enter" && !event.shiftKey && !event.nativeEvent.isComposing) send(event);
  }

  return (
    <div className={`w-full ${className}`}>
      <style>{`@property --prompt-angle{syntax:"<angle>";inherits:false;initial-value:0deg}@keyframes prompt-turn{to{--prompt-angle:360deg}}@media (prefers-reduced-motion:reduce){[data-prompt] [data-turn]{animation:none!important}}`}</style>
      <form data-prompt="" onSubmit={send} className="relative">
        {/* the border: a conic gradient that turns while focused, and a soft glow of the same colours behind */}
        <div
          aria-hidden
          data-turn=""
          className="absolute -inset-px rounded-[1.15rem] transition-opacity duration-500"
          style={{
            background: `conic-gradient(from var(--prompt-angle), ${a}, ${b}, ${c}, ${a})`,
            opacity: focused ? 1 : 0.18,
            animation: focused ? "prompt-turn 4s linear infinite" : undefined,
          }}
        />
        <div
          aria-hidden
          data-turn=""
          className="absolute -inset-2 rounded-[1.6rem] blur-2xl transition-opacity duration-700"
          style={{ background: `conic-gradient(from var(--prompt-angle), ${a}, ${b}, ${c}, ${a})`, opacity: focused ? 0.28 : 0, animation: focused ? "prompt-turn 4s linear infinite" : undefined }}
        />
        <div className="relative rounded-[1.1rem] bg-[#0E1313] p-3 shadow-[inset_0_1px_0_rgb(255_255_255/0.06)]">
          <div className="relative">
            <textarea
              ref={area}
              id={id}
              rows={1}
              value={value}
              aria-label={label}
              onChange={(event) => setValue(event.target.value)}
              onKeyDown={onKeyDown}
              onFocus={() => setFocused(true)}
              onBlur={() => setFocused(false)}
              className="block w-full resize-none bg-transparent px-1.5 py-1 text-[15px] leading-6 text-[#F6F1E8] outline-none placeholder:text-transparent"
            />
            {/* the example prompt, swapped with a soft blur; only shown while the box is empty */}
            <AnimatePresence mode="wait" initial={false}>
              {empty && placeholders.length > 0 && (
                <motion.span
                  key={hint}
                  aria-hidden
                  className="pointer-events-none absolute inset-x-1.5 top-1 truncate text-[15px] leading-6 text-[#94A9A7]"
                  initial={reduceMotion ? { opacity: 0 } : { opacity: 0, y: 6, filter: "blur(6px)" }}
                  animate={{ opacity: 1, y: 0, filter: "blur(0px)" }}
                  exit={reduceMotion ? { opacity: 0 } : { opacity: 0, y: -6, filter: "blur(6px)" }}
                  transition={{ duration: 0.35, ease: [0.16, 1, 0.3, 1] }}
                >
                  {placeholders[hint]}
                </motion.span>
              )}
            </AnimatePresence>
          </div>

          <div className="mt-3 flex items-center justify-between gap-3">
            <div className="flex items-center gap-1.5">
              {models.length > 0 && (
                <label className="relative inline-flex items-center rounded-full border border-white/[0.09] bg-white/[0.03] text-xs text-[#DCE3E2] transition hover:border-white/[0.18] focus-within:outline-2 focus-within:outline-[#B9C7FF]">
                  <span className="sr-only">Model</span>
                  <span aria-hidden className="ml-2.5 size-1.5 rounded-full" style={{ background: `linear-gradient(135deg, ${a}, ${c})` }} />
                  <select value={model} onChange={(event) => setModel(event.target.value)} className="cursor-pointer appearance-none bg-transparent py-1.5 pl-2 pr-6 outline-none">
                    {models.map((option) => (
                      <option key={option} value={option} className="bg-[#141B1B]">
                        {option}
                      </option>
                    ))}
                  </select>
                  <svg aria-hidden viewBox="0 0 12 12" className="pointer-events-none absolute right-2 size-3 text-[#94A9A7]">
                    <path d="M3 4.5l3 3 3-3" fill="none" stroke="currentColor" strokeWidth="1.4" strokeLinecap="round" strokeLinejoin="round" />
                  </svg>
                </label>
              )}
              <span className="hidden text-[11px] text-[#94A9A7] sm:inline">
                <kbd className="font-sans">Shift</kbd> + <kbd className="font-sans">Enter</kbd> for a new line
              </span>
            </div>

            <motion.button
              type="submit"
              aria-label={sending ? "Sending" : "Send"}
              disabled={empty && !sending}
              whileTap={reduceMotion ? undefined : { scale: 0.92 }}
              className="relative grid size-9 shrink-0 place-items-center rounded-full outline-none transition-colors focus-visible:ring-2 focus-visible:ring-[#B9C7FF] disabled:cursor-not-allowed"
              style={{ background: empty && !sending ? "rgb(255 255 255 / 0.07)" : "#F6F1E8", color: empty && !sending ? "#5E7271" : "#0C1010" }}
            >
              <AnimatePresence mode="popLayout" initial={false}>
                {sending ? (
                  <motion.span key="stop" className="grid place-items-center" initial={{ scale: 0.5, opacity: 0 }} animate={{ scale: 1, opacity: 1 }} exit={{ scale: 0.5, opacity: 0 }}>
                    {/* a ring spins round the stop square while the reply is on its way */}
                    <motion.span
                      aria-hidden
                      className="absolute inset-0.5 rounded-full border-2 border-[#0C1010]/15 border-t-[#0C1010]/70"
                      animate={reduceMotion ? undefined : { rotate: 360 }}
                      transition={{ duration: 0.9, repeat: Infinity, ease: "linear" }}
                    />
                    <span className="size-2.5 rounded-[3px] bg-[#0C1010]" />
                  </motion.span>
                ) : (
                  <motion.svg key="send" aria-hidden viewBox="0 0 16 16" className="size-4" initial={{ y: 6, opacity: 0 }} animate={{ y: 0, opacity: 1 }} exit={{ y: -8, opacity: 0 }}>
                    <path d="M8 13V3M3.5 7.5L8 3l4.5 4.5" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round" />
                  </motion.svg>
                )}
              </AnimatePresence>
            </motion.button>
          </div>
        </div>
      </form>

      {suggestions.length > 0 && (
        <ul className="mt-3 flex flex-wrap gap-2" aria-label="Suggestions">
          {suggestions.map((suggestion, index) => (
            <motion.li
              key={suggestion}
              initial={reduceMotion ? false : { opacity: 0, y: 6 }}
              animate={{ opacity: 1, y: 0 }}
              transition={{ delay: 0.15 + index * 0.06, duration: 0.4, ease: [0.16, 1, 0.3, 1] }}
            >
              <button
                type="button"
                onClick={() => {
                  setValue(`${suggestion}: `);
                  area.current?.focus();
                }}
                className="rounded-full border border-white/[0.08] bg-white/[0.025] px-3 py-1.5 text-xs text-[#DCE3E2] transition hover:border-white/[0.2] hover:bg-white/[0.06] hover:text-[#F6F1E8] focus-visible:outline-2 focus-visible:outline-[#B9C7FF]"
              >
                {suggestion}
              </button>
            </motion.li>
          ))}
        </ul>
      )}
    </div>
  );
}
```
