---
title: Notch for Astro
description: "Set a label or action into the corner of a card or image. The notch fits its content."
seo:
    title: Notch for Astro | Card and Image Cutouts
related:
    - /components/card
    - /blocks/features
sidebar:
    label: "Notch"
---

```astro
---
import { Image } from "astro:assets"
import { ShoppingBag } from "@lucide/astro"

import robot from "@/assets/wizard/robot.png"
import { Button } from "@/components/ui/button"
import {
  Card,
  CardAction,
  CardDescription,
  CardFooter,
  CardHeader,
} from "@/components/ui/card"
import {
  Dialog,
  DialogContent,
  DialogDescription,
  DialogHeader,
  DialogTitle,
  DialogTrigger,
} from "@/components/ui/dialog"
import { Notch } from "@/components/ui/notch"
---

<Card as="article" size="sm" class="mx-auto w-full max-w-sm rounded-2xl">
  <Image
    src={robot}
    alt="A small silver robot with black oval eyes on a pale blue background."
    widths={[384, 768]}
    sizes="(max-width: 420px) 90vw, 384px"
    class="h-auto w-full outline-1 -outline-offset-1 outline-black/10 dark:outline-white/10"
  />
  <Notch class="bg-card text-sm leading-none font-semibold">New</Notch>
  <CardHeader>
    <h3 class="font-heading text-xl leading-tight font-semibold">
      Pocket Robot
    </h3>
    <CardDescription>
      A palm-sized 3D robot companion for your sci-fi game.
    </CardDescription>
    <CardAction class="text-base leading-tight font-semibold tabular-nums">
      $12
    </CardAction>
  </CardHeader>
  <CardFooter class="pt-0">
    <Dialog class="w-full">
      <DialogTrigger
        class="w-full motion-safe:active:scale-[0.96]"
        aria-label="Purchase asset, Pocket Robot for 12 dollars"
      >
        <ShoppingBag aria-hidden="true" />
        Purchase asset
      </DialogTrigger>
      <DialogContent class="sm:max-w-sm">
        <DialogHeader>
          <DialogTitle>Pocket Robot</DialogTitle>
          <DialogDescription>
            This is a sample purchase. Download a preview of the 3D model.
          </DialogDescription>
        </DialogHeader>
        <Button as="a" href={robot.src} download="pocket-robot.png">
          Download preview PNG
        </Button>
      </DialogContent>
    </Dialog>
  </CardFooter>
</Card>
```

## Installation

### Command

```sh
bunx --bun shadcn@latest add @gnostic/notch
```

### Manual

Complete the [Installation guide](/docs/installation) first. Then copy the component files below.

No extra packages are required.

#### src/components/ui/notch/notch.astro

```astro
---
import type { HTMLTag, Polymorphic } from "astro/types"
import { cn } from "cn"

import type { NotchProps } from "./types.ts"

type Props<Tag extends HTMLTag = "div"> = Polymorphic<{ as: Tag }> & NotchProps

const {
  as: Tag = "div",
  corner = "top-left",
  class: className,
  ...props
} = Astro.props

const positions = {
  "top-left":
    "top-0 left-0 rounded-br-(--notch-curve) before:top-0 before:left-full after:top-full after:left-0",
  "top-right":
    "top-0 right-0 rounded-bl-(--notch-curve) before:top-0 before:right-full after:top-full after:right-0",
  "bottom-left":
    "bottom-0 left-0 rounded-tr-(--notch-curve) before:bottom-0 before:left-full after:bottom-full after:left-0",
  "bottom-right":
    "bottom-0 right-0 rounded-tl-(--notch-curve) before:bottom-0 before:right-full after:bottom-full after:right-0",
}
---

<Tag
  data-slot="notch"
  data-corner={corner}
  class={cn(
    "absolute z-10 inline-flex max-w-full items-center justify-center gap-2 bg-background px-4 py-2 text-center wrap-anywhere",
    positions[corner],
    className,
  )}
  {...props}
>
  <slot />
</Tag>

<style>
  [data-slot="notch"] {
    --notch-curve: var(--notch-radius, var(--radius-2xl));
    --notch-x: 100%;
    --notch-y: 100%;
  }

  [data-corner$="-right"] {
    --notch-x: 0%;
  }
  [data-corner^="bottom-"] {
    --notch-y: 0%;
  }

  [data-slot="notch"]::before,
  [data-slot="notch"]::after {
    content: "";
    position: absolute;
    width: var(--notch-curve);
    height: var(--notch-curve);
    background-color: inherit;
    pointer-events: none;
    mask: radial-gradient(
      circle at var(--notch-x) var(--notch-y),
      transparent calc(var(--notch-curve) - 0.5px),
      black var(--notch-curve)
    );
  }
</style>
```

#### src/components/ui/notch/index.ts

```ts
export { default as Notch } from './notch.astro'

export type { NotchProps } from './types.ts'
```

#### src/components/ui/notch/types.ts

```ts
/** Props for a content-sized corner inset. */
export interface NotchProps {
    /**
     * Corner of the positioned parent that holds the slot content.
     *
     * @default "top-left"
     */
    corner?: 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right'
}
```

Component classes use the preset configured during project setup. Select the same preset in the docs before copying Manual source. To change installed component classes, edit or reinstall their source. See [Theming](/docs/theming) for details.


## Usage

```astro
---
import { Card } from "@/components/ui/card"
import { Notch } from "@/components/ui/notch"
---

<Card as="article" class="rounded-2xl p-6 pt-12">
  <Notch class="text-sm font-medium">Featured</Notch>
  <h3>Project brief</h3>
</Card>
```

Put `Notch` inside a positioned parent. `Card` already has `position: relative`. For an image, put the image and its notches in a wrapper with `class="relative rounded-2xl"`. Set `rounded-[inherit]` on the image. Leave overflow visible on the wrapper so the notch covers the image edge.

Put text, an icon, or a link in the default slot. The content and padding set the notch size. Use padding utilities to adjust the space around the content. Leave room for the notch when you place other content near the same corner.

## Image with two notches

Place one `Notch` in each corner that needs a label or action. Both are children of the same figure.

```astro
---
import { Image } from "astro:assets"
import { ArrowUpRight } from "@lucide/astro"

import landscape from "@/assets/images/winter-landscape-orion.png"
import { Notch } from "@/components/ui/notch"
---

<figure class="relative isolate mx-auto w-full max-w-xl rounded-2xl">
  <Notch as="figcaption" class="text-sm font-semibold">
    Winter on Orion
  </Notch>
  <Image
    src={landscape}
    alt="A traveler crosses a snowy plain toward a mountain beneath a pink sun."
    widths={[576, 1152]}
    sizes="(max-width: 640px) 90vw, 576px"
    class="aspect-4/3 w-full rounded-[inherit] object-cover"
  />
  <Notch
    as="a"
    href={landscape.src}
    corner="bottom-right"
    class="text-sm font-medium underline-offset-4 hover:underline focus-visible:outline-2 focus-visible:outline-ring focus-visible:-outline-offset-2"
  >
    View full image
    <ArrowUpRight aria-hidden="true" class="size-4" />
  </Notch>
</figure>
```

## Theme and layout

The notch uses `bg-background` to blend into the surrounding surface. Use `bg-card` for a card-colored inset or another solid background utility to match your layout. All three curves use `--radius-2xl` by default. For a host with `rounded-xl`, set `[--notch-radius:var(--radius-xl)]` on the host to match its radius.

## API reference

<AutoTypeTable
    path="../../packages/ui/src/components/ui/notch/types.ts"
    name="NotchProps"
/>

Read the [installed source](/ui/r/notch.json) for the complete component.
