Skip to content

Badge

A number or status marker that appears next to buttons or icons.

Basic Usage

Use the value prop to define the displayed number, and the type prop to set different types.

Basic Usage

Maximum Value

Use the max prop to set the maximum value. Values exceeding the max will display {max}+.

Maximum Value

Dot Badge

Use the is-dot prop to display a dot indicator.

Dot Badge

Text Content

The value prop can also accept strings to display text content.

Text Content

Custom Color

Customize the badge color through the color prop.

Custom Color

Offset

Customize the badge position through the offset prop.

Offset

Show Zero

By default, the badge is hidden when value is 0. Use the show-zero prop to force display.

Show Zero

Custom Content

Use the #content slot to customize the badge content.

Custom Content

Standalone

Can be used independently without wrapping any content.

Standalone

Use in Nuxt

The Badge component fully supports Nuxt 3/4 SSR rendering. During server-side rendering, badge content and position are directly included in the generated HTML, ensuring users can see real-time notification status on initial page load, enhancing user experience.

Use in Nuxt

SSR Notes:

  • ✅ Initial value, maximum value limit (max) render correctly on the server
  • ✅ Dot badge (is-dot) and standalone mode support SSR
  • ✅ Custom color and offset take effect on initial page load
  • 💡 Dynamic updates (e.g., real-time unread count via WebSocket) will be automatically completed through the reactive system after client-side activation

State Sync Recommendation

In the Nuxt ecosystem, it is recommended to store badge values in useState or Pinia for zero-cost state synchronization across routes and from SSR to Client.

API

Props

PropDescriptionTypeDefault
valueDisplay valuestring | number
maxMaximum value, displays {max}+ when exceedednumber99
is-dotWhether to show a dot indicatorbooleanfalse
hiddenWhether to hide the badgebooleanfalse
typeBadge type'default' | 'primary' | 'success' | 'warning' | 'danger' | 'info''danger'
show-borderWhether to show borderbooleantrue
colorCustom badge colorstring
offsetBadge offset [x, y][number, number]
show-zeroWhether to show when value is 0booleanfalse

Slots

Slot NameDescription
defaultElement wrapped by the badge
contentCustom badge content

Theme Variables

VariableDescriptionDefault
--yh-badge-bg-colorBackground colorvar(--yh-color-danger)
--yh-badge-text-colorText color#ffffff
--yh-badge-font-sizeFont sizevar(--yh-font-size-xs)

Released under the MIT License.