> ## Documentation Index
> Fetch the complete documentation index at: https://anvil.servicetitan.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Icon – Design

> Icons act as visual aids to help users complete tasks.

export const LiveCode = ({children, customHeight, clickToLoad, example, fullWidth, fullHeight, hideCodeInLiveCode, screenshot, screenshotOnly, showCode: showCodeProp}) => {
  const SCREENSHOTS_BASE = "https://servicetitan.github.io/anvil2-docs-live-code/screenshots";
  const STACKBLITZ_BASE = "https://stackblitz.com/github/servicetitan/anvil2-docs-live-code/tree/main/examples";
  const [showCodeBlock, setShowCodeBlock] = useState(showCodeProp ?? false);
  const [isLocalOverride, setIsLocalOverride] = useState(false);
  useEffect(() => {
    const examplePath = `/images/live-code-screenshots-tmp/${example}.png`;
    fetch(examplePath, {
      method: "HEAD"
    }).then(r => {
      if (r.ok) setIsLocalOverride(true);
    }).catch(() => {});
  }, [example]);
  const screenshotBase = isLocalOverride ? "/images/live-code-screenshots-tmp" : SCREENSHOTS_BASE;
  if (screenshotOnly) {
    return <Frame className="flex flex-col">
        <div className="flex dark:hidden" style={{
      justifyContent: "center",
      alignItems: "center",
      width: fullWidth ? "100%" : "50%",
      minHeight: fullHeight ? "284px" : undefined,
      background: "#FFFFFF"
    }}>
          <img srcset={`${screenshotBase}/${example}.png, ${screenshotBase}/${example}-2x.png 2x`} src={`${screenshotBase}/${example}.png`} alt={example} noZoom />
        </div>
        <div className="hidden dark:flex" style={{
      justifyContent: "center",
      alignItems: "center",
      width: fullWidth ? "100%" : "50%",
      minHeight: fullHeight ? "284px" : undefined,
      background: "#141414"
    }}>
          <img srcset={`${screenshotBase}/${example}-dark.png, ${screenshotBase}/${example}-dark-2x.png 2x`} src={`${screenshotBase}/${example}-dark.png`} alt={example} noZoom />
        </div>
      </Frame>;
  }
  if (screenshot) {
    return <Frame className="flex flex-col -mb-2">
        <div className="flex dark:hidden bg-white dark:bg-codeblock border border-gray-950/10 dark:border-white/10 dark:twoslash-dark rounded-2xl overflow-hidden" style={{
      justifyContent: "center",
      alignItems: "center",
      width: fullWidth ? "100%" : "50%",
      minHeight: fullHeight ? "284px" : undefined
    }}>
          <img srcset={`${screenshotBase}/${example}.png, ${screenshotBase}/${example}-2x.png 2x`} src={`${screenshotBase}/${example}.png`} alt={example} noZoom />
        </div>

        <div className="hidden dark:flex bg-white dark:bg-codeblock border border-gray-950/10 dark:border-white/10 dark:twoslash-dark rounded-2xl overflow-hidden" style={{
      background: "#141414",
      justifyContent: "center",
      alignItems: "center",
      width: fullWidth ? "100%" : "50%",
      minHeight: fullHeight ? "284px" : undefined
    }}>
          <img srcset={`${screenshotBase}/${example}-dark.png, ${screenshotBase}/${example}-dark-2x.png 2x`} src={`${screenshotBase}/${example}-dark.png`} alt={example} noZoom />
        </div>

        <div className="flex justify-end items-center text-xs py-2 px-1 gap-4">
          {!showCodeProp ? <button className="inline-flex justify-end items-center text-gray-700 dark:text-gray-50 hover:text-blue-500 dark:hover:text-blue-300 transition-colors group self-end gap-1 cursor-pointer" onClick={() => setShowCodeBlock(!showCodeBlock)} style={{
      appearance: "none"
    }}>
              <Icon icon="code" size="12px" className="group-hover:bg-blue-500 dark:group-hover:bg-blue-300" />
              <span>{showCodeBlock ? "Hide code" : "Show code"}</span>
            </button> : null}

          <a className="inline-flex justify-end items-center hover:text-blue-500 dark:hover:text-blue-300 transition-colors group self-end gap-1" href={`${STACKBLITZ_BASE}/${example}?file=src/App.tsx`} target="_blank" rel="noreferrer">
            <Icon icon="bolt" size="12px" className="group-hover:bg-blue-500 dark:group-hover:bg-blue-300" />
            <span>StackBlitz demo</span>
          </a>
        </div>

        <div className="grid transition-[grid-template-rows] duration-300 ease-in-out overflow-auto overflow-y-hidden overflow-x-auto" style={showCodeBlock ? {
      gridTemplateRows: "1fr"
    } : {
      gridTemplateRows: "0fr"
    }}>
          <div style={{
      minHeight: 0,
      overflowX: "auto",
      overflowY: "hidden",
      marginBlockStart: "-1.25rem",
      marginBlockEnd: "-1.5rem"
    }}>
            {children}
          </div>
        </div>
      </Frame>;
  } else {
    return <div style={{
      display: "flex",
      width: fullWidth ? "100%" : "50%",
      minHeight: customHeight ? customHeight : "316px",
      resize: "vertical",
      overflow: "auto"
    }}>
        <iframe title={example} style={{
      flex: 1,
      width: fullWidth ? "100%" : "50%",
      minHeight: customHeight ? customHeight : "316px"
    }} src={`${STACKBLITZ_BASE}/${example}?embed=1&hideNavigation=1&hideExplorer=1&terminalHeight=0&file=src/App.tsx${clickToLoad ? "&ctl=1" : ""}${hideCodeInLiveCode ? "&view=preview" : ""}`} allow="accelerometer; ambient-light-sensor; camera; encrypted-media; geolocation; gyroscope; hid; microphone; midi; payment; usb; vr; xr-spatial-tracking" sandbox="allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts" />
      </div>;
  }
};

export const CodePreviewPlaceholder = ({double, fullWidth}) => {
  const single = <div style={{
    width: fullWidth ? "100%" : "50%",
    borderRadius: "1rem",
    display: "flex",
    padding: "1rem",
    flexDirection: "column",
    gap: "0.5rem",
    height: "10rem",
    marginBlockEnd: "1rem"
  }} className="border-width-default border-color-subdued">
      <div className="bg-strong border-radius-large" style={{
    width: "100%",
    flexGrow: "1"
  }} />
      <div className="bg-strong border-radius-large" style={{
    width: "100%",
    flexGrow: "1"
  }} />
    </div>;
  return double ? <div style={{
    display: "flex",
    gap: "1rem"
  }}>
      {single}
      {single}
    </div> : single;
};

<Frame>
  <div className="w-full h-full bg-[#FFFFFF] p-2 rounded flex items-center justify-center">
    <img noZoom src="https://mintcdn.com/servicetitan/H5FwKyiqhPVZ1UJQ/images/docs/web/components/shared/preview-of-icon-component.png?fit=max&auto=format&n=H5FwKyiqhPVZ1UJQ&q=85&s=8a150a020ecf5e8204d5631388d5d40b" width="528" height="240" data-path="images/docs/web/components/shared/preview-of-icon-component.png" />
  </div>
</Frame>

## Anatomy

The Icon consists of two primary elements that work together to act as visual aids.

<Frame>
  <div className="w-full h-full bg-[#FFFFFF] p-2 rounded flex items-center justify-center">
    <img
      src="https://mintcdn.com/servicetitan/CekIMDXcDEhGoN_I/images/docs/web/components/icon/design/anatomy-of-an-icon.png?fit=max&auto=format&n=CekIMDXcDEhGoN_I&q=85&s=8df79371b6a430d914bcf9fd289f3b20"
      alt="Anatomy of an
icon"
      width="204"
      height="144"
      data-path="images/docs/web/components/icon/design/anatomy-of-an-icon.png"
    />
  </div>
</Frame>

1. Icon
2. Bounding area

## Options

The Icon supports multiple sizes, SVG support, and color configurations to accommodate various visual aid scenarios.

### Sizes

<LiveCode example="icon-size" screenshot fullWidth>
  ```tsx lines theme={null}
  import { Icon, Text } from "@servicetitan/anvil2";
  import Close from "@servicetitan/anvil2/assets/icons/material/round/close.svg";

  function App() {
    return (
      <div
        style={{
          display: "grid",
          gap: "1rem",
          fontFamily: "monospace",
          gridTemplateColumns: "60px 60px 60px 60px",
          justifyItems: "center",
          alignItems: "center",
        }}
      >
        <Icon svg={Close} size="small" />
        <Icon svg={Close} size="medium" />
        <Icon svg={Close} size="large" />
        <Icon svg={Close} size="xlarge" />
        <Text>small</Text>
        <Text>medium</Text>
        <Text>large</Text>
        <Text>xlarge</Text>
      </div>
    );
  }

  export default App;
  ```
</LiveCode>

| Size        | Height | When to use                                                  |
| ----------- | ------ | ------------------------------------------------------------ |
| Small       | 12px   | For high dense pages. Not recommended for interactive Icons. |
| Medium      | 16px   | Used within Buttons.                                         |
| Large       | 24px   | For supplementing information on the page, such as status.   |
| Extra Large | 32px   | For low density, expressive pages.                           |

### SVG support

Icon accepts SVGs. This typically involves using Anvil's provided icon library but also supports custom SVGs.

### Color

Icons inherit a color provided to them. When providing a color, use a token value.

<LiveCode example="icon-inherit" screenshot fullWidth>
  ```tsx lines theme={null}
  import { Icon, Text } from "@servicetitan/anvil2";
  import { core } from "@servicetitan/anvil2/token";
  import Warning from "@servicetitan/anvil2/assets/icons/material/round/warning.svg";

  function App() {
    return (
      <div
        style={{
          display: "grid",
          gap: "1rem",
          fontFamily: "monospace",
          gridTemplateColumns: "140px 140px 140px",
          justifyItems: "center",
          textAlign: "center",
        }}
      >
        <span>
          <Icon svg={Warning} size="large" />
        </span>
        <span style={{ color: core.semantic.BackgroundColorDanger.value }}>
          <Icon svg={Warning} size="large" inherit />
        </span>
        <span style={{ color: "#FF0000" }}>
          <Icon svg={Warning} size="large" inherit />
        </span>
        <Text>no color added</Text>
        <Text>token value (recommended)</Text>
        <Text>raw hex value (not recommended)</Text>
      </div>
    );
  }

  export default App;
  ```
</LiveCode>

## Behavior

The Icon responds to different size and color requirements while maintaining consistent visual representation.

## Usage Guidelines

Use the Icon to enhance the understanding of a concept or in places where space is a premium.

### When to Use

Icons enhance the understanding of a concept. They also work well in places where space is a premium.

### When not to use

Avoid using Icons for the sake of having icons. Most icons have ambiguous meaning and result in confusion and an overwhelming visual design.

### How to Use

#### Provide a label for Icons

An Icon's label takes two forms: as a text label next to an icon, or as a [Tooltip](/docs/web/components/tooltip/design). A text label is generally preferred as most icons do not have an obvious meaning.

<LiveCode example="icon-label-obvious-text-do" screenshot fullWidth>
  ```tsx lines theme={null}
  import { Button } from "@servicetitan/anvil2";
  import Edit from "@servicetitan/anvil2/assets/icons/material/round/edit.svg";

  function App() {
    return (
      <Button icon={Edit} appearance="ghost">
        Edit
      </Button>
    );
  }

  export default App;
  ```
</LiveCode>

<Check>**Do**</Check>

<LiveCode example="icon-label-obvious-tooltip-do" screenshot fullWidth>
  ```tsx lines theme={null}
  import { Button, Tooltip } from "@servicetitan/anvil2";
  import Edit from "@servicetitan/anvil2/assets/icons/material/round/edit.svg";

  function App() {
    return (
      <div style={{ paddingBlockStart: "2.5rem" }}>
        <Tooltip open>
          <Tooltip.Trigger>
            <Button icon={Edit} appearance="ghost" />
          </Tooltip.Trigger>
          <Tooltip.Content>Edit</Tooltip.Content>
        </Tooltip>
      </div>
    );
  }

  export default App;
  ```
</LiveCode>

<Check>**Do**</Check>

<LiveCode example="icon-label-nonobvious-text-do" screenshot fullWidth>
  ```tsx lines theme={null}
  import { Button } from "@servicetitan/anvil2";
  import AddCircle from "@servicetitan/anvil2/assets/icons/material/round/add_circle.svg";

  function App() {
    return (
      <Button icon={AddCircle} appearance="ghost">
        Add Widget
      </Button>
    );
  }

  export default App;
  ```
</LiveCode>

<Check>**Do**</Check>

Labels can clarify what the icon is trying to represent.

<LiveCode example="icon-label-nonobvious-tooltip-caution" screenshot fullWidth>
  ```tsx lines theme={null}
  import { Button, Tooltip } from "@servicetitan/anvil2";
  import AddCircle from "@servicetitan/anvil2/assets/icons/material/round/add_circle.svg";

  function App() {
    return (
      <div style={{ paddingBlockStart: "2.5rem", paddingInline: "2rem" }}>
        <Tooltip open>
          <Tooltip.Trigger>
            <Button icon={AddCircle} appearance="ghost" />
          </Tooltip.Trigger>
          <Tooltip.Content>Add Widget</Tooltip.Content>
        </Tooltip>
      </div>
    );
  }

  export default App;
  ```
</LiveCode>

<Warning>**Caution**</Warning>

More ambiguous actions are less discoverable when only providing a Tooltip.

#### Provide information without action

Icon provides indication for users and can be focused or hovered to convey more details. In these use cases, add `tabIndex={0}` to make icon focusable and use Tooltip with it.

<LiveCode example="icon-tabindex-do" screenshot fullWidth>
  ```tsx lines theme={null}
  import { Icon, Tooltip } from "@servicetitan/anvil2";
  import Warning from "@servicetitan/anvil2/assets/icons/material/round/warning.svg";

  function App() {
    return (
      <div style={{ paddingBlockStart: "2.5rem", paddingInline: "4rem" }}>
        <Tooltip>
          <Tooltip.Trigger>
            <Icon svg={Warning} tabIndex={0} />
          </Tooltip.Trigger>
          <Tooltip.Content>Hello, I&apos;m a tooltip</Tooltip.Content>
        </Tooltip>
      </div>
    );
  }

  export default App;
  ```
</LiveCode>

#### Consistent icon usage

Consistent icon usage of status and actions brings familiarity. Use the standard that a product has adopted.

<LiveCode example="icon-consistent-dont" screenshot fullWidth>
  ```tsx lines theme={null}
  import { Button } from "@servicetitan/anvil2";
  import Add from "@servicetitan/anvil2/assets/icons/material/round/add.svg";
  import AddCircle from "@servicetitan/anvil2/assets/icons/material/round/add_circle.svg";

  function App() {
    return (
      <span>
        <Button icon={Add} appearance="ghost">
          Add Object
        </Button>
        <Button icon={AddCircle} appearance="ghost">
          Add Thing
        </Button>
      </span>
    );
  }

  export default App;
  ```
</LiveCode>

<Danger>**Don't**</Danger>

#### Use semantic token colors for Icons

When using color for Icons, use a semantic token value. This ensures an icon is both themeable and internally consistent with other UI's color usage.

#### Avoid custom icon resizing

Icons have a consistent set of dimensions. Resizing breaks the internal consistency and creates awkward vector scaling.

## Content

Content within the Icon should be clear and recognizable, helping users understand the concept being represented.

## Keyboard Interaction

Users can navigate the Icon using standard keyboard controls.

### Accessibility

#### Non-interactive Icons

Pair Icons with a text label when possible.

When using an Icon without text, provide an `aria-label` to the Icon directly, describing what the icon is.

For more guidance on icon accessibility, see [accessible icon usage best practices](/docs/accessibility/media-and-animation#alt-tags-vs-decorative-images).
