Skip to content

Badge - Vant 4

Badge

🏷️ Want to grab attention with style? Let's dive into the Badge component!

Intro 📖

A tiny but mighty component that displays eye-catching badges or notification dots! 🔴 Perfect for showing unread messages, notifications, or any important status that deserves a spotlight! ✨

Install 📦

Ready to add some flair? Register the component globally via app.use - it's super easy! 🎯 Check out our Component Registration guide for more installation magic.

js
import { createApp } from'vue'; import { Badge } from'vant'; const app = createApp(); app.use(Badge);

Usage 🎮

Basic Usage ⚡

html

Max 🔢

Keep things tidy! When numbers get too big, the badge automatically shows a neat "99+" format. No more overwhelming your users with huge numbers! 📊

html

Custom Color 🎨

Express yourself! Change the badge color to match your brand or mood. Red for urgent, blue for info, green for success - the choice is yours! 🌈

html

Custom Content 🎭

Get creative! Use the content slot to add custom icons, text, or whatever your imagination dreams up! ✨

html
css
.badge-icon { display: block; font-size: 10px; line-height: 16px; }

Custom Position 📍

Location, location, location! Use the position prop to place your badge exactly where it needs to be. Top-left, bottom-right, or anywhere in between! 🎯

html

Standalone 🌟

Sometimes badges need their independence! Use them standalone without wrapping other elements - perfect for status indicators and labels! 🏷️

html

API

Props

AttributeDescriptionTypeDefault
contentBadge content (Effective when dot is false)*numberstring*
colorBackground colorstring#ee0a24

| dot | Whether to show dot | boolean | false | | max | Max value, show {max}+ when exceed, only works when content is number | number | string | - | | offset | Offset of badge dot, the two items of the array correspond to the horizontal and vertical offsets | [number | string, number | string] | - | | show-zero | Whether to show badge when content is zero | boolean | true | | position | Badge position, can be set to top-left``bottom-left``bottom-right | string | top-right |

Slots

NameDescription
defaultDefault slot
contentCustom badge content

Types

The component exports the following type definitions:

ts
importtype { BadgeProps, BadgePosition } from'vant';

Theming

CSS Variables

The component provides the following CSS variables, which can be used to customize styles. Please refer to ConfigProvider component.

NameDefault ValueDescription
--van-badge-size16px-
--van-badge-colorvar(--van-white)-
--van-badge-padding0 3px-
--van-badge-font-sizevar(--van-font-size-sm)-
--van-badge-font-weightvar(--van-font-bold)-
--van-badge-border-widthvar(--van-border-width)-
--van-badge-backgroundvar(--van-danger-color)-
--van-badge-dot-colorvar(--van-danger-color)-
--van-badge-dot-size8px-
--van-badge-font-apple-system-font, Helvetica Neue, Arial, sans-serif-
  • Icon - Icon component for custom badge content
  • Button - Interactive button component
  • Cell - Cell component with badge support
  • Tab - Tab component with badge indicators

Enterprise-level mobile solution based on Vant