Skip to content
Dalvan UI

Icon

Size inline SVG icons and align them with surrounding text.

Playground

Add item
<span class="dv-inline-flex dv-align-items-center dv-gap-100 dv-color-primary dv-appearance-plain">
  <svg class="dv-icon" style="--dv-icon-size: 1.5rem" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true">
    <path d="M5 12h14M12 5v14" />
  </svg>
  Add item
</span>

Usage

After setting up the CSS, apply dv-icon to an SVG with a viewBox. Use currentColor for the fill or stroke so it follows the surrounding text color.

<span><svg class="dv-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true">
  <path d="M5 12h14M12 5v14" />
</svg> Add item</span>

Examples

Decorative icon with text

Hide decorative SVGs from assistive technology when visible text already conveys the meaning.

Add item
<span class="dv-color-primary dv-appearance-plain"><svg class="dv-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true">
  <path d="M5 12h14M12 5v14" />
</svg> Add item</span>

Named icon-only action

Give the button an accessible name and hide its decorative SVG. Use the existing button icon slot for button spacing.

<button type="button" class="dv-button dv-button--square dv-appearance-subtle dv-appearance-interactive" aria-label="Add item">
  <span class="dv-button__leading"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true">
  <path d="M5 12h14M12 5v14" />
</svg></span>
</button>

Custom size

Override the icon size on the SVG or an ancestor. The viewBox keeps the drawing proportional.

<svg class="dv-icon" style="--dv-icon-size: 2rem" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true">
  <path d="M5 12h14M12 5v14" />
</svg>

API reference

Class or attributeBehavior
dv-iconSets equal inline and block dimensions and vertically aligns the SVG.
aria-hidden=truearia-labelHide decorative artwork and give icon-only controls an accessible name.

Customization

Prefer the shared icon sizing for icons next to text and set a custom size for standalone artwork.

PropertyEffect and defaults
--dv-icon-sizeSets both dimensions. Defaults to 1em when no inherited icon size is set.