Skip to Content
Cristal

Data

Badge

Short status or count, in a coloured pill.

<cr-badge>CrBadge

Example

cr-badge shows a short text in a pill: a status ("Paid", "Overdue") or a count. variant picks the colour: neutral (default), primary, success or danger. The text must carry the meaning: the colour only supports it.

With count, a number is added after the text. When it changes, it rolls to its new value through the numbers in between, like an odometer: digits go up when the number increases, down when it decreases.

DraftNewPaidOverdueUnreadReceive messagesMark all as read
'use client';

import { useState } from 'react';
import { CrBadge, CrBox, CrButton } from '@cristal-ui/react';

export default function BadgeBasic() {
  const [unread, setUnread] = useState(3);

  return (
    <CrBox display="flex" direction="column" gap="lg" align="start">
      <CrBox display="flex" gap="sm" align="center" wrap>
        <CrBadge>Draft</CrBadge>
        <CrBadge variant="primary">New</CrBadge>
        <CrBadge variant="success">Paid</CrBadge>
        <CrBadge variant="danger">Overdue</CrBadge>
      </CrBox>
      <CrBox display="flex" gap="sm" align="center" wrap>
        <CrBadge variant="primary" count={unread} live>
          Unread
        </CrBadge>
        <CrButton size="s" variant="secondary" onClick={() => setUnread((count) => count + 4)}>
          Receive messages
        </CrButton>
        <CrButton size="s" variant="outline" onClick={() => setUnread(0)}>
          Mark all as read
        </CrButton>
      </CrBox>
    </CrBox>
  );
}

Announcing changes

By default, a count change is not announced: the badge is read with the rest of the page. With live, it becomes a role="status" region: each change is announced politely ("Unread 7"), once the screen reader has finished its sentence. Keep live for counts whose change matters to the user, not for every badge in a list.

If the user asked their system to reduce motion, the number goes straight to its new value, without rolling.

Accessibility

  • The badge is text: it is read with its content and its number ("Unread 3").
  • The rolling digits are hidden from screen readers, which only read the final number.
  • Each variant pairs a light background with a dark text of the same hue, with a contrast of at least 4.5:1. Colour is never the only information: the text states the status.
  • With live, the announcement is polite (role="status") and does not interrupt the user.

API

Properties

PropertyTypeDefaultDescription
countnumber—Nombre affiché après le texte ; il défile jusqu'à chaque nouvelle valeur.
livebooleanfalseAnnonce poliment chaque changement aux lecteurs d'écran (zone role="status") ; désactivé par défaut.
variant"danger" | "neutral" | "primary" | "success"'neutral'Couleur : neutral (gris), primary, success, danger.

Slots

SlotDescription
defaultLe texte de la pastille.

CSS parts

To style it from outside: cr-badge::part(name) { … }

PartDescription
badgeLa pastille.
countLe nombre.

On this page