# useBottomInset (https://docs.salla.dev/twilight/react/hooks/use-bottom-inset)



Many stores install apps that add a floating button at the bottom of the screen, such as a chat bubble or a WhatsApp button. On a phone, that button can sit on top of your theme's bottom navigation bar. Neither side knows about the other: the app cannot see your bar, and your theme does not control the app's markup.

Use `useBottomInset` on your fixed bottom bar. A hook is a function that adds behaviour to a React component. While the bar is visible, this one sets the CSS variable `--twilight-bottom-inset` on `<html>` to the height the bar takes, in pixels. Apps and your own CSS read it to stay clear of the bar. Nothing outside your theme is moved.

## Example [#example]

```tsx title="app/components/layout/MobileNav.tsx"
import { useBottomInset } from '@salla.sa/twilight-theme-engine/hooks/useBottomInset';

export function MobileNav() {
  const ref = useBottomInset<HTMLElement>();
  return (
    <nav ref={ref} className="fixed inset-x-0 bottom-0 md:hidden">
      ...
    </nav>
  );
}
```

Put the ref on the bar's outer element: the one that is fixed to the bottom.

## API [#api]

```ts
function useBottomInset<T extends Element = HTMLElement>(): (element: T | null) => () => void;
```

It returns a ref callback. Pass it as the `ref` of the bar.

## What the variable holds [#what-the-variable-holds]

| The bar is…                                                                                                          | `--twilight-bottom-inset`                                                 |
| -------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------- |
| Visible at the bottom of the screen                                                                                  | Its height, from its top edge to the bottom of the screen, such as `64px` |
| Partly slid below the screen                                                                                         | Only the part still on screen                                             |
| Hidden (`display: none`, for example `md:hidden` on desktop, or `visibility: hidden`) or slid fully below the screen | Not set                                                                   |
| Unmounted                                                                                                            | Not set                                                                   |

With more than one registered bar, the variable holds the tallest. A bar taller than the screen counts as the screen height. It is measured again when the bar or the window changes size, when the bar's `style`, `class` or `hidden` changes, and when a transition or animation ends, batched into one measurement per frame. During server rendering it does nothing.

## Using the variable in CSS [#using-the-variable-in-css]

Keep your own content clear of the bar, for example the end of a long page:

```css title="app/styles/layout.css"
main {
  padding-bottom: var(--twilight-bottom-inset, 0px);
}
```

Always give a fallback (`0px`): the variable is not set on desktop, while the bar is hidden, or on themes without a bar.

App developers use the same variable to place their widgets. Point them to [Keep app widgets above the bottom bar](https://docs.salla.dev/twilight/react/recipes/keep-app-widgets-above-the-bottom-bar).

## Next [#next]

* [useDocumentClass](https://docs.salla.dev/twilight/react/hooks/use-document-class) sets classes on `<html>` and `<body>`.
* [Styling](https://docs.salla.dev/twilight/react/guide/styling) shows how to write theme CSS.
