Tag

A small label for a keyword or a choice, which the user can often remove.

Plain tag
Closable tag

Usage

Code
import { Tag } from '@leverui/components';
Code
<Tag.Root>
  <Tag.Label>Tag here</Tag.Label>
</Tag.Root>

For one ready-made component, see the snippet below.

Examples

Icon

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

Member
Top rated
Guest

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.

Fitness
Travel

Overflow

Use the max-width style 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.

This label is much too long to fit in a tag that is only 200 pixels wide, so the tag shows as much of the text as it can on one line and cuts off the rest

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.

IC
Iris sm
IC
Iris md
IC
Iris lg
IC
Iris xl

Render as button

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

Closed Component

Code
import { Show, omit } from 'solid-js';
import type { JSX } from '@solidjs/web';
import { Tag, type TagRootProps } from '@leverui/components';

export type ClosedTagProps = TagRootProps & {
  startElement?: JSX.Element;
  endElement?: JSX.Element;
  onClose?: () => void;
  closable?: boolean;
};

export function ClosedTag(props: ClosedTagProps) {
  const root = omit(props, 'startElement', 'endElement', 'onClose', 'closable', 'children');

  return (
    <Tag.Root {...root}>
      <Show when={props.startElement}>
        <Tag.StartElement>{props.startElement}</Tag.StartElement>
      </Show>
      <Tag.Label>{props.children}</Tag.Label>
      <Show when={props.endElement}>
        <Tag.EndElement>{props.endElement}</Tag.EndElement>
      </Show>
      <Show when={props.closable ?? Boolean(props.onClose)}>
        <Tag.EndElement>
          <Tag.CloseTrigger onClick={() => props.onClose?.()} />
        </Tag.EndElement>
      </Show>
    </Tag.Root>
  );
}

Props

Root

PropDefaultTypeDescription
colorPalettegray'gray' | 'red' | 'orange' | 'yellow' | 'green' | 'teal' | 'blue' | 'cyan' | 'purple' | 'pink'Color palette.
sizemd'sm' | 'md' | 'lg' | 'xl'Tag size. Responsive.
variantsurface'subtle' | 'solid' | 'outline' | 'surface'Tag style. Responsive.
asdivNative HTML tagHTML tag to render.
asChild—Solid render functionRender your own element with the tag's props.
unstyledfalsebooleanTurn off the Lever UI styles.

The root is a native div with no ARIA role. The label and the start and end elements are span elements. The label stays on one line. For long text, limit the root's width with style.

Tag.CloseTrigger is a native type="button" with a decorative close icon. Screen readers announce it as Close. Pass a more specific aria-label when the user needs to know what closes. It does not remove the tag, so do that in onClick.

With asChild, spread getProps() on your element to keep the Tag styles, attributes, and events. Tag.RootPropsProvider takes its defaults as an object or a Solid accessor. Use an accessor when they depend on signals. A prop on a tag wins.

Customize with CSS

Import @leverui/components/styles.css, then style .leverui-tag__root, .leverui-tag__label, .leverui-tag__startElement, .leverui-tag__endElement, and .leverui-tag__closeTrigger. The class names do not change.

The root has attributes for its size, variant, and palette. Responsive values add data-size-sm through data-size-2xl and data-variant-sm through data-variant-2xl. Override the --leverui-* variables on a theme scope or on a single Tag.

Code
.leverui-tag__label {
  letter-spacing: 0.01em;
}

A part's class gives your own element that part's default styles. <span class="leverui-tag__label">Custom</span> inside Tag.Root follows the root's current size.

Explorer

Click a part name to highlight it in the preview.

Component Anatomy

Hover to highlight, click to select parts