---
title: "MazBadge"
description: "MazBadge is a standalone component to show short text in colored container"
package: "maz-ui"
url: "https://maz-ui.com/components/maz-badge"
---

# MazBadge

> MazBadge is a standalone component to show short text in colored container

- Package: `maz-ui`
- Import: `import MazBadge from 'maz-ui/components/MazBadge'`
- Nuxt: auto-imported by `@maz-ui/nuxt`, no import needed in a Nuxt app
- Web: https://maz-ui.com/components/maz-badge

> Before use it, you should install the MazUi plugin in your project, follow instructions in [Getting Started](../guide/getting-started.md)

## Basic usage

```vue
<script lang="ts" setup>
  import MazBadge from 'maz-ui/components/MazBadge'
</script>

<template>
  <MazBadge>
    Badge
  </MazBadge>
</template>
```

## Options

> See all options props here

### Colors

```vue
<script lang="ts" setup>
  import MazBadge from 'maz-ui/components/MazBadge'

  const colors = [
    'primary',
    'secondary',
    'info',
    'success',
    'warning',
    'destructive',
    'contrast',
    'accent',
    'surface',
    'container',
    'transparent',
  ]
</script>

<template>
  <MazBadge v-for="color in color" :key="color" :color="color">
    {{ color }}
  </MazBadge>
</template>
```

### Outlined

```vue
<script lang="ts" setup>
import MazBadge from 'maz-ui/components/MazBadge'

const colors = [
  'primary',
  'secondary',
  'info',
  'success',
  'warning',
  'destructive',
  'contrast',
  'accent',
  'surface',
  'container',
  'transparent',
]
</script>

<template>
  <MazBadge v-for="color in color" :key="color" :color="color" outlined>
    {{ color }}
  </MazBadge>
</template>
```

### Pastel

```vue
<script lang="ts" setup>
  import MazBadge from 'maz-ui/components/MazBadge'

  const colors = [
    'primary',
    'secondary',
    'info',
    'success',
    'warning',
    'destructive',
    'contrast',
    'accent',
    'surface',
    'container',
    'transparent',
  ]
</script>

<template>
  <MazBadge v-for="color in color" :key="color" :color="color" pastel>
    {{ color }}
  </MazBadge>
</template>
```

### Size

The `size` prop accepts one of the standardized `MazSize` values (`'mini' | 'xs' | 'sm' | 'md' | 'lg' | 'xl'`). The default is `'md'`. Padding, line-height and dimensions all scale relative to the chosen font-size, so a single keyword controls the whole badge footprint.

```vue
<script lang="ts" setup>
import MazBadge from 'maz-ui/components/MazBadge'

const sizes = ['mini', 'xs', 'sm', 'md', 'lg', 'xl']
</script>

<template>
  <MazBadge v-for="size in sizes" :key="size" :size="size">
    {{ size }}
  </MazBadge>
</template>
```

### Rounded sizes

```vue
<script lang="ts" setup>
import MazBadge from 'maz-ui/components/MazBadge'

const roundedSize = ['none', 'sm', 'md', 'lg', 'xl', 'full']
</script>

<template>
  <MazBadge v-for="size in roundedSize" :key="size" :rounded-size="size">
    {{ size }}
  </MazBadge>
</template>
```

### Removable

Add `removable` to show a remove button at the end of the badge: it emits `remove` with the click event and has an accessible label ("Remove", translated), which you can change with `remove-label`. The button uses the color of the badge text and a visible focus ring, so it works with every color and with `outlined` and `pastel`.

Last removed:

```vue
<script lang="ts" setup>
import MazBadge from 'maz-ui/components/MazBadge'
import { ref } from 'vue'

const tags = ref(['Vue', 'Nuxt', 'Vite'])

function removeTag(tag: string) {
  tags.value = tags.value.filter(t => t !== tag)
}
</script>

<template>
  <MazBadge v-for="tag in tags" :key="tag" removable @remove="removeTag(tag)">
    {{ tag }}
  </MazBadge>
</template>
```

## MazBadge API

`import MazBadge from 'maz-ui/components/MazBadge'`

### Props

- `color` (`MazBadgeColor`, default: `"primary"`): Color of the badge: `surface` and `container` are the neutral colors of the theme, with the foreground text. Values: `'primary'`, `'secondary'`, `'accent'`, `'info'`, `'success'`, `'warning'`, `'destructive'`, `'contrast'`, `'transparent'`, `'surface'`, `'container'` (non exhaustive).
- `size` (`"xs" | "sm" | "md" | "lg" | "xl" | "mini"`, default: `md`): Size of the badge - drives font-size; padding, line-height and dimensions scale relative to it via `em` units.
- `nowrap` (`boolean`, default: `true`): Will not wrap the text.
- `outlined` (`boolean`, default: `false`): Will add a border to the badge.
- `pastel` (`boolean`, default: `false`): Will add a pastel style to the badge.
- `rounded-size` (`MazBadgeRoundedSize`, default: `md`): Size radius of the component's border. Values: `'none'`, `'sm'`, `'md'`, `'lg'`, `'xl'`, `'full'` (non exhaustive).
- `removable` (`boolean`, default: `false`): Will add a remove button at the end of the badge, which emits `remove`.
- `remove-label` (`string`): Accessible label of the remove button (translated "Remove" by default).

### Events

- `@remove` (payload: `event: MouseEvent`): Emitted when the remove button is clicked (`removable` only)

### Slots

- `#default`: Badge content
