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. Use icon-search or
icon-success for Moraine’s semantic aliases. Editor completion suggests the built-in names, while
i-lucide-search and app-logo remain valid. Icon applies string names as classes, so your
UnoCSS or Tailwind setup must generate the CSS for custom names.
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 is
rendered.
Root styling#
Icon always renders one span root, whatever the name source. Use class and style for an
individual icon, or configure icon.base.root in your Theme for shared defaults. root is the only
slot, so classes and styles only duplicate class and style.
Every icon follows the surrounding font size. A string icon is sized by its icon class, which is
1.2em in moraine/icon.css. For a JSX or component graphic, the root is a 1.2em box
(size-[1.2em]) and the graphic fills it through *:size-full. Resize an icon with a
font-size utility on the icon or an ancestor, such as text-2xl, or with a size utility such as
size-6 on the icon; the graphic follows the root. moraine/icon.css puts its rules in the
components cascade layer, so these utilities override it in both UnoCSS and Tailwind.
Icon renders no data-slot of its own. Pass a data-slot attribute 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 replace that background with the page
background and hide the icon. For string icons, Icon adds the icon-mask class, which sets
forced-color-adjust: preserve-parent-color (falling back to none) and drops its own color, so
the icon is painted with the surrounding forced text color. presetMoraine defines icon-mask as a
shortcut and the Tailwind plugin defines it as a utility. Element and component icons keep the browser’s default forced colors handling.
Examples#
Mark deploy status with class names#
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.
Render a custom SVG glyph#
Pass a JSX element or a Solid component when the mark is not an icon-class name. It renders inside
the Icon root. Components are rendered without props: class, style, data-slot, and ARIA
attributes go to the root, and the SVG inherits its color through currentColor. To set an
SVG-specific attribute such as stroke-width, pass inline JSX instead. Name the icon when it is the
only indicator.
Name a warning and hide a decorative check#
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.