# Card

> A versatile card component for displaying titled content blocks, optionally linked and with images.

The Card component displays content in a contained, titled block. When an `href`
is provided the entire card renders as an `<a>` element, making the whole
surface clickable. Without `href`, it renders as a `<div>`.

```astro
---
import Card from "astro-theme-university/components/Card.astro";
---
```

## Props

<PropsTable component="components/Card" />

The component also accepts a default slot for body content below the title, and
a named `actions` slot for a control that does something other than follow the
card's link.

## Examples

<Example label="Basic card">
  <Card title="Getting started">
    <p>Learn how to install and configure the theme for your project.</p>
  </Card>
</Example>

<Example label="Linked card">
  <Card title="View the source" href="https://github.com">
    <p>Cards with an href prop become fully clickable links.</p>
  </Card>
</Example>

<Example label="Card with description">
  <Card title="Accessibility">
    <p>
      All components are built with semantic HTML and tested against WCAG
      guidelines. Colour contrast ratios meet AA standards in both light and
      dark modes.
    </p>
  </Card>
</Example>

<Example label="Card with an action">
  <Card title="Deployed prototype" href="https://example.com">
    <button slot="actions" type="button">
      QR
    </button>
    <p>The action sits in the top corner, above the card's link.</p>
  </Card>
</Example>

## Actions

A card can carry a control that isn't the card's link --- a copy button, a QR
toggle, a dismiss. Put it in the `actions` slot and it renders as a badge in the
card's top corner.

```astro
<Card title="Deployed prototype" href={url}>
  <button slot="actions" type="button" aria-label="Show QR code">…</button>
  <p>Card body.</p>
</Card>
```

Filling the slot changes how a linked card is marked up. Normally the whole card
is one `<a>`, which can't contain a button; with actions, the anchor shrinks to
the title and stretches back over the card through a `::after` overlay. The card
stays clickable end to end, the action stays clickable in its corner, and the
link's accessible name becomes the title alone rather than every word on the
card. A card without an `href` is unaffected either way.

Style the slot's contents yourself --- the theme positions the badge and stacks
it above the overlay but doesn't dictate how a control inside it looks.

## Notes

When using the `image` prop, provide meaningful `imageAlt` text if the image
conveys information. When `imageAlt` is omitted the card's `title` is used as
the alt text, which suits an image that illustrates its subject; pass `""` to
mark a purely decorative image.

The `image` prop also accepts a `RemoteImage` object
(`{ src, width?, height?, srcset?, sizes? }`) for a pre-encoded external source
--- a CDN or object-store URL --- rendered as a plain `<img>` with no build-time
processing. Supply `srcset` (and per-image `sizes` if the default doesn't fit)
for responsive variants you've encoded yourself; the card's CSS aspect ratio
handles layout either way.

Cards inside a [CardGrid](https://anucybernetics.github.io/astro-theme-university/docs/components/card-grid/) use
[CSS subgrid](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_grid_layout/Subgrid)
to align their image and body rows across the grid row, keeping cards aligned
when titles or body text vary in length.
