> ## Documentation Index
> Fetch the complete documentation index at: https://prefab.prefect.io/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Badge

> Compact status indicators and labels with semantic color variants.

export const ComponentPreview = ({json, height, resizable, bare, hideJson, playground, children}) => {
  const hostRef = React.useRef(null);
  const handleRef = React.useRef(null);
  const cardRef = React.useRef(null);
  const containerRef = React.useRef(null);
  const [previewWidth, setPreviewWidth] = React.useState(null);
  const [isDragging, setIsDragging] = React.useState(false);
  const [playgroundHref, setPlaygroundHref] = React.useState(null);
  React.useEffect(function () {
    if (!playground) return;
    var isLocal = location.hostname === "localhost" || location.hostname === "127.0.0.1";
    var path = isLocal ? "/playground" : "/docs/playground";
    var url = new URL(path, window.location.href);
    url.hash = "code=" + playground;
    setPlaygroundHref(url.href);
  }, [playground]);
  var jsonStr = typeof json === "string" ? json : JSON.stringify(json, null, 2);
  React.useEffect(function () {
    if (cardRef.current) {
      var card = cardRef.current.closest(".group");
      if (card) card.classList.remove("group");
    }
    var host = hostRef.current;
    if (!host || !json) return;
    function mount() {
      if (!window.__prefab || !host) return;
      var dark = document.documentElement.classList.contains("dark");
      handleRef.current = window.__prefab.mountPreview(host, jsonStr, {
        dark: dark
      });
      if (bare && host.shadowRoot) {
        var m = host.shadowRoot.querySelector("[data-prefab-mount]");
        if (m) m.style.background = "transparent";
      }
    }
    if (window.__prefab) {
      mount();
    } else {
      if (!window.__prefabLoading) {
        if (!window.__prefabReady) {
          var s = document.createElement("script");
          s.src = "/renderer.js";
          document.head.appendChild(s);
        }
        window.__prefabLoading = new Promise(function (resolve) {
          function check() {
            if (window.__prefabReady) {
              window.__prefabReady.then(resolve);
            } else {
              setTimeout(check, 10);
            }
          }
          check();
        });
      }
      window.__prefabLoading.then(mount);
    }
    var observer = new MutationObserver(function () {
      var dark = document.documentElement.classList.contains("dark");
      if (handleRef.current) handleRef.current.setDark(dark);
    });
    observer.observe(document.documentElement, {
      attributes: true,
      attributeFilter: ["class"]
    });
    return function () {
      observer.disconnect();
      if (handleRef.current) {
        handleRef.current.unmount();
        handleRef.current = null;
      }
    };
  }, [json]);
  function startResize(e) {
    e.preventDefault();
    var startX = e.clientX;
    var startW = hostRef.current ? hostRef.current.offsetWidth : 0;
    var maxW = containerRef.current ? containerRef.current.offsetWidth - 10 : startW;
    setIsDragging(true);
    function onMove(ev) {
      var w = Math.max(260, Math.min(startW + (ev.clientX - startX), maxW));
      setPreviewWidth(w);
    }
    function onUp() {
      document.removeEventListener("mousemove", onMove);
      document.removeEventListener("mouseup", onUp);
      setIsDragging(false);
    }
    document.addEventListener("mousemove", onMove);
    document.addEventListener("mouseup", onUp);
  }
  if (bare) {
    return <div ref={hostRef} />;
  }
  if (resizable) {
    return <Card>
        <div ref={cardRef} />
        <div ref={containerRef} style={{
      display: "flex",
      position: "relative",
      overflow: "hidden"
    }}>
          <div ref={hostRef} style={{
      flex: previewWidth ? "none" : 1,
      width: previewWidth ? previewWidth + "px" : undefined,
      minWidth: 0
    }} />
          <div onMouseDown={startResize} style={{
      width: "14px",
      flexShrink: 0,
      cursor: "col-resize",
      background: isDragging ? "var(--border, #e5e7eb)" : "color-mix(in srgb, var(--border, #e5e7eb) 40%, transparent)",
      display: "flex",
      alignItems: "center",
      justifyContent: "center",
      transition: "background 0.15s",
      userSelect: "none"
    }}>
            <svg width="6" height="24" style={{
      opacity: 0.5
    }}>
              <circle cx="2" cy="4" r="1.2" fill="currentColor" />
              <circle cx="2" cy="9" r="1.2" fill="currentColor" />
              <circle cx="2" cy="14" r="1.2" fill="currentColor" />
              <circle cx="2" cy="19" r="1.2" fill="currentColor" />
              <circle cx="5" cy="4" r="1.2" fill="currentColor" />
              <circle cx="5" cy="9" r="1.2" fill="currentColor" />
              <circle cx="5" cy="14" r="1.2" fill="currentColor" />
              <circle cx="5" cy="19" r="1.2" fill="currentColor" />
            </svg>
          </div>
          <div style={{
      flex: previewWidth ? 1 : "0 0 24px",
      minWidth: "24px",
      background: "repeating-linear-gradient(-45deg, transparent, transparent 3px, var(--border, #e5e7eb) 3px, var(--border, #e5e7eb) 4px)",
      opacity: 0.4
    }} />
          {previewWidth && <div style={{
      position: "absolute",
      bottom: "8px",
      right: "8px",
      background: "var(--background, white)",
      border: "1px solid var(--border, #e5e7eb)",
      borderRadius: "4px",
      padding: "1px 6px",
      fontSize: "11px",
      fontFamily: "monospace",
      color: "var(--muted-foreground, #6b7280)",
      pointerEvents: "none"
    }}>
              {previewWidth}px
            </div>}
        </div>
        {playgroundHref && <div style={{
      display: "flex",
      justifyContent: "flex-end",
      padding: "4px 0 8px"
    }}>
            <a href={playgroundHref} target="_blank" rel="noopener noreferrer" style={{
      fontSize: "11px",
      opacity: 0.4,
      textDecoration: "none",
      textDecorationLine: "none",
      borderBottom: "none",
      boxShadow: "none",
      display: "inline-flex",
      alignItems: "center",
      gap: "3px",
      transition: "opacity 0.15s",
      fontWeight: 400
    }} onMouseOver={function (e) {
      e.currentTarget.style.opacity = "0.6";
    }} onMouseOut={function (e) {
      e.currentTarget.style.opacity = "0.4";
    }}>
              Edit in Playground
              <svg xmlns="http://www.w3.org/2000/svg" width="11" height="11" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="M15 3h6v6" /><path d="M10 14 21 3" /><path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6" /></svg>
            </a>
          </div>}
        <div style={{
      marginBottom: "-2rem"
    }}>{children}</div>
      </Card>;
  }
  return <Card>
      <div ref={cardRef} />
      <div ref={hostRef} />
      {playgroundHref && <div style={{
    display: "flex",
    justifyContent: "flex-end",
    padding: "4px 0 8px"
  }}>
          <a href={playgroundHref} target="_blank" rel="noopener noreferrer" style={{
    fontSize: "11px",
    opacity: 0.4,
    textDecoration: "none",
    textDecorationLine: "none",
    borderBottom: "none",
    boxShadow: "none",
    display: "inline-flex",
    alignItems: "center",
    gap: "3px",
    transition: "opacity 0.15s",
    fontWeight: 400
  }} onMouseOver={function (e) {
    e.currentTarget.style.opacity = "0.6";
  }} onMouseOut={function (e) {
    e.currentTarget.style.opacity = "0.4";
  }}>
            Edit in Playground
            <svg xmlns="http://www.w3.org/2000/svg" width="11" height="11" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="M15 3h6v6" /><path d="M10 14 21 3" /><path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6" /></svg>
          </a>
        </div>}
      <div style={{
    marginBottom: "-2rem"
  }}>{children}</div>
    </Card>;
};

Badges are small, pill-shaped labels for status indicators, counts, and categories. They're inline elements that sit naturally alongside text or within cards.

## Basic Usage

<ComponentPreview json={{"view":{"type":"Badge","label":"Mostly Harmless","variant":"default"}}} playground="ZnJvbSBwcmVmYWJfdWkuY29tcG9uZW50cyBpbXBvcnQgQmFkZ2UKCkJhZGdlKCJNb3N0bHkgSGFybWxlc3MiKQo">
  <CodeGroup>
    ```python Python icon="python" theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
    from prefab_ui.components import Badge

    Badge("Mostly Harmless")
    ```

    ```json Protocol icon="brackets-curly" theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
    {"view": {"type": "Badge", "label": "Mostly Harmless", "variant": "default"}}
    ```
  </CodeGroup>
</ComponentPreview>

## Variants

Eight variants cover the most common use cases — five base styles from shadcn plus three semantic colors for status indicators.

<ComponentPreview json={{"view":{"cssClass":"gap-8 grid-cols-4 place-items-center","type":"Grid","children":[{"type":"Badge","label":"Default","variant":"default"},{"type":"Badge","label":"Secondary","variant":"secondary"},{"type":"Badge","label":"Destructive","variant":"destructive"},{"type":"Badge","label":"Outline","variant":"outline"},{"type":"Badge","label":"Ghost","variant":"ghost"},{"type":"Badge","label":"Success","variant":"success"},{"type":"Badge","label":"Warning","variant":"warning"},{"type":"Badge","label":"Info","variant":"info"}]}}} playground="ZnJvbSBwcmVmYWJfdWkuY29tcG9uZW50cyBpbXBvcnQgQmFkZ2UsIEdyaWQKCndpdGggR3JpZChnYXA9OCwgY29sdW1ucz00LCBjc3NfY2xhc3M9InBsYWNlLWl0ZW1zLWNlbnRlciIpOgogICAgQmFkZ2UoIkRlZmF1bHQiKQogICAgQmFkZ2UoIlNlY29uZGFyeSIsIHZhcmlhbnQ9InNlY29uZGFyeSIpCiAgICBCYWRnZSgiRGVzdHJ1Y3RpdmUiLCB2YXJpYW50PSJkZXN0cnVjdGl2ZSIpCiAgICBCYWRnZSgiT3V0bGluZSIsIHZhcmlhbnQ9Im91dGxpbmUiKQogICAgQmFkZ2UoIkdob3N0IiwgdmFyaWFudD0iZ2hvc3QiKQogICAgQmFkZ2UoIlN1Y2Nlc3MiLCB2YXJpYW50PSJzdWNjZXNzIikKICAgIEJhZGdlKCJXYXJuaW5nIiwgdmFyaWFudD0id2FybmluZyIpCiAgICBCYWRnZSgiSW5mbyIsIHZhcmlhbnQ9ImluZm8iKQo">
  <CodeGroup>
    ```python Python icon="python" theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
    from prefab_ui.components import Badge, Grid

    with Grid(gap=8, columns=4, css_class="place-items-center"):
        Badge("Default")
        Badge("Secondary", variant="secondary")
        Badge("Destructive", variant="destructive")
        Badge("Outline", variant="outline")
        Badge("Ghost", variant="ghost")
        Badge("Success", variant="success")
        Badge("Warning", variant="warning")
        Badge("Info", variant="info")
    ```

    ```json Protocol icon="brackets-curly" theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
    {
      "view": {
        "cssClass": "gap-8 grid-cols-4 place-items-center",
        "type": "Grid",
        "children": [
          {"type": "Badge", "label": "Default", "variant": "default"},
          {"type": "Badge", "label": "Secondary", "variant": "secondary"},
          {"type": "Badge", "label": "Destructive", "variant": "destructive"},
          {"type": "Badge", "label": "Outline", "variant": "outline"},
          {"type": "Badge", "label": "Ghost", "variant": "ghost"},
          {"type": "Badge", "label": "Success", "variant": "success"},
          {"type": "Badge", "label": "Warning", "variant": "warning"},
          {"type": "Badge", "label": "Info", "variant": "info"}
        ]
      }
    }
    ```
  </CodeGroup>
</ComponentPreview>

## Examples

Badges pair well with cards and other layout components as inline status indicators.

<ComponentPreview json={{"view":{"cssClass":"gap-3","type":"Column","children":[{"type":"Card","children":[{"type":"CardHeader","children":[{"cssClass":"gap-2 items-center","type":"Row","children":[{"type":"CardTitle","content":"Heart of Gold"},{"type":"Badge","label":"Online","variant":"success"}]},{"type":"CardDescription","content":"Infinite Improbability Drive engaged"}]}]},{"type":"Card","children":[{"type":"CardHeader","children":[{"cssClass":"gap-2 items-center","type":"Row","children":[{"type":"CardTitle","content":"Vogon Fleet"},{"type":"Badge","label":"Approaching","variant":"warning"}]},{"type":"CardDescription","content":"Demolition order filed with local planning authority"}]}]}]}}} playground="ZnJvbSBwcmVmYWJfdWkuY29tcG9uZW50cyBpbXBvcnQgKAogICAgQmFkZ2UsCiAgICBDYXJkLAogICAgQ2FyZERlc2NyaXB0aW9uLAogICAgQ2FyZEhlYWRlciwKICAgIENhcmRUaXRsZSwKICAgIENvbHVtbiwKICAgIFJvdywKKQoKd2l0aCBDb2x1bW4oZ2FwPTMpOgogICAgd2l0aCBDYXJkKCk6CiAgICAgICAgd2l0aCBDYXJkSGVhZGVyKCk6CiAgICAgICAgICAgIHdpdGggUm93KGdhcD0yLCBjc3NfY2xhc3M9Iml0ZW1zLWNlbnRlciIpOgogICAgICAgICAgICAgICAgQ2FyZFRpdGxlKCJIZWFydCBvZiBHb2xkIikKICAgICAgICAgICAgICAgIEJhZGdlKCJPbmxpbmUiLCB2YXJpYW50PSJzdWNjZXNzIikKICAgICAgICAgICAgQ2FyZERlc2NyaXB0aW9uKCJJbmZpbml0ZSBJbXByb2JhYmlsaXR5IERyaXZlIGVuZ2FnZWQiKQogICAgd2l0aCBDYXJkKCk6CiAgICAgICAgd2l0aCBDYXJkSGVhZGVyKCk6CiAgICAgICAgICAgIHdpdGggUm93KGdhcD0yLCBjc3NfY2xhc3M9Iml0ZW1zLWNlbnRlciIpOgogICAgICAgICAgICAgICAgQ2FyZFRpdGxlKCJWb2dvbiBGbGVldCIpCiAgICAgICAgICAgICAgICBCYWRnZSgiQXBwcm9hY2hpbmciLCB2YXJpYW50PSJ3YXJuaW5nIikKICAgICAgICAgICAgQ2FyZERlc2NyaXB0aW9uKCJEZW1vbGl0aW9uIG9yZGVyIGZpbGVkIHdpdGggbG9jYWwgcGxhbm5pbmcgYXV0aG9yaXR5IikK">
  <CodeGroup>
    ```python Python icon="python" theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
    from prefab_ui.components import (
        Badge,
        Card,
        CardDescription,
        CardHeader,
        CardTitle,
        Column,
        Row,
    )

    with Column(gap=3):
        with Card():
            with CardHeader():
                with Row(gap=2, css_class="items-center"):
                    CardTitle("Heart of Gold")
                    Badge("Online", variant="success")
                CardDescription("Infinite Improbability Drive engaged")
        with Card():
            with CardHeader():
                with Row(gap=2, css_class="items-center"):
                    CardTitle("Vogon Fleet")
                    Badge("Approaching", variant="warning")
                CardDescription("Demolition order filed with local planning authority")
    ```

    ```json Protocol icon="brackets-curly" theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
    {
      "view": {
        "cssClass": "gap-3",
        "type": "Column",
        "children": [
          {
            "type": "Card",
            "children": [
              {
                "type": "CardHeader",
                "children": [
                  {
                    "cssClass": "gap-2 items-center",
                    "type": "Row",
                    "children": [
                      {"type": "CardTitle", "content": "Heart of Gold"},
                      {"type": "Badge", "label": "Online", "variant": "success"}
                    ]
                  },
                  {"type": "CardDescription", "content": "Infinite Improbability Drive engaged"}
                ]
              }
            ]
          },
          {
            "type": "Card",
            "children": [
              {
                "type": "CardHeader",
                "children": [
                  {
                    "cssClass": "gap-2 items-center",
                    "type": "Row",
                    "children": [
                      {"type": "CardTitle", "content": "Vogon Fleet"},
                      {"type": "Badge", "label": "Approaching", "variant": "warning"}
                    ]
                  },
                  {
                    "type": "CardDescription",
                    "content": "Demolition order filed with local planning authority"
                  }
                ]
              }
            ]
          }
        ]
      }
    }
    ```
  </CodeGroup>
</ComponentPreview>

Badge is a container component, so you can compose children for richer content — icons, loaders, or custom ordering.

<ComponentPreview json={{"view":{"cssClass":"gap-4 items-center","type":"Row","children":[{"type":"Badge","variant":"success","children":[{"type":"Icon","name":"check","size":"sm"},{"content":"Verified","type":"Text"}]},{"type":"Badge","variant":"default","children":[{"type":"Loader","variant":"spin","size":"sm"},{"content":"Syncing","type":"Text"}]},{"type":"Badge","variant":"secondary","children":[{"type":"Loader","variant":"dots","size":"sm"},{"content":"Processing","type":"Text"}]}]}}} playground="ZnJvbSBwcmVmYWJfdWkuY29tcG9uZW50cyBpbXBvcnQgQmFkZ2UsIEljb24sIExvYWRlciwgUm93LCBUZXh0Cgp3aXRoIFJvdyhnYXA9NCwgY3NzX2NsYXNzPSJpdGVtcy1jZW50ZXIiKToKICAgIHdpdGggQmFkZ2UodmFyaWFudD0ic3VjY2VzcyIpOgogICAgICAgIEljb24oImNoZWNrIiwgc2l6ZT0ic20iKQogICAgICAgIFRleHQoIlZlcmlmaWVkIikKICAgIHdpdGggQmFkZ2UoKToKICAgICAgICBMb2FkZXIoc2l6ZT0ic20iKQogICAgICAgIFRleHQoIlN5bmNpbmciKQogICAgd2l0aCBCYWRnZSh2YXJpYW50PSJzZWNvbmRhcnkiKToKICAgICAgICBMb2FkZXIodmFyaWFudD0iZG90cyIsIHNpemU9InNtIikKICAgICAgICBUZXh0KCJQcm9jZXNzaW5nIikK">
  <CodeGroup>
    ```python Python icon="python" theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
    from prefab_ui.components import Badge, Icon, Loader, Row, Text

    with Row(gap=4, css_class="items-center"):
        with Badge(variant="success"):
            Icon("check", size="sm")
            Text("Verified")
        with Badge():
            Loader(size="sm")
            Text("Syncing")
        with Badge(variant="secondary"):
            Loader(variant="dots", size="sm")
            Text("Processing")
    ```

    ```json Protocol icon="brackets-curly" theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
    {
      "view": {
        "cssClass": "gap-4 items-center",
        "type": "Row",
        "children": [
          {
            "type": "Badge",
            "variant": "success",
            "children": [
              {"type": "Icon", "name": "check", "size": "sm"},
              {"content": "Verified", "type": "Text"}
            ]
          },
          {
            "type": "Badge",
            "variant": "default",
            "children": [
              {"type": "Loader", "variant": "spin", "size": "sm"},
              {"content": "Syncing", "type": "Text"}
            ]
          },
          {
            "type": "Badge",
            "variant": "secondary",
            "children": [
              {"type": "Loader", "variant": "dots", "size": "sm"},
              {"content": "Processing", "type": "Text"}
            ]
          }
        ]
      }
    }
    ```
  </CodeGroup>
</ComponentPreview>

## API Reference

<Card icon="code" title="Badge Parameters">
  <ParamField body="label" type="str | None" default="None">
    Badge text. Can be passed as a positional argument. When using children, omit the label and compose content directly.
  </ParamField>

  <ParamField body="variant" type="str" default="default">
    Visual style: `"default"`, `"secondary"`, `"destructive"`, `"outline"`, `"ghost"`, `"success"`, `"warning"`, `"info"`.
  </ParamField>

  <ParamField body="css_class" type="str | None" default="None">
    Additional Tailwind CSS classes appended to the component's built-in styles.
  </ParamField>
</Card>

## Protocol Reference

```json Badge theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
{
  "type": "Badge",
  "id?": "string",
  "onMount?": "any",
  "children?": "[Component]",
  "let?": "object",
  "label?": "string",
  "variant?": "default | secondary | destructive | success | warning | info | outline | ghost | string",
  "cssClass?": "string"
}
```

For the complete protocol schema, see [Badge](/protocol/badge).
