Skip to main content
Default Gray Amethyst

Badge

<mo-badge> | MOBadge
Since 1.0 stable

Badges are used to draw attention and display statuses or counts.

Badge
<mo-badge>Badge</mo-badge>
import { MOBadge } from '@metsooutotec/modes-web-components/dist/react';

const App = () => <MOBadge>Badge</MOBadge>;

Examples

Variants

Set the variant attribute to change the badge’s variant.

Primary Neutral Inactive Info Success Warning Alert
<mo-badge variant="primary">Primary</mo-badge>
<mo-badge variant="neutral">Neutral</mo-badge>
<mo-badge variant="inactive">Inactive</mo-badge>
<mo-badge variant="info">Info</mo-badge>
<mo-badge variant="success">Success</mo-badge>
<mo-badge variant="warning">Warning</mo-badge>
<mo-badge variant="alert">Alert</mo-badge>
import { MOBadge } from '@metsooutotec/modes-web-components/dist/react';

const App = () => (
  <>
    <MOBadge variant="primary">Primary</MOBadge>
    <MOBadge variant="neutral">Neutral</MOBadge>
    <MOBadge variant="inactive">Inactive</MOBadge>
    <MOBadge variant="info">Info</MOBadge>
    <MOBadge variant="success">Success</MOBadge>
    <MOBadge variant="warning">Warning</MOBadge>
    <MOBadge variant="alert">Alert</MOBadge>
  </>
);

Sizes

Set the size attribute to change the badge’s size.

Small Medium Large
<mo-badge size="small">Small</mo-badge>
<mo-badge size="medium">Medium</mo-badge>
<mo-badge size="large">Large</mo-badge>
import { MOBadge } from '@metsooutotec/modes-web-components/dist/react';

const App = () => (
  <>
    <MOBadge size="small">Small</MOBadge>
    <MOBadge size="medium">Medium</MOBadge>
    <MOBadge size="large">Large</MOBadge>
  </>
);

Pill badges

Use the pill attribute to give badges rounded edges.

Primary Neutral Inactive Info Success Warning Alert
<mo-badge variant="primary" pill>Primary</mo-badge>
<mo-badge variant="neutral" pill>Neutral</mo-badge>
<mo-badge variant="inactive" pill>Inactive</mo-badge>
<mo-badge variant="info" pill>Info</mo-badge>
<mo-badge variant="success" pill>Success</mo-badge>
<mo-badge variant="warning" pill>Warning</mo-badge>
<mo-badge variant="alert" pill>Alert</mo-badge>
import { MOBadge } from '@metsooutotec/modes-web-components/dist/react';

const App = () => (
  <>
    <MOBadge variant="primary" pill>
      Primary
    </MOBadge>
    <MOBadge variant="neutral" pill>
      Neutral
    </MOBadge>
    <MOBadge variant="inactive" pill>
      Inactive
    </MOBadge>
    <MOBadge variant="info" pill>
      Info
    </MOBadge>
    <MOBadge variant="success" pill>
      Success
    </MOBadge>
    <MOBadge variant="warning" pill>
      Warning
    </MOBadge>
    <MOBadge variant="alert" pill>
      Alert
    </MOBadge>
  </>
);

Pulsating badges

Use the pulse attribute to draw attention to the badge with a subtle animation.

0 1 2 3 4 5 6
<div class="badge-pulse">
  <mo-badge variant="primary" pill pulse>0</mo-badge>
  <mo-badge variant="neutral" pill pulse>1</mo-badge>
  <mo-badge variant="inactive" pill pulse>2</mo-badge>
  <mo-badge variant="info" pill pulse>3</mo-badge>
  <mo-badge variant="success" pill pulse>4</mo-badge>
  <mo-badge variant="warning" pill pulse>5</mo-badge>
  <mo-badge variant="alert" pill pulse>6</mo-badge>
  <mo-badge variant="alert" pill pulse></mo-badge>
</div>

<style>
  .badge-pulse mo-badge:not(:last-of-type) {
    margin-right: 1rem;
  }
</style>
import { MOBadge } from '@metsooutotec/modes-web-components/dist/react';

const css = `
  .badge-pulse mo-badge:not(:last-of-type) {
    margin-right: 1rem;
  }
`;

const App = () => (
  <>
    <div className="badge-pulse">
      <MOBadge variant="primary" pill pulse>
        0
      </MOBadge>
      <MOBadge variant="success" pill pulse>
        1
      </MOBadge>
      <MOBadge variant="inactive" pill pulse>
        2
      </MOBadge>
      <MOBadge variant="warning" pill pulse>
        3
      </MOBadge>
      <MOBadge variant="alert" pill pulse>
        4
      </MOBadge>
      <MOBadge variant="neutral" pill pulse>
        5
      </MOBadge>
      <MOBadge variant="alert" pill pulse></MOBadge>
    </div>

    <style>{css}</style>
  </>
);

With buttons

One of the most common use cases for badges is attaching them to buttons. To make this easier, badges will be automatically positioned at the top-right when they’re a child of a button.

Requests 30 Warnings 8 Errors 6
<mo-button>
  Requests
  <mo-badge pill>30</mo-badge>
</mo-button>

<mo-button style="margin-left: 1rem;">
  Warnings
  <mo-badge variant="warning" pill>8</mo-badge>
</mo-button>

<mo-button style="margin-left: 1rem;">
  Errors
  <mo-badge variant="alert" pill>6</mo-badge>
</mo-button>
import { MOBadge, MOButton } from '@metsooutotec/modes-web-components/dist/react';

const App = () => (
  <>
    <MOButton>
      Requests
      <MOBadge pill>30</MOBadge>
    </MOButton>

    <MOButton style={{ marginLeft: '1rem' }}>
      Warnings
      <MOBadge variant="warning" pill>
        8
      </MOBadge>
    </MOButton>

    <MOButton style={{ marginLeft: '1rem' }}>
      Errors
      <MOBadge variant="alert" pill>
        6
      </MOBadge>
    </MOButton>
  </>
);

With menu items

When including badges in menu items, use the suffix slot to make sure they’re aligned correctly.

Messages Comments 4 Replies 12
<mo-menu
  style="max-width: 240px; border: solid 1px var(--mo-panel-border-color); border-radius: var(--mo-border-radius-medium);"
>
  <mo-menu-label>Messages</mo-menu-label>
  <mo-menu-item>Comments <mo-badge slot="suffix" variant="primary" pill>4</mo-badge></mo-menu-item>
  <mo-menu-item>Replies <mo-badge slot="suffix" variant="primary" pill>12</mo-badge></mo-menu-item>
</mo-menu>
import { MOBadge, MOButton, MOMenu, MOMenuItem, MOMenuLabel } from '@metsooutotec/modes-web-components/dist/react';

const App = () => (
  <MOMenu
    style={{
      maxWidth: '240px',
      border: 'solid 1px var(--mo-panel-border-color)',
      borderRadius: 'var(--mo-border-radius-medium)'
    }}
  >
    <MOMenuLabel>Messages</MOMenuLabel>
    <MOMenuItem>
      Comments
      <MOBadge slot="suffix" variant="primary" pill>
        4
      </MOBadge>
    </MOMenuItem>
    <MOMenuItem>
      Replies
      <MOBadge slot="suffix" variant="primary" pill>
        12
      </MOBadge>
    </MOMenuItem>
  </MOMenu>
);

Importing

If you’re using the autoloader or the traditional loader, you can ignore this section. Otherwise, feel free to use any of the following snippets to cherry pick this component.

Bundler React Script

To import this component using a bundler:

import '@metsooutotec/modes-web-components/dist/components/badge/badge.js';

To import this component as a React component:

import MOBadge from '@metsooutotec/modes-web-components/dist/react/badge/';

To import this component using a script tag:

<script type="module" src="https://modes-web.metso.com/dist/components/cdn/components/badge/badge.js"></script>

Slots

Name Description
(default) The badge’s content.

Learn more about using slots.

Properties

Name Description Reflects Type Default
variant The badge’s variant. 'primary' | 'neutral' | 'inactive' | 'success' | 'info' | 'warning' | 'alert' 'primary'
size The badge’s size. 'small' | 'medium' | 'large' 'small'
pill Draws a pill-style badge with rounded edges. boolean false
pulse Makes the badge pulsate to draw attention. boolean false
updateComplete A read-only promise that resolves when the component has finished updating.

Learn more about attributes and properties.

Parts

Name Description
base The component’s internal wrapper.

Learn more about customizing CSS parts.