---
title: "Icon · UI SDK — StyleX Blocks"
description: "A sizing wrapper for inline SVG icons that inherits the current text color."
url: "https://stylexblocks.com/components/ui-sdk/icon/"
agent:
  instructions: "Use this search API to find relevant components and blocks across this site with keywords or natural-language queries, instead of crawling individual pages. Results are returned in Markdown."
  endpoint: "https://stylexblocks.com/.well-known/search?q={query}"
  method: "GET"
  documentation: "https://developers.cloudflare.com/ai-search/how-to/search-for-agents/"
---

# Icon

A sizing wrapper for inline SVG icons that inherits the current text color.

- Behavior engine: UI SDK
- Also available for: [Ark UI](https://stylexblocks.com/components/ark-ui/icon.md), [Base UI](https://stylexblocks.com/components/base-ui/icon.md)
- Category: Display
- Sizes: inherit, xs, sm, md, lg, xl, 2xl
- Used in blocks: [Basic Login](https://stylexblocks.com/block/ui-sdk/basic-login.md), [Card Grid](https://stylexblocks.com/block/ui-sdk/card-grid.md), [Centered Hero](https://stylexblocks.com/block/ui-sdk/centered-hero.md), [Checkout Form](https://stylexblocks.com/block/ui-sdk/checkout-form.md), [Checkout Wizard](https://stylexblocks.com/block/ui-sdk/checkout-wizard.md), [Classic Gallery](https://stylexblocks.com/block/ui-sdk/classic-gallery.md), [Comparison Table](https://stylexblocks.com/block/ui-sdk/comparison-table.md), [Contact Form](https://stylexblocks.com/block/ui-sdk/contact-form.md), [Course Detail](https://stylexblocks.com/block/ui-sdk/course-detail.md), [Documentation Catalog](https://stylexblocks.com/block/ui-sdk/documentation-catalog.md), [Documentation Design](https://stylexblocks.com/block/ui-sdk/documentation-design.md), [Documentation Technical](https://stylexblocks.com/block/ui-sdk/documentation-technical.md), [Filterable Table](https://stylexblocks.com/block/ui-sdk/filterable-table.md), [Two-Column Form](https://stylexblocks.com/block/ui-sdk/form-two-column.md), [Form Wizard](https://stylexblocks.com/block/ui-sdk/form-wizard.md), [Dialog Wizard](https://stylexblocks.com/block/ui-sdk/form-wizard-dialog.md), [Inline Wizard](https://stylexblocks.com/block/ui-sdk/form-wizard-inline.md), [Vertical Wizard](https://stylexblocks.com/block/ui-sdk/form-wizard-vertical.md), [Gallery Hero](https://stylexblocks.com/block/ui-sdk/gallery-hero.md), [Grouped Table](https://stylexblocks.com/block/ui-sdk/grouped-table.md), [IDE Workspace](https://stylexblocks.com/block/ui-sdk/ide.md), [Inbox Table](https://stylexblocks.com/block/ui-sdk/inbox-table.md), [Incident Console](https://stylexblocks.com/block/ui-sdk/incident-console.md), [Kanban Board](https://stylexblocks.com/block/ui-sdk/kanban-board.md), [Login Card](https://stylexblocks.com/block/ui-sdk/login-card.md), [Login Split](https://stylexblocks.com/block/ui-sdk/login-split.md), [Login SSO](https://stylexblocks.com/block/ui-sdk/login-sso.md), [Messaging Shell](https://stylexblocks.com/block/ui-sdk/messaging-shell.md), [Mixed Gallery](https://stylexblocks.com/block/ui-sdk/mixed-gallery.md), [Order Detail](https://stylexblocks.com/block/ui-sdk/order-detail.md), [Page Editor](https://stylexblocks.com/block/ui-sdk/page-editor.md), [Product Detail](https://stylexblocks.com/block/ui-sdk/product-detail.md), [Product Gallery](https://stylexblocks.com/block/ui-sdk/product-gallery.md), [Searchable Table](https://stylexblocks.com/block/ui-sdk/searchable-table.md), [Settings Dialog](https://stylexblocks.com/block/ui-sdk/settings-dialog.md), [Settings Form](https://stylexblocks.com/block/ui-sdk/settings-form.md), [Settings Panels](https://stylexblocks.com/block/ui-sdk/settings-panels.md), [Shell Nav](https://stylexblocks.com/block/ui-sdk/shell-nav.md), [Side Nav Shell](https://stylexblocks.com/block/ui-sdk/shell-side-nav.md), [Top Nav Shell](https://stylexblocks.com/block/ui-sdk/shell-top-nav.md), [Side Gallery](https://stylexblocks.com/block/ui-sdk/side-gallery.md), [Simple Table](https://stylexblocks.com/block/ui-sdk/simple-table.md), [Theme Showcase](https://stylexblocks.com/block/ui-sdk/theme-showcase.md), [Work Item Detail](https://stylexblocks.com/block/ui-sdk/work-item-detail.md)
- HTML page: https://stylexblocks.com/components/ui-sdk/icon/

## Install

Configure the project once (sets the behavior engine and import aliases):

```sh
npx stylexblocks init --style ui-sdk
```

Then add the item as source you own:

```sh
npx stylexblocks add icon
```

Equivalent: `npx shadcn add @stylexblocks/icon`. Registry item JSON: https://stylexblocks.com/r/ui-sdk/icon.json

## Usage

```tsx
import { Icon } from "#components/ui/ui-sdk/icon.tsx";

export function Example() {
  return (
    <>
      {/* the component is an svg element — viewBox and paths pass through,
          and the size prop resolves through the StyleX recipe */}
      <Icon viewBox="0 0 24 24" fill="none" size="md" aria-hidden="true">
        <path d="M13 2 4.5 13.5H11L10 22l8.5-11.5H12L13 2Z" stroke="currentColor" strokeWidth="1.5" strokeLinejoin="round" />
      </Icon>

      {/* composition: the render prop sizes an existing icon component */}
      <Icon size="lg" render={<BoltIcon />} />
    </>
  );
}
```

## Source

`components/ui/ui-sdk/icon.tsx`

```tsx
import * as stylex from "@stylexjs/stylex";
import { createComponent } from "#lib/ui-sdk/create-component.tsx";
import { defineRecipe } from "#lib/recipe-props.ts";
import { sizes } from '@stylexblocks/ui/tokens/sizes.stylex.ts'

const iconStyles = stylex.create({
  base: {
    display: 'inline-block',
    lineHeight: '1em',
    flexShrink: 0,
    color: 'currentcolor',
    verticalAlign: 'middle',
    width: 'var(--icon-size)',
    height: 'var(--icon-size)',
  },
})

const iconSizes = stylex.create({
  inherit: {
    '--icon-size': '1em',
  },
  xs: {
    '--icon-size': sizes._3,
  },
  sm: {
    '--icon-size': sizes._4,
  },
  md: {
    '--icon-size': sizes._5,
  },
  lg: {
    '--icon-size': sizes._6,
  },
  xl: {
    '--icon-size': sizes._7,
  },
  '2xl': {
    '--icon-size': sizes._8,
  },
})

export type IconSize = keyof typeof iconSizes

/**
 * Icon — recipe and component colocated in one file. The size prop resolves
 * mechanically from the axis map; the element is an `svg`, so viewBox,
 * fill, and path children pass straight through. Composition via `render`.
 */
const iconRecipe = defineRecipe({
  styles: iconStyles,
  axes: { size: iconSizes },
  defaultVariants: { size: "inherit" },
});

export const Icon = createComponent("svg", iconRecipe, "Icon");

export type IconProps = React.ComponentProps<typeof Icon>;
```
