<!-- generated by scripts/gen-docs.mjs from docs/system/media-tile.md. Edit the source and rerun. -->
# MediaTile

## Description
Shows a thing by its picture first: a room, a venue, an event, a listing. A square photo, then its name and a line or two about it, straight on the page, and the whole tile is one link.

`import { MediaTile, MediaTileMedia, MediaTileTitle, MediaTileMeta } from "@/components/cobalt/ui/media-tile"`, source `registry/cobalt/ui/media-tile.tsx`, status `ready`.
Foundation: `hand-rolled`. Traps checked: `trap/link-as-button`, `trap/focus-ring-shape`, `trap/text-measure`, `trap/illustration-announced`, `trap/touch-hover-flash`, `trap/loading-layout-shift`, `trap/surface-double-edge`, `trap/motion-frequent`.

`trap/link-as-button` is answered by the title's link, stretched over the tile, so the tile is one real anchor and the overlay action is a separate button beside it, never inside it (Rules). `trap/focus-ring-shape` by the outline drawn on the stretched box, around the whole tile with its 16px corner, not around the words (States). `trap/text-measure` by the title cut at two lines with its whole text in `title`, and each meta line cut at one (Limits). `trap/illustration-announced` by the empty `alt` the photo takes when the title names it (Rules). `trap/touch-hover-flash` by Tailwind's `(hover: hover)` guard on the dim (States). `trap/loading-layout-shift` by the square box, which holds its size before the photo arrives, and by `Skeleton` lines at the text's height (Examples). `trap/surface-double-edge` by the hairline inside the photo, the only edge the tile has. `trap/motion-frequent` by the dim, a filter change at `--t-press` and nothing that moves (Motion).

### Foundation
Not applicable: hand-rolled.

| Given by the foundation | Added by the team |
|---|---|
| Not applicable: hand-rolled, with Base UI `useRender` for the title's level | An `article` with the photo, the title and the meta lines; the photo square, 16px round (D38), with `image-outline` and the `--muted` fill while it loads; the photo dims to 95 percent brightness under the pointer, and nothing scales (D36); the title's link stretched over the tile through its `::after`, with `data-focus="custom"` so the outline is drawn there; the title cut at two lines, balanced, with its text in the system tooltip, taking the room a stretched tile has over (`mb-auto`), so in a grid row, where tiles stretch to the tallest, the meta lines sit at the foot and line up even when one title wraps (they sat one line lower under a wrapped title before, and a row of one-line titles keeps no gap), and `select-none`, since it is the tile's link, a target to press, so a double press selects no word of it ("night", "Welcome" before); meta lines muted, cut at one, with tabular figures; `renderLink` for a router (D19) |

## Examples
Events as tiles with the photo first, one link per tile and a bookmark on each photo.

Real uses, 0 call sites (`rg -n "<MediaTile\b" app registry --glob '!registry/cobalt/ui/*'`): the part is new. The first source app draws its event tiles this way (`docs/research/2026-10-17-bespoke-sources.md`, section 2.2).

### Example files
| File | Covers | Caption |
|---|---|---|
| `docs/system/examples/media-tile/default.tsx` | default | Events as tiles with the photo first, one link per tile and a bookmark on each photo |
| `docs/system/examples/media-tile/state-loading.tsx` | state:loading | While the events load, each tile keeps its size, a grey square and lines where the words will go |
| `docs/system/examples/media-tile/default.tsx` | composition:SaveToggle | The overlay bookmark on each photo, pressable apart from the tile's link |

Example: Events as tiles with the photo first, one link per tile and a bookmark on each photo (`docs/system/examples/media-tile/default.tsx`)

```tsx
import { toast } from "sonner";

import { SaveToggle } from "@/components/cobalt/ui/save-toggle";
import { MediaTile, MediaTileMedia, MediaTileMeta, MediaTileTitle } from "@/components/cobalt/ui/media-tile";
import { useOptimisticToggle } from "@/lib/cobalt/use-optimistic-toggle";

const events = [
  { id: "film", name: "Film night", when: "Thu, Oct 22, 7:30 PM", where: "Screening room, Arts building", src: "/photos/film-night.webp" },
  { id: "gala", name: "Winter gala dinner", when: "Sat, Dec 5, 7:00 PM", where: "Great Hall", src: "/photos/gala-dinner.webp" },
  { id: "speaker", name: "Speaker night: a career in public policy", when: "Tue, Oct 27, 6:00 PM", where: "Lecture theatre 2", src: "/photos/speaker-night.webp" },
  { id: "mixer", name: "Welcome mixer", when: "Fri, Oct 23, 5:00 PM", where: "Student union, first floor", src: "/photos/welcome-mixer.webp" },
  { id: "fjord", name: "Fjord walk", when: "Sun, Oct 25, 9:00 AM", where: "Meet at the harbour car park", src: "/photos/fjord-walk.jpg" },
  { id: "football", name: "Five-a-side football", when: "Wed, Oct 28, 6:30 PM", where: "Sports hall courts", src: "/photos/football.jpg" },
];

// Stands in for your API call. It answers after 600ms, and fails while the browser is offline or the
// address has ?network=offline.
const request = () =>
  new Promise<void>((resolve, reject) =>
    setTimeout(() => {
      const offline = !navigator.onLine || new URLSearchParams(location.search).get("network") === "offline";
      if (offline) reject(new Error("offline"));
      else resolve();
    }, 600),
  );

function EventTile({ event }: { event: (typeof events)[number] }) {
  const saved = useOptimisticToggle(`saved:${event.id}`, event.id === "gala", {
    send: request,
    // Keyed by the item, so a second refusal before the first toast goes says it once.
    onRefused: (on) =>
      toast(on ? `Could not save ${event.name}` : `Could not remove ${event.name} from saved`, {
        id: `saved:${event.id}`,
        description: "Check your connection and try again.",
      }),
  });
  return (
    <MediaTile>
      <MediaTileMedia>
        <img src={event.src} alt="" width={800} height={800} loading="lazy" decoding="async" />
        <SaveToggle variant="overlay" pressed={saved.on} onPressedChange={saved.flip} label={`Save ${event.name}`} />
      </MediaTileMedia>
      <MediaTileTitle href={`#${event.id}`}>{event.name}</MediaTileTitle>
      <MediaTileMeta>{event.when}</MediaTileMeta>
      <MediaTileMeta>{event.where}</MediaTileMeta>
    </MediaTile>
  );
}

export default function Example() {
  return (
    <div className="grid w-full grid-cols-2 gap-x-4 gap-y-6 sm:grid-cols-3">
      {events.map((event) => (
        <EventTile key={event.id} event={event} />
      ))}
    </div>
  );
}
```

Example: The overlay bookmark on each photo, pressable apart from the tile's link (`docs/system/examples/media-tile/default.tsx`)

```tsx
import { toast } from "sonner";

import { SaveToggle } from "@/components/cobalt/ui/save-toggle";
import { MediaTile, MediaTileMedia, MediaTileMeta, MediaTileTitle } from "@/components/cobalt/ui/media-tile";
import { useOptimisticToggle } from "@/lib/cobalt/use-optimistic-toggle";

const events = [
  { id: "film", name: "Film night", when: "Thu, Oct 22, 7:30 PM", where: "Screening room, Arts building", src: "/photos/film-night.webp" },
  { id: "gala", name: "Winter gala dinner", when: "Sat, Dec 5, 7:00 PM", where: "Great Hall", src: "/photos/gala-dinner.webp" },
  { id: "speaker", name: "Speaker night: a career in public policy", when: "Tue, Oct 27, 6:00 PM", where: "Lecture theatre 2", src: "/photos/speaker-night.webp" },
  { id: "mixer", name: "Welcome mixer", when: "Fri, Oct 23, 5:00 PM", where: "Student union, first floor", src: "/photos/welcome-mixer.webp" },
  { id: "fjord", name: "Fjord walk", when: "Sun, Oct 25, 9:00 AM", where: "Meet at the harbour car park", src: "/photos/fjord-walk.jpg" },
  { id: "football", name: "Five-a-side football", when: "Wed, Oct 28, 6:30 PM", where: "Sports hall courts", src: "/photos/football.jpg" },
];

// Stands in for your API call. It answers after 600ms, and fails while the browser is offline or the
// address has ?network=offline.
const request = () =>
  new Promise<void>((resolve, reject) =>
    setTimeout(() => {
      const offline = !navigator.onLine || new URLSearchParams(location.search).get("network") === "offline";
      if (offline) reject(new Error("offline"));
      else resolve();
    }, 600),
  );

function EventTile({ event }: { event: (typeof events)[number] }) {
  const saved = useOptimisticToggle(`saved:${event.id}`, event.id === "gala", {
    send: request,
    // Keyed by the item, so a second refusal before the first toast goes says it once.
    onRefused: (on) =>
      toast(on ? `Could not save ${event.name}` : `Could not remove ${event.name} from saved`, {
        id: `saved:${event.id}`,
        description: "Check your connection and try again.",
      }),
  });
  return (
    <MediaTile>
      <MediaTileMedia>
        <img src={event.src} alt="" width={800} height={800} loading="lazy" decoding="async" />
        <SaveToggle variant="overlay" pressed={saved.on} onPressedChange={saved.flip} label={`Save ${event.name}`} />
      </MediaTileMedia>
      <MediaTileTitle href={`#${event.id}`}>{event.name}</MediaTileTitle>
      <MediaTileMeta>{event.when}</MediaTileMeta>
      <MediaTileMeta>{event.where}</MediaTileMeta>
    </MediaTile>
  );
}

export default function Example() {
  return (
    <div className="grid w-full grid-cols-2 gap-x-4 gap-y-6 sm:grid-cols-3">
      {events.map((event) => (
        <EventTile key={event.id} event={event} />
      ))}
    </div>
  );
}
```

## Variants
Not applicable: one shape. The grid around the tiles is the host's, and an overlay action is a child of `MediaTileMedia`.

## States
| State | Trigger | What the user can do | Shown by, besides color | Checked by |
|---|---|---|---|---|
| rest | rendered | open the thing, or use the overlay action | the photo, the title and its meta | test |
| hover | pointer over the tile, under `(hover: hover)` | open it | the photo dims a step, and the pointer cursor | by hand |
| focus-visible | Tab onto the title's link | open it with Enter | the 2px outline around the whole tile, on its 16px corner | by hand |
| loading | the host leaves `MediaTileMedia` empty and puts `Skeleton` lines in the text | wait | the grey square and the bars, at the size the content will take | by hand |
| cut | the title runs past two lines | hover or long-press for the whole title | an ellipsis on the second line, and the whole text in the tooltip | test |
| wrapped-in-a-row | a title in a grid row wraps to two lines and its neighbours' do not | read | every tile's meta lines start at the same height in the row, measured at 390 with "Speaker night: a career in public policy" beside "Welcome mixer"; a row with no wrapped title has no gap | test |

Example: While the events load, each tile keeps its size, a grey square and lines where the words will go (`docs/system/examples/media-tile/state-loading.tsx`)

```tsx
import { MediaTile, MediaTileMedia, MediaTileMeta } from "@/components/cobalt/ui/media-tile";
import { Skeleton } from "@/components/cobalt/ui/skeleton";

export default function Example() {
  return (
    // Four tiles fill two rows of two in a narrow column and one row of four in a wide one, so no
    // tile waits alone on a row. The grid follows its own box, not the window.
    <div aria-busy="true" aria-label="Events" className="@container w-full">
      <div className="grid grid-cols-2 gap-x-4 gap-y-6 @xl:grid-cols-4">
        {[0, 1, 2, 3].map((i) => (
          <MediaTile key={i}>
            <MediaTileMedia />
            <p className="font-medium">
              <Skeleton className="w-3/4" />
            </p>
            <MediaTileMeta>
              <Skeleton className="w-1/2" />
            </MediaTileMeta>
            <MediaTileMeta>
              <Skeleton className="w-2/5" />
            </MediaTileMeta>
          </MediaTile>
        ))}
      </div>
    </div>
  );
}
```

### State precedence
- Hover and focus-visible: both show. The dim is on the photo and the outline around the tile.
- Loading and hover: Not applicable: a loading tile has no link to hover.
- Cut and every other state: both show. The ellipsis is on the title.
- Wrapped-in-a-row and cut: both show. A cut title is two lines, the tallest a title gets, and its neighbours' meta lines line up with its own.

### Motion
| Trigger | Kind | Preset | Properties | Reduced motion |
|---|---|---|---|---|
| pointer over and out | input | `--t-press` on `--curve` | filter, the photo's brightness | the same; a brightness change moves nothing |

## Props

<!-- Props generated from registry/cobalt/ui/media-tile.tsx with TypeScript by scripts/props-table.mjs -->
### MediaTile

No props of its own.

Also accepts every native HTML attribute.

### MediaTileMedia

No props of its own.

Also accepts every native `<div>` attribute.

### MediaTileTitle

| Prop | Type | Default | Purpose |
|---|---|---|---|
| `children` | `string` |  |  |
| `href` | `string` |  |  |
| `className?` | `string` |  |  |
| `lines?` | `1 \| 2` | `2` | How many lines the name may take before it is cut. |
| `render?` | `RenderProp<Record<string, unknown>>` |  |  |
| `renderLink?` | `RenderLink` | `defaultLink` |  |

### MediaTileMeta

No props of its own.

Also accepts every native `<p>` attribute.

`MediaTileTitle` takes `href`, its text as `children`, `renderLink` for a router, `lines` (2 by default, 1 for short names such as places) and `render` for its heading level, an `h3` by default. `MediaTile`, `MediaTileMedia` and `MediaTileMeta` take their native element's attributes; `className` is for placement.

## Usage

### When to use
- A list where the picture is how a person chooses: rooms, venues, listings, events.
- Search results for things people recognise by sight.

### When not to use
- The list is read by name and compared by figures. Use Item instead, or Table.
- The thing has no picture of its own. Use Item instead; a tile with a placeholder in every square is a list pretending to be a gallery.
- A record's details in a side column. Use Card instead.

### Rules
- `rule/media-tile-one-link`: When a tile opens its thing, let `MediaTileTitle` be the only link, with `href`, and keep any other action an overlay button inside `MediaTileMedia`, instead of a link wrapped around the tile, because a link around the tile would hold the overlay button inside a link, two actions in one place. Evidence: principle wcag: 4.1.2 Name, role, value, nested interactive content has no reliable role; single use docs/system/examples/media-tile/default.tsx:44. Check: test `media-tile.test.tsx` renders one anchor per tile.
  - Don't: `<a href="/rooms/harbour"><MediaTile>...<SaveToggle ... /></MediaTile></a>`
  - Do: `<MediaTile><MediaTileMedia><img src={src} alt="" /><SaveToggle variant="overlay" ... /></MediaTileMedia><MediaTileTitle href="/rooms/harbour">Harbour room</MediaTileTitle></MediaTile>`
- `rule/media-tile-photo-alt`: When the title names what the photo shows, give the `img` an empty `alt`, instead of repeating the name, because the tile's link is read with its title and a second "Harbour room" before it is noise. Evidence: principle wcag: 1.1.1 Non-text content, a decorative image takes an empty alt. Check: review.
  - Don't: `<img src={src} alt="Harbour room" />`
  - Do: `<img src={src} alt="" />`
- `rule/media-tile-one-grid`: When tiles fall into groups such as days or floors, lay them in one grid for the whole list, `grid-cols-2 gap-x-4 gap-y-6 sm:grid-cols-3`, instead of one grid per group, because a group with 1 tile leaves 2 empty columns beside it. Evidence: single use docs/system/examples/media-tile/default.tsx:53; principle heuristic: aesthetic and minimalist design, a group of one leaves two empty columns. Check: review.
  - Don't: `{days.map((d) => <div className="grid grid-cols-3">{d.rooms.map(...)}</div>)}`
  - Do: `<div className="grid grid-cols-2 gap-x-4 gap-y-6 sm:grid-cols-3">{rooms.map(...)}</div>`

### Content
- `rule/media-tile-meta-one-fact`: When writing `MediaTileMeta`, put one fact on each line, such as the seats or when it is free, in at most 2 lines, instead of a sentence, because each line is cut at one line and the second fact of a sentence is the one that is lost. Evidence: measured a meta line cut at 112px in a 2-column grid at a 320px screen, docs/system/stress/media-tile.tsx; principle heuristic: recognition rather than recall. Check: review.
  - Don't: `<MediaTileMeta>Seats 12 on the second floor and is free from 2:00 PM today</MediaTileMeta>`
  - Do: `<MediaTileMeta>Seats 12, second floor</MediaTileMeta><MediaTileMeta>Free from 2:00 PM</MediaTileMeta>`

### Anti-slop
- `rule/media-tile-no-lift`: When a tile is hovered, let the photo dim as it does, instead of a scale, a lift or a shadow through `className`, because tiles are scanned many at a time and the system never scales. Evidence: person D36; person D11. Check: lint rule/component-override (scripts/check-system.mjs).
  - Don't: `<MediaTile className="hover:-translate-y-1 hover:shadow-lg">`
  - Do: `<MediaTile>`

### Limits
- `rule/media-tile-title-length`: When titles run past 50 characters, put the short name in `MediaTileTitle` and the rest in a `MediaTileMeta` line, because the title is cut at two lines and on a 320px screen a tile in a 2-column grid is 112px wide, about 16 characters a line at 14px. Evidence: measured 112px tiles and 40px two-line titles in a 2-column grid at a 320px screen, docs/system/stress/media-tile.tsx. Check: probe docs/system/stress/media-tile.tsx on the break-ui harness at 320.
  - Don't: `<MediaTileTitle href={href}>Studio 4 with a ceiling projector, a whiteboard wall and a view over the courtyard</MediaTileTitle>`
  - Do: `<MediaTileTitle href={href}>Studio 4</MediaTileTitle><MediaTileMeta>Projector and whiteboard wall</MediaTileMeta>`

## Accessibility
Rests on an `article`, the host's `img`, and the anchor `renderLink` returns.

### Keyboard
| Key | Where focus is | Effect | Focus after | Checked by |
|---|---|---|---|---|
| Tab | before the tile | focuses the overlay action first, then the title's link | the action, then the link | by hand |
| Enter | the title's link | opens the thing | the destination | by hand |

### ARIA
| Part | Role | Accessible name from | States and properties | Announced | Checked by |
|---|---|---|---|---|---|
| tile | article | none | none | its content in order | test |
| title | heading, level 3 by default | its text | none | the heading and its level | test |
| link | link | its text | none | the title and "link" | test |
| photo | none, with an empty `alt` | none | none | nothing | by hand |

## Tokens
| Part | State | Token |
|---|---|---|
| photo | all | `--r-2xl`, `--muted`, `--outline-image` |
| photo | hover | `--t-press`, `--curve` |
| link | focus-visible | `--ring`, `--line-focus`, `--focus-offset` |
| meta | all | `--muted-foreground` |

## Related
- SaveToggle: the overlay action on the photo.
- Item: a row for things read by name.
- Card: a surface of facts about one thing.
- Skeleton: the tile while it loads.
- MessageAttachment: pictures and files sent in a message, with upload progress and a failure you can retry.
- Lightbox: the tile's photos, opened one at a time.
- FileTile: one file as a tile: its type, name and size, with the upload or the failure drawn on it.
