---
title: "Icon · Ark UI — StyleX Blocks"
description: "A sizing wrapper for inline SVG icons that inherits the current text color."
url: "https://stylexblocks.com/components/ark-ui/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: Ark UI
- Also available for: [Base UI](https://stylexblocks.com/components/base-ui/icon.md), [UI SDK](https://stylexblocks.com/components/ui-sdk/icon.md)
- Category: Display
- Sizes: inherit, xs, sm, md, lg, xl, 2xl
- HTML page: https://stylexblocks.com/components/ark-ui/icon/

## Install

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

```sh
npx stylexblocks init
```

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/ark-ui/icon.json

## Usage

```tsx
import { Icon } from "#components/ui/ark-ui/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: asChild sizes an existing icon component */}
      <Icon asChild size="lg">
        <BoltIcon />
      </Icon>
    </>
  );
}
```

## Source

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

```tsx
import * as stylex from "@stylexjs/stylex";
import { createComponent } from "#lib/ark-ui/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 `asChild`.
 */
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>;
```
