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

# setScrollPadding()

> Keep room clear at the page's edges when Usertour scrolls a tooltip's target into view

When a tooltip points to an element outside the viewport, Usertour scrolls that element into view. If your app has a fixed header or a fixed bottom bar, the element can end up underneath it. `setScrollPadding()` tells Usertour how many pixels to keep clear at each edge of the page, so the element lands in the part the user can actually see.

## Parameters

**scrollPadding** `object | null` *required*

The pixels to keep clear at each edge. Every side is optional and defaults to
`0`. Pass `null` to clear the padding.

**properties**

**top** `number`

Pixels to keep clear at the top of the page, e.g. the height of a fixed header.

**right** `number`

Pixels to keep clear at the right edge.

**bottom** `number`

Pixels to keep clear at the bottom, e.g. the height of a fixed bottom bar.

**left** `number`

Pixels to keep clear at the left edge, e.g. the width of a fixed sidebar.

## Examples

### Keep a fixed header clear

```javascript theme={null}
// The app's header is fixed at the top and 64px high
usertour.setScrollPadding({ top: 64 });
```

### A fixed header and a fixed bottom bar

```javascript theme={null}
usertour.setScrollPadding({ top: 64, bottom: 56 });
```

### Clear the padding

```javascript theme={null}
usertour.setScrollPadding(null);
```

## How the default scroll works

* A target that can already be seen whole, clear of the padding, is left where it is: the page doesn't move.
* Otherwise, a target that fits in the visible part of the page (the viewport minus the padding) is centered in it.
* A target taller than that, such as a long table, is scrolled in by its top, so the user starts at the beginning of it rather than in the middle.
* The padding applies when the page itself scrolls to the target. An element that has to be scrolled inside a scrolling container or an iframe is scrolled into view the browser's way, and the padding does not decide where it lands. For such pages, set CSS [`scroll-padding`](https://developer.mozilla.org/en-US/docs/Web/CSS/scroll-padding) on your page's `html` element instead.
* If your page also sets a CSS `scroll-padding` on its `html` element, the `setScrollPadding()` value is the one used when the page itself scrolls to the target; the CSS value is not added to it. Pass the full amount you want kept clear. Without `setScrollPadding()`, the browser does the scroll and keeps your CSS `scroll-padding` clear.
* A padding with no positive side, such as `{ top: 0 }`, is the same as `null`: the browser does the scroll and keeps your CSS `scroll-padding` clear. `setScrollPadding()` can't be used to turn a CSS `scroll-padding` off.
* Usertour never changes your page's styles.

## Notes

* You can call it before `usertour.init()`, or before the script has loaded; the call is applied when the SDK loads. Queuing it before load needs the current installation snippet or the `usertour.js` npm package v0.0.28 or newer; an older snippet drops that early call with a warning, so call it again after the SDK has loaded or update the snippet.
* When a [`setCustomScrollIntoView()`](https://docs.usertour.io/developers/usertourjs-reference/advanced/set-custom-scroll-into-view) callback is set, your callback does the scrolling and the padding is not used.
* Needs Usertour.js newer than v0.9.9. Usertour Cloud always serves the newest version; self-hosted, upgrade your server. An older version ignores the call and logs a warning.


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