coss.com Svelte

Badge

A badge or a component that looks like a badge.

Loading p-badge-1 preview…

Installation

pnpm dlx shadcn-svelte@latest add https://coss-sv.vercel.app/r/badge.json

Usage

<script lang="ts">
  import { Badge } from "$lib/components/ui/badge/index.js";
</script>

<Badge>Badge</Badge>

Use the as prop to render another element with the badge styles. Here is a link that looks like a badge.

<script lang="ts">
  import { Badge } from "$lib/components/ui/badge/index.js";
</script>

<Badge as="a" href="/pricing">New</Badge>

API Reference

Badge

A badge component with variant and size options. Native attributes for the selected element pass through.

PropTypeDefaultDescription
variant"default" \| "destructive" \| "error" \| "info" \| "outline" \| "secondary" \| "success" \| "warning""default"Controls the badge styling and color scheme
size"default" \| "sm" \| "lg""default"Controls the badge size
askeyof SvelteHTMLElements"span"Selects the rendered HTML element

Examples

Outline

Loading p-badge-2 preview…

Secondary

Loading p-badge-3 preview…

Destructive

Loading p-badge-4 preview…

Info

Loading p-badge-5 preview…

Success

Loading p-badge-6 preview…

Warning

Loading p-badge-7 preview…

Error

Loading p-badge-8 preview…

Small

Loading p-badge-9 preview…

Large

Loading p-badge-10 preview…

With Icon

Loading p-badge-11 preview…
Loading p-badge-12 preview…

With Count

Loading p-badge-13 preview…