Image label
A short text or an icon pinned to a corner of an image: “New”, “AI”, a discount, a video length. Requires Tabler 1.7+.
<div class="d-flex flex-wrap gap-3"> <twig:Tabler:ImageLabel src="/examples/photo-1.jpg" alt="Open-plan office with desks" width="200" label="New" variant="primary" /> <twig:Tabler:ImageLabel src="/examples/photo-2.jpg" alt="Meeting room with a long table" icon="player-play" label="1:24" width="200" /> <twig:Tabler:ImageLabel src="/examples/photo-3.jpg" alt="Lounge with sofas by the windows" label="-20%" variant="danger" position="top-start" width="200" /></div><div class="d-flex flex-wrap gap-3"> <div class="img-labeled"> <img src="/examples/photo-1.jpg" alt="Open-plan office with desks" width="200" /> <span class="img-label bg-primary text-primary-fg">New</span> </div> <div class="img-labeled"> <img src="/examples/photo-2.jpg" alt="Meeting room with a long table" width="200" /> <span class="img-label"> <i class="ti ti-player-play"></i> 1:24 </span> </div> <div class="img-labeled"> <img src="/examples/photo-3.jpg" alt="Lounge with sofas by the windows" width="200" /> <span class="img-label img-label-top-start bg-danger text-danger-fg">-20%</span> </div></div>src, alt and width render the image, label and icon the label, on a dark see-through background that stays
readable on any photo. variant colors it: primary secondary success danger warning info dark light
(bg-{variant} with its matching text-{variant}-fg):
<div class="d-flex flex-wrap gap-3"> {% for variant in ['primary', 'success', 'warning', 'danger'] %} <twig:Tabler:ImageLabel src="/examples/photo-3.jpg" alt="Lounge with sofas by the windows" label="{{ variant }}" variant="{{ variant }}" width="200" /> {% endfor %}</div><div class="d-flex flex-wrap gap-3"> <div class="img-labeled"> <img src="/examples/photo-3.jpg" alt="Lounge with sofas by the windows" width="200" /> <span class="img-label bg-primary text-primary-fg">primary</span> </div> <div class="img-labeled"> <img src="/examples/photo-3.jpg" alt="Lounge with sofas by the windows" width="200" /> <span class="img-label bg-success text-success-fg">success</span> </div> <div class="img-labeled"> <img src="/examples/photo-3.jpg" alt="Lounge with sofas by the windows" width="200" /> <span class="img-label bg-warning text-warning-fg">warning</span> </div> <div class="img-labeled"> <img src="/examples/photo-3.jpg" alt="Lounge with sofas by the windows" width="200" /> <span class="img-label bg-danger text-danger-fg">danger</span> </div></div>Position
Section titled “Position”The label sits in the bottom end corner. position moves it to top-start, top-end or bottom-start. The corners
follow the text direction, so start and end swap in right-to-left layouts:
<div class="d-flex flex-wrap gap-3"> {% for position in ['top-start', 'top-end', 'bottom-start', 'bottom-end'] %} <twig:Tabler:ImageLabel src="/examples/photo-1.jpg" alt="Open-plan office with desks" width="200" label="{{ position }}" position="{{ position }}" /> {% endfor %}</div><div class="d-flex flex-wrap gap-3"> <div class="img-labeled"> <img src="/examples/photo-1.jpg" alt="Open-plan office with desks" width="200" /> <span class="img-label img-label-top-start">top-start</span> </div> <div class="img-labeled"> <img src="/examples/photo-1.jpg" alt="Open-plan office with desks" width="200" /> <span class="img-label img-label-top-end">top-end</span> </div> <div class="img-labeled"> <img src="/examples/photo-1.jpg" alt="Open-plan office with desks" width="200" /> <span class="img-label img-label-bottom-start">bottom-start</span> </div> <div class="img-labeled"> <img src="/examples/photo-1.jpg" alt="Open-plan office with desks" width="200" /> <span class="img-label">bottom-end</span> </div></div>Composed
Section titled “Composed”Children replace the image and the label: an ImageLabel:Image, which takes any <img> attribute (a class, a
srcset…), and as many ImageLabel:Labels as corners. iconOnly makes a square label with only the icon, its
label kept for assistive technology:
<twig:Tabler:ImageLabel> <twig:Tabler:ImageLabel:Image src="/examples/photo-2.jpg" alt="Meeting room with a long table" class="rounded" width="320" /> <twig:Tabler:ImageLabel:Label position="top-start" variant="danger">Live</twig:Tabler:ImageLabel:Label> <twig:Tabler:ImageLabel:Label icon="crown" label="Premium" iconOnly position="top-end" /> <twig:Tabler:ImageLabel:Label>AI<span class="visually-hidden"> generated</span></twig:Tabler:ImageLabel:Label></twig:Tabler:ImageLabel><div class="img-labeled"> <img src="/examples/photo-2.jpg" alt="Meeting room with a long table" class="rounded" width="320" /> <span class="img-label img-label-top-start bg-danger text-danger-fg">Live</span> <span class="img-label img-label-icon img-label-top-end"> <i class="ti ti-crown"></i> <span class="visually-hidden">Premium</span> </span> <span class="img-label"> AI <span class="visually-hidden">generated</span> </span></div>Accessibility
Section titled “Accessibility”The label is real text, read after the image. Spell out a short form such as “AI” in a visually-hidden element, as in
the last label above, and name an icon-only label with label and iconOnly. The label does not take clicks: on a
linked image, a click on it follows the link.
| Prop | Type | Default | Description |
|---|---|---|---|
src |
string? | null |
Image URL, rendered with ImageLabel:Image |
alt |
string | '' |
Alternative text of the image |
width |
int|string? | null |
Width of the image (width attribute) |
label |
string? | null |
Label text, rendered with ImageLabel:Label |
icon |
string? | null |
Icon before the label text |
position |
string? | null |
top-start top-end bottom-start bottom-end (img-label-{position}) |
variant |
string? | null |
Label color (bg-{variant} text-{variant}-fg); unset, dark and see-through |
Other attributes go to the root <div class="img-labeled">.
ImageLabel:Label:
| Prop | Type | Default | Description |
|---|---|---|---|
label |
string? | null |
Label text |
icon |
string? | null |
Icon before the text |
iconOnly |
bool | false |
Square label with the icon only (img-label-icon); label is visually hidden |
position |
string? | null |
top-start top-end bottom-start bottom-end |
variant |
string? | null |
primary secondary success danger warning info dark light |
Other attributes go to the <span class="img-label">: a style setting the --tblr-img-label-* variables changes its
offset, size or background.
ImageLabel:Image takes src and alt; other attributes go to the <img>.
Sub-components
Section titled “Sub-components”| Component | Renders |
|---|---|
ImageLabel:Image |
<img>: the image the labels are pinned to |
ImageLabel:Label |
<span class="img-label">: one label in a corner |
Blocks
Section titled “Blocks”| Block | Default |
|---|---|
image |
ImageLabel:Image with the src, alt and width props, when src is set |
label |
ImageLabel:Label with the label props, when label or icon is set |
content |
image and label: replace it to compose freely |
Blocks of ImageLabel:Label: icon (an Icon of the icon prop) and content (the label prop).
