Veil UI
Components

Icon Button

A square button for a single icon. Requires an accessible label.

Installation

$ npx veil-ui@latest add icon-button

Usage

import { IconButton } from "@/components/ui/icon-button";
import { Plus } from "lucide-react";

<IconButton aria-label="Add item">
  <Plus />
</IconButton>;

Examples

Basic

Variants

Sizes

Composition

asChild forwards the styling and props to a single child, so the same visual result can be applied to a link.

API reference

PropTypeDefaultDescription
variant"default" | "secondary" | "outline" | "ghost" | "destructive""default"Visual style of the button.
size"sm" | "default" | "lg""default"Square control size: 32px, 36px or 40px.
aria-labelstring—Required accessible name. The icon itself is decorative.
asChildbooleanfalseRender the child element instead of a button.
...propsReact.ComponentProps<"button">—All native button attributes except aria-label.

Accessibility

  • aria-label is required at the type level, so an icon-only button cannot ship without a name.
  • Icons inherit currentColor and are sized to match the button.
  • Disabled buttons use pointer-events: none and opacity: 50%.

Vue and plain HTML

This component also ships for Vue (Reka UI) and plain HTML. Install it with npx veil-ui add icon-button --framework vue or switch the framework in components.json.

<script setup lang="ts">
import { Primitive } from "reka-ui";
import { computed } from "vue";

import { cn } from "@/lib/utils";

import { iconButtonVariants, type IconButtonVariants } from "./variants";

defineOptions({ inheritAttrs: false });

const props = withDefaults(
  defineProps<{
    variant?: IconButtonVariants["variant"];
    size?: IconButtonVariants["size"];
    asChild?: boolean;
    class?: string;
  }>(),
  { variant: "default", size: "default", asChild: false },
);

const classes = computed(() =>
  cn(iconButtonVariants({ variant: props.variant, size: props.size }), props.class),
);
</script>

<template>
  <Primitive
    v-if="asChild"
    as-child
    data-slot="icon-button"
    :data-variant="variant"
    :data-size="size"
    :class="classes"
    v-bind="$attrs"
  >
    <slot />
  </Primitive>
  <button
    v-else
    data-slot="icon-button"
    :data-variant="variant"
    :data-size="size"
    :class="classes"
    v-bind="$attrs"
  >
    <slot />
  </button>
</template>

On this page