Web Component

Icon

Place scalable vector icons anywhere in your content.

Table of contents

Under the hood, FrankenstyleKit uses Lucide, a collection of open-source icons known for their beautiful and consistent design. With built-in options for size, stroke width, color, and accessibility attributes, this component simplifies the process of incorporating iconography into your web applications.

Usage

Make sure to include the icon library script. For more details, see the installation instructions.

Once included, you can use the <uk-icon> tag and place any icon you like, for example:

Opting out

Using the built-in icon is completely optional. If you prefer to use a different icon library, place the code below right before loading any components. This suppresses errors and prevents missing object issues.

Icon library

To view the list of all currently available icons, please visit the Lucide website for the complete catalog of 1000+ icons.

Accessibility

The icon component provides robust accessibility support with three modes:

Semantic icons (with labels)

Use the label attribute for icons that convey meaning:

When a label is provided, the icon receives role="img" and aria-label automatically.

Decorative icons

Use the decorative attribute for purely visual icons:

Decorative icons are hidden from screen readers with aria-hidden="true".

Default behavior

Icons without labels or the decorative attribute are accessible but don’t have specific semantic meaning.

Internationalization

The Icon component supports internationalization for icon labels through multiple methods with the following priority order (highest to lowest):

  • Component-level i18n (via i18n attribute or script tag)
  • Global component-specific namespace (via <script id="uk-i18n">)
  • Label attribute value

Using the i18n attribute

Using a configuration script

Using global i18n

Place this in your document <head> or before any icon components:

Available i18n option

KeyDefaultDescription
labelAccessible label for the icon (used with role=“img”)

Custom classes

The Icon component supports custom CSS classes through the cls attribute.

Using simple string format

Using JSON object format

Available cls target

TargetDescription
svgThe SVG element itself

Custom inline styles

The Icon component supports custom inline styles through the stl attribute.

Example

Preventing layout shift

When loading Web Components, there may be a brief delay before the content is fully rendered. This can result in a flash of unstyled content or unprocessed templates. To mitigate this issue, consider setting a predefined height on the parent element to prevent layout shift and ensure a smooth user experience.

Attributes

NameTypeDefaultDescription
iconStringName of the Lucide icon to display (kebab-case format, e.g., “arrow-right”)
labelStringAccessible label for semantic icons (automatically adds role=“img”)
decorativeBooleanfalseMarks icon as decorative, hiding it from screen readers
roleStringARIA role for the icon (defaults to “img” when label is provided)
sizeStringUniform size for both width and height (overrides width/height attributes)
widthString16Icon width in pixels
heightString16Icon height in pixels
stroke-widthString2SVG stroke width
colorStringIcon color (any valid CSS color value)
fillStringnoneFill color for the icon (use with stroke-width=“0” for solid icons)
clsStringCustom CSS classes for the SVG element
stlStringCustom inline styles for the SVG element
i18nStringInternationalization strings as JSON object or via configuration script
force-prevent-rerenderBooleanfalsePrevents component rerendering (useful for HTMX or SPA scenarios)