Build faster with Premium Chakra UI Components 💎

Learn more
Skip to Content
DocsPlaygroundGuidesBlog
Sponsor

Tag

Used for categorizing or labeling content

SourceStorybookRecipe
Plain Tag
Closable Tag

Usage

import { Tag } from "@chakra-ui/react"
<Tag.Root>
  <Tag.Label>Tag here</Tag.Label>
</Tag.Root>

Examples

Icon

Use the Tag.StartElement and Tag.EndElement components to add an icon to the start or end of the tag

Tag 1
Top Rated
Tag 2

Variants

Use the variant prop to change the appearance of the tag.

Gray
Gray
Gray
Gray
Gray
Gray
Gray
Gray
Gray
Gray
Gray
Gray

Sizes

Use the size prop to change the size of the tag.

Gray
Gray
Gray
Gray
Gray
Gray
Gray
Gray
Gray

Colors

Use the colorPalette prop to change the color of the tag.

gray

Content
Content
Content

red

Content
Content
Content

green

Content
Content
Content

blue

Content
Content
Content

teal

Content
Content
Content

pink

Content
Content
Content

purple

Content
Content
Content

cyan

Content
Content
Content

orange

Content
Content
Content

yellow

Content
Content
Content

Closable

Use the Tag.CloseTrigger within the Tag.EndElement to make the tag closable.

Tag 1
Tag 2

Overflow

Use the maxWidth prop to control the maximum width of the tag. When the content exceeds this width, it will be truncated with an ellipsis.

This is particularly useful when dealing with dynamic or user-generated content where the length might vary.

Lorem ipsum dolor sit amet consectetur adipisicing elit. Quisquam molestias, laboriosam, quod, quia quidem quae voluptatem natus exercitationem autem quibusdam

Avatar

The tag component has been designed to work well with the Avatar component.

Note: Set the avatar size to full to ensure it's sized correctly.

JD
Emily sm
JD
Emily md
JD
Emily lg
JD
Emily xl

Render as button

Use the asChild prop to render the tag as a button.

Closed Component

Here's how to setup the Tag for a closed component composition.

import { Tag as ChakraTag } from "@chakra-ui/react"
import * as React from "react"

export interface TagProps extends ChakraTag.RootProps {
  startElement?: React.ReactNode
  endElement?: React.ReactNode
  onClose?: VoidFunction
  closable?: boolean
}

export const Tag = React.forwardRef<HTMLSpanElement, TagProps>(
  function Tag(props, ref) {
    const {
      startElement,
      endElement,
      onClose,
      closable = !!onClose,
      children,
      ...rest
    } = props

    return (
      <ChakraTag.Root ref={ref} {...rest}>
        {startElement && (
          <ChakraTag.StartElement>{startElement}</ChakraTag.StartElement>
        )}
        <ChakraTag.Label>{children}</ChakraTag.Label>
        {endElement && (
          <ChakraTag.EndElement>{endElement}</ChakraTag.EndElement>
        )}
        {closable && (
          <ChakraTag.EndElement>
            <ChakraTag.CloseTrigger onClick={onClose} />
          </ChakraTag.EndElement>
        )}
      </ChakraTag.Root>
    )
  },
)

Props

Root

PropDefaultType
colorPalette 'gray'
'gray' | 'red' | 'orange' | 'yellow' | 'green' | 'teal' | 'blue' | 'cyan' | 'purple' | 'pink' | 'accent'

The color palette of the component

size 'md'
'sm' | 'md' | 'lg'

The size of the component

variant 'surface'
'subtle' | 'solid' | 'outline' | 'surface'

The variant of the component

Previous

Table

Next

Textarea