Icon
Render decorative or named icons from utility names or JSX.
Anatomy#
Usage#
Use Icon for decoration or a named symbol alongside text. If the icon alone conveys meaning, give it an accessible name; otherwise it is hidden from assistive technology.
Icon sources#
Pass an icon class name, a JSX element, or a Solid component as name:
- Semantic aliases: use
icon-searchoricon-successfor Moraine’s built-in aliases (suggested by editor completion). - Utility classes: any class your UnoCSS or Tailwind setup generates, such as
i-lucide-searchorapp-logo. - Custom graphics: a JSX element or Solid component.
Solid control-flow nodes such as <Show>, <For>, and <Switch> are not supported as the top-level name value. Keep control flow outside Icon so it owns whether the component renders.
Root styling and sizing#
Icon always renders one span root, regardless of the name source. Use class and style for an individual icon, or configure icon.base.root in your Theme for shared defaults. Because root is the only slot, classes and styles duplicate class and style.
Every icon scales with the surrounding font size:
- String icons: sized by their icon class (
1.2eminmoraine/icon.css). - JSX or component graphics: the root renders a
1.2embox (size-[1.2em]) and the graphic fills it via*:size-full.
Resize an icon with a font-size utility on the icon or an ancestor (such as text-2xl), or with a box-size utility on the icon (such as size-6). moraine/icon.css places its rules in the components cascade layer, so utilities override it in both UnoCSS and Tailwind.
Icon renders no data-slot of its own. Pass data-slot when the icon fills a component slot.
Forced colors#
String icons are CSS masks painted with background-color: currentColor. In forced colors mode (such as Windows contrast themes), the browser would normally replace that background with the page background and hide the icon.
For string icons, Icon adds the icon-mask class (presetMoraine shortcut or Tailwind plugin utility). It sets forced-color-adjust: preserve-parent-color (falling back to none) and drops its own color so the mask paints with the surrounding forced text color.
Element and component icons keep the browser’s default forced colors handling.
Examples#
Icon classes#
Use Moraine aliases such as icon-success, or any class your UnoCSS or Tailwind setup generates (i-lucide:git-branch). Adjacent text is the accessible name when the icon is decoration.
Custom SVG#
Pass a JSX element or a Solid component when the mark is not an icon-class name. Components render inside the Icon root without props: class, style, data-slot, and ARIA attributes apply to the root, and the SVG inherits color through currentColor.
To set an SVG-specific attribute such as stroke-width, pass inline JSX instead. Give the icon an aria-label when it is the only indicator.
Accessibility#
Keep adjacent text as the name when the icon is decoration. Set aria-label when the icon is the
only indicator.
API Reference#
Props#
Props for the Icon component. Renders a <span> element by default.