> ## Documentation Index
> Fetch the complete documentation index at: https://docs.skybridge.tech/llms.txt
> Use this file to discover all available pages before exploring further.

# useViewport

> Fit the view to the space the host gives it

Your [view](https://docs.skybridge.tech/build/view.md) renders inside the host's surface, on its terms: a bounded height to fit and edges to keep clear of device chrome. `useViewport` reports those constraints so the view can size itself to the space the host actually gives it. It re-renders on every resize, so read the host theme from [`useUser`](https://docs.skybridge.tech/api-reference/use-user) instead.

## Example

The carousel fits its scroll area to the height the host offers and keeps content clear of notches and home indicators.

```tsx highlight={4,9,11-14} theme={null}
import { useViewport } from "skybridge/web";

function Carousel({ products }: { products: Product[] }) {
  const { maxHeight, safeArea } = useViewport();

  return (
    <div
      style={{
        maxHeight,
        overflowY: "auto",
        paddingTop: safeArea.insets.top,
        paddingRight: safeArea.insets.right,
        paddingBottom: safeArea.insets.bottom,
        paddingLeft: safeArea.insets.left,
      }}
    >
      {products.map((product) => (
        <ProductCard key={product.id} product={product} />
      ))}
    </div>
  );
}
```

## Returns

`useViewport` returns the host's current viewport for the view, as a `ViewportState`.

### `maxHeight`

```tsx theme={null}
maxHeight: number | undefined;
```

The maximum height in pixels the host gives the view. It is `undefined` when the host does not report a height limit. It updates as the host resizes the view's container.

### `safeArea`

```tsx theme={null}
safeArea: SafeArea;
```

The pixel insets the view should keep clear of host chrome and device cutouts (notches, rounded corners, home indicators). When the host reports no insets, every side is `0`.

```tsx theme={null}
type SafeArea = {
  insets: SafeAreaInsets;
};

type SafeAreaInsets = {
  top: number;
  right: number;
  bottom: number;
  left: number;
};
```

> [card] [useUser](https://docs.skybridge.tech/api-reference/use-user.md)
>
> Read the host's theme, locale, and device capabilities

> [card] [useRequestSize](https://docs.skybridge.tech/api-reference/use-request-size.md)
>
> Ask the host to resize the view

> [card] [Design for the Host](https://docs.skybridge.tech/guides/ux.md)
>
> Adapt the view to the host's surface


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.