# CloseButton **Category**: react **URL**: https://www.heroui.com/docs/react/components/close-button **Source**: https://raw.githubusercontent.com/heroui-inc/heroui/refs/heads/v3/apps/docs/content/docs/react/components/(buttons)/close-button.mdx > Button component for closing dialogs, modals, or dismissing content *** ## Import ```tsx import { CloseButton } from "@heroui/react"; ``` ### Usage ```tsx import {CloseButton} from "@heroui/react"; export function Default() { return ; } ``` ### With Custom Icon ```tsx import {CircleXmark, Xmark} from "@gravity-ui/icons"; import {CloseButton} from "@heroui/react"; export function WithCustomIcon() { return (
Custom Icon
Alternative Icon
); } ``` ### Interactive ```tsx "use client"; import {CloseButton} from "@heroui/react"; import {useState} from "react"; export function Interactive() { const [count, setCount] = useState(0); return (
setCount(count + 1)} /> Clicked: {count} times
); } ``` ## Related Components - **Alert**: Display important messages and notifications - **AlertDialog**: Critical confirmations requiring user attention - **Chip**: Compact elements for tags and filters ## Styling ### Passing Tailwind CSS classes ```tsx import {CloseButton} from "@heroui/react"; function CustomCloseButton() { return Close; } ``` ### Customizing the component classes To customize the CloseButton component classes, you can use the `@layer components` directive.
[Learn more](https://tailwindcss.com/docs/adding-custom-styles#adding-component-classes). ```css @layer components { .close-button { @apply bg-red-100 text-red-800 hover:bg-red-200; } .close-button--custom { @apply rounded-full border-2 border-red-300; } } ``` HeroUI follows the [BEM](https://getbem.com/) methodology to ensure component variants and states are reusable and easy to customize. ### CSS Classes The CloseButton component uses these CSS classes ([View source styles](https://github.com/heroui-inc/heroui/blob/v3/packages/styles/components/close-button.css)): #### Base Classes - `.close-button` - Base component styles #### Variant Classes - `.close-button--default` - Default variant ### Interactive States The component supports both CSS pseudo-classes and data attributes for flexibility: - **Hover**: `:hover` or `[data-hovered="true"]` - **Active/Pressed**: `:active` or `[data-pressed="true"]` - **Focus**: `:focus-visible` or `[data-focus-visible="true"]` - **Disabled**: `:disabled` or `[aria-disabled="true"]` ## API Reference ### CloseButton Props | Prop | Type | Default | Description | | ---------- | ----------------------- | ----------- | ----------- | | `variant` | `"default"` | `"default"` | Visual variant of the button | | `children` | `ReactNode \| function` | `` | Content to display (defaults to close icon) | | `onPress` | `() => void` | - | Handler called when the button is pressed | | `isDisabled` | `boolean` | `false` | Whether the button is disabled | ### React Aria Button Props CloseButton extends all React Aria Button props. Common props include: | Prop | Type | Description | | ----------------- | --------- | ----------- | | `aria-label` | `string` | Accessible label for screen readers | | `aria-labelledby` | `string` | ID of element that labels the button | | `aria-describedby`| `string` | ID of element that describes the button | ### RenderProps When using the render prop pattern, these values are provided: | Prop | Type | Description | | ------------- | --------- | ----------- | | `isHovered` | `boolean` | Whether the button is hovered | | `isPressed` | `boolean` | Whether the button is pressed | | `isFocused` | `boolean` | Whether the button is focused | | `isDisabled` | `boolean` | Whether the button is disabled |