Tag
sl-tag
Tags are used as labels to organize things or to indicate a selection.
Examples
Basic Tag
<sl-tag variant="blue">Blue</sl-tag> <sl-tag variant="green">Green</sl-tag> <sl-tag variant="gray">Gray</sl-tag> <sl-tag variant="yellow">Yellow</sl-tag> <sl-tag variant="red">Red</sl-tag> <sl-tag variant="teal">Teal</sl-tag> <sl-tag variant="fuchsia">Fuchsia</sl-tag> <sl-tag variant="purple">Purple</sl-tag>
sl-tag variant="blue" Blue sl-tag variant="green" Green sl-tag variant="gray" Gray sl-tag variant="yellow" Yellow sl-tag variant="red" Red sl-tag variant="teal" Teal sl-tag variant="fuchsia" Fuchsia sl-tag variant="purple" Purple
Sizes
Use the size
attribute to change a tag’s size.
<sl-tag size="small">Small</sl-tag> <sl-tag size="medium">Medium</sl-tag> <sl-tag size="large">Large</sl-tag>
sl-tag size="small" Small sl-tag size="medium" Medium sl-tag size="large" Large
Semantic variants
A selection of tag colors also map to semantic variants: primary
(blue),
success
(green), neutral
(gray), warning
(yellow),
danger
(red).
<sl-tag variant="primary">Primary</sl-tag> <sl-tag variant="success">Success</sl-tag> <sl-tag variant="neutral">Neutral</sl-tag> <sl-tag variant="warning">Warning</sl-tag> <sl-tag variant="danger">Danger</sl-tag>
sl-tag variant="primary" Primary sl-tag variant="success" Success sl-tag variant="neutral" Neutral sl-tag variant="warning" Warning sl-tag variant="danger" Danger
Pill
Use the pill
attribute to give tags rounded edges. This variant is very similar to the pill
button. Use only when there’s little risk of it being confused with a button.
Note: Pill-shaped tags are not the standard tag pattern in our Design System, and there is no Figma component for this option. Please check with the design team before using this option.
<sl-tag size="small" pill>Small</sl-tag> <sl-tag size="medium" pill>Medium</sl-tag> <sl-tag size="large" pill>Large</sl-tag>
sl-tag size="small" pill=true Small sl-tag size="medium" pill=true Medium sl-tag size="large" pill=true Large
Removable
Use the removable
attribute to add a remove button to the tag.
<div class="tags-removable"> <sl-tag size="small" removable>Small</sl-tag> <sl-tag size="medium" removable>Medium</sl-tag> <sl-tag size="large" removable>Large</sl-tag> </div> <script> const div = document.querySelector('.tags-removable'); div.addEventListener('sl-remove', event => { const tag = event.target; tag.style.opacity = '0'; setTimeout(() => (tag.style.opacity = '1'), 2000); }); </script> <style> .tags-removable sl-tag { transition: var(--sl-transition-medium) opacity; } </style>
div.tags-removable sl-tag size="small" removable=true Small sl-tag size="medium" removable=true Medium sl-tag size="large" removable=true Large javascript: const div = document.querySelector(.tags-removable); div.addEventListener(sl-remove, event => { const tag = event.target; tag.style.opacity = 0; setTimeout(() => (tag.style.opacity = 1), 2000); }); css: .tags-removable sl-tag { transition: var(--sl-transition-medium) opacity; }
Usage
Tag Basics
- Tags can be removed (for example, when they are being used to indicate a filter selection), but they aren’t otherwise interactive
- Don’t use tags as buttons
When to Use a Tag
- Use a tag to label or organize items
- Use a tag to show that a certain category of items has been selected (e.g. a search filter)
When to Use Something Else
Component Props
Note: The following appear as options in the Properties table but are currently not part of the Teamshares Design System. Please check with the design team before using these options:
- Boolean
pill
Property | Default | Details |
---|---|---|
variant
|
'gray'
|
The tag’s theme variant. |
size
|
'medium'
|
The tag’s size. |
pill
|
false
|
Draws a pill-style tag with rounded edges. |
removable
|
false
|
Makes the tag removable and shows a remove button. |
updateComplete
|
A read-only promise that resolves when the component has finished updating. |
Learn more about attributes and properties.
Slots
Name | Details |
---|---|
(default) | The tag’s content. |
Learn more about using slots.
Events
Name | Name | Name | React Event | Details | |
---|---|---|---|---|---|
sl-remove
|
sl-remove
|
sl-remove
|
onSlRemove
|
Emitted when the remove button is activated. |
Learn more about events.
CSS Parts
Name | Description |
---|---|
base
|
The component’s base wrapper. |
content
|
The tag’s content. |
remove-button
|
The tag’s remove button, an <sl-icon-button> . |
remove-button__base
|
The remove button’s exported base part. |
Learn more about customizing CSS parts.
Dependencies
This component automatically imports the following dependencies.
-
<sl-icon>
-
<sl-icon-button>