# Img

An image that fades in once decoded, never painting top to bottom, in a slot over its placeholder, loaded as it nears the view.

Live variants: https://design.arcadia.is/components/img

```tsx
import { Img } from "@arcadia/ui";
```

```tsx
import { useState } from "react";
import { Button, Img } from "@arcadia/ui";

function Fading() {
  const [n, setN] = useState(0);
  return (
    <div {...sx("cmp-img-stage", ImgStyles.stage)}>
      <span {...sx("cmp-img-frame", ImgStyles.frame)}><Img key={n} src={PICTURE} alt="A gradient" rootStyle={ImgStyles.picture} /></span>
      <div {...sx("cmp-bar", cmp.bar)}><Button variant="secondary" size="sm" onClick={() => setN(n + 1)}>Load again</Button></div>
    </div>
  );
}
```

## Accessibility

`alt` works as on any image. An image that fails to load shows at once, so the browser's broken-image box and its alt text are never hidden; in a slot it says so with a Try again button instead. Reduced motion shows the picture as soon as it has decoded, without the fade, and its skeleton does not pulse. A placeholder is hidden from a reader.

## API reference

### Img

- `src` (`string`): An address: a Blob goes through `useAddress` first (Next's types let an `<img>` take one).
- `fit` (`"cover" | "contain" | "fill" | "scale-down" | "none"`): How the picture fits its box. Defaults to `cover` in a placeholder slot.
- `rootStyle` (`RootStyle`): Typed StyleX override: where the image sits; in a slot, where the slot sits.
- `placeholder` (`string | null`): Makes it a slot: what stands in the picture's box from the first frame until the picture has faded in over it, its placeholder's code (`makePlaceholder`) drawn as a blur of its colours, or `null` for the quiet skeleton. The Img then fills its nearest positioned box, and a picture that cannot be loaded says so there, with a way to try again.
- `ahead` (`boolean`, default `false`): Fetched only once its place comes within about two windows of the view, either way, and first when in view.
- `still` (`boolean`, default `false`): `src` moves and no still of it is given, so its first frame is drawn, named by `alt`, and it never plays.
- `style` (`CSSProperties`): Inline geometry the image needs from data (an aspect ratio, the part of a cut picture it keeps).

Rest props go to `<img>` props.
