Tag
Overview
The Tag component renders a Bulma-styled label or badge.
It supports color, size, rounded, hoverable, and delete (close) variants. Use it for status indicators, categorization, dismissible tokens, or compact UI elements.
Tags are perfect for highlighting statuses, categories, or adding removable tokens to your UI.
Import
import { Tag } from '@allxsmith/bestax-bulma';
Usage
Default Tag
A basic Tag renders a simple label. Use this for static status indicators or simple badges.
<Tag>Default Tag</Tag>
Colored Tag
Set the color prop to apply a Bulma color modifier, such as color="primary", for visual emphasis or to indicate status.
<Tag color="primary">Primary Tag</Tag>
Light Tag
Add the isLight prop to render the light variant of the chosen color — a softer, pastel version that works well for secondary status indicators.
<Tags> <Tag color="primary" isLight> Light Primary </Tag> <Tag color="danger" isLight> Light Danger </Tag> </Tags>
Medium and Large Tag
Use the size prop with values like size="medium" or size="large" to adjust the tag's size for different UI contexts.
<Tags> <Tag size="medium">Medium Tag</Tag> <Tag size="large">Large Tag</Tag> </Tags>
Rounded Tag
Add the isRounded prop to render a tag with fully rounded corners, making it stand out as a pill-shaped badge.
<Tag isRounded>Rounded Tag</Tag>
Delete Tag (Button)
Set isDelete to render a tag as a delete button. Use the onDelete callback to handle removal actions. The button is named "Delete tag" unless you pass an aria-label, and that name doesn't say which tag it removes, so give it one that does.
<Tags hasAddons> <Tag color="primary">React</Tag> <Tag isDelete aria-label="Remove React" onDelete={() => alert('Removed React')} /> </Tags>
With Margin
You can use Bulma helper props like m="4" to add margin around the tag for spacing within layouts.
<Tag m="4">Tag with Margin</Tag>
Combined Styles
Combine multiple props such as color, size, isRounded, and spacing helpers to create visually distinct tags.
<Tag color="success" size="medium" isRounded m="2"> Combined Tag </Tag>
All Colors
Render a set of tags with different color values to display a palette of available Bulma color modifiers. The isHoverable prop adds a hover effect to each tag.
<Tags> {( [ 'primary', 'link', 'info', 'success', 'warning', 'danger', 'black', 'dark', 'light', 'white', ] as const ).map(color => ( <Tag key={color} color={color} isHoverable> {color.charAt(0).toUpperCase() + color.slice(1)} </Tag> ))} </Tags>
Sizes Together
You can combine color, size, and isHoverable props to show all size variants for each color in a single layout.
<Block> {(['primary', 'success', 'danger'] as const).map(color => ( <Tags key={color}> <Tag color={color} size="normal" isHoverable> {color.charAt(0).toUpperCase() + color.slice(1)} Normal </Tag> <Tag color={color} size="medium" isHoverable> {color.charAt(0).toUpperCase() + color.slice(1)} Medium </Tag> <Tag color={color} size="large" isHoverable> {color.charAt(0).toUpperCase() + color.slice(1)} Large </Tag> </Tags> ))} </Block>
Hoverable Tag
Set isHoverable to give the tag Bulma's hover shade and pointer cursor. It's only a look: the tag is still a <span>, which a keyboard can't reach, so a tag that does something takes as="button" or as="a", below.
<Tag color="primary" isHoverable> Hoverable Tag </Tag>
Link or Button Tag
A tag that does something, a filter someone clicks or a topic it links to, renders the link or button Bulma styles with as. A keyboard reaches it, and a screen reader announces it as a link or a button. A button renders type="button", so it doesn't submit a form around it.
function example() { const [active, setActive] = React.useState(false); return ( <Tags> <Tag as="a" href="#components" color="info"> Components </Tag> <Tag as="button" color="primary" isLight={!active} aria-pressed={active} onClick={() => setActive(!active)} > Open issues </Tag> </Tags> ); }
Tag with Delete Component
You can combine Tag with the Delete component for custom dismissible tags. Use hasAddons on the Tags container to group them visually.
import { Tag, Tags, Delete } from '@allxsmith/bestax-bulma'; <Tags hasAddons> <Tag color="primary" size="medium"> React <Delete ariaLabel="Remove React" onClick={() => alert('Removed React')} /> </Tag> </Tags>;
Accessibility
- Delete buttons: A delete tag is named "Delete tag", and a
Deleteinside a tag "Close", unless you name them. Neither says which tag it removes, so a screen reader user moving between several hears the same name each time. Name each one after its tag:aria-label="Remove React"on a delete tag,ariaLabel="Remove React"on aDelete. - Keyboard: Delete tags are rendered as
<button>, supporting keyboard activation. A tag that does something takesas="button"oras="a", so a keyboard reaches it and a screen reader announces it as a button or a link.isHoverableonly changes the look, and leaves a span out of the keyboard's reach. - Focus: A link or button tag shows Bulma's focus ring on keyboard focus, as Bulma's links and buttons do.
- Semantics: Use tags for supplemental information, not as primary headings.
- Contrast: A light tag's text, and a white, black or dark tag's with
isLight, reads against its background the way a lightButton's does, in both color schemes. That comes from bestax's stylesheets, as thecolorandisLightprops' descriptions say.
Combine Tag with Tags for grouped, multi-tag UIs.
Related Components
Tags: For grouping tags.Delete: For standalone delete buttons.- Helper Props: Bulma helper props for spacing, color, etc.
Additional Resources
Props
| Prop | Type | Default | Description |
|---|---|---|---|
as | 'span' | 'a' | 'button' | 'span' | Element to render (default span). A tag that does something, a filter someone clicks or a topic it links to, takes button or a, so a keyboard reaches it and a screen reader announces it as a button or a link. Bulma styles both, and bestax's stylesheets give a button tag the font and text a span takes from the text around it. A button renders type="button" unless you pass submit or reset. A link's attributes, such as href, need as="a", and a button's, such as disabled, as="button". With isDelete, the tag renders its delete button whatever this says. |
className | string | — | Additional CSS classes to apply. |
color | TagColor | — | Bulma color modifier for the tag. light takes the light color's own text from bestax's stylesheets. With Bulma's CSS alone, a light tag's text inherits the color around it, which on a dark page is hard to read. |
size | 'normal' | 'medium' | 'large' | — | Tag size. |
isLight | boolean | false | Use the light color variant. The light color has none, so color="light" with isLight looks the same as without it. white, black and dark with isLight keep Bulma's light background, and bestax's stylesheets give their text the lightness a light tag's text has. With Bulma's CSS alone, their text inherits the color around it, which on a dark page is hard to read. |
isRounded | boolean | false | Renders a rounded tag. |
isDelete | boolean | false | Renders a delete-style tag (delete button). The button renders type="button", so it does not submit a form around it, and is named "Delete tag" unless you pass an aria-label. An empty one, or a spread carrying 'aria-label': undefined, keeps that name rather than leaving the button unnamed. "Delete tag" doesn't say which tag the button removes, so pass a name that does, such as aria-label="Remove React". |
isHoverable | boolean | false | Adds Bulma's hover shade and pointer cursor. It's only a look: a span tag stays out of the keyboard's reach, so a tag that does something takes as="button" or as="a" instead. |
onDelete | () => void | — | Callback for delete tag/button. |
children | React.ReactNode | — | Tag content. |
... | All standard <a> / <button> / <span> attributes and Bulma helper props | — | See Helper Props |
Types:
TagColor:'primary'|'link'|'info'|'success'|'warning'|'danger'|'black'|'dark'|'light'|'white'— Valid color values for the Tag component (Bulma tag colors).
CSS & Sass Variables
Tag registers these variables on its own .tag element. Override them there (or via className) — a value set on an ancestor is only inherited, and loses to the component-level declaration. See Theme.
| CSS Variable | Sass Variable | Default |
|---|---|---|
--bulma-tag-h | $tag-h | var(--bulma-scheme-h) |
--bulma-tag-s | $tag-s | var(--bulma-scheme-s) |
--bulma-tag-background-l | $tag-background-l | var(--bulma-background-l) |
--bulma-tag-background-l-delta | $tag-background-l-delta | 0% |
--bulma-tag-hover-background-l-delta | $tag-hover-background-l-delta | var(--bulma-hover-background-l-delta) |
--bulma-tag-active-background-l-delta | $tag-active-background-l-delta | var(--bulma-active-background-l-delta) |
--bulma-tag-color-l | $tag-color-l | var(--bulma-text-l) |
--bulma-tag-radius | $tag-radius | var(--bulma-radius) |
--bulma-tag-delete-margin | $tag-delete-margin | 1px |