Scroller supports four scroll directions: vertical, horizontal, both, and none. The default is both.
Vertical
When vertical scrolling is enabled, users can scroll down if the content exceeds the container’s height. Horizontal overflow, however, is clipped and inaccessible—so the content’s width should be set to 100%.
Horizontal
When horizontal scrolling is enabled, users can scroll sideways if the content exceeds the container’s width. However, vertical overflow is clipped and inaccessible—so the content’s height should be set to 100%.
Note
Use horizontal scrolling with caution, as it’s less common and can be harder for users to notice and interact with—especially on non-mobile devices.
Desktop
Aside from grids, horizontal scrolling is uncommon in desktop or business applications, as it can be unintuitive and cumbersome.
To improve usability, consider using buttons to make horizontal scrolling more noticeable and accessible. For horizontally scrollable lists, it’s good practice to indicate the total number of items and highlight which ones are currently in view.
Mobile
Horizontal scrolling or swiping is more common on mobile, often used for navigation. It can also help conserve vertical space—for example, when displaying less important content such as shortcuts or images.
When the scroll direction is set to Both (the default), users can scroll both vertically and horizontally if the content overflows in either direction.
This option is ideal for allowing users to pan across large elements, such as images. It can also serve as a fallback for responsive layouts that may overflow in certain situations.
package com.vaadin.demo.component.scroller;
import com.vaadin.flow.component.html.Div;
import com.vaadin.flow.component.html.Image;
import com.vaadin.flow.component.orderedlayout.Scroller;
import com.vaadin.flow.router.Route;
import com.vaadin.flow.server.streams.DownloadHandler;
@Route("scroller-both")
public class ScrollerBoth extends Div {
public ScrollerBoth() {
// tag::snippet[]
Scroller scroller = new Scroller();
scroller.setWidthFull();
scroller.setHeight("300px");
DownloadHandler imageHandler = DownloadHandler.forClassResource(
getClass(), "/images/reindeer.jpg", "reindeer.jpg");
Image img = new Image(imageHandler,
"A reindeer walking on a snowy lake shore at dusk");
scroller.setContent(img);
add(scroller);
// end::snippet[]
}
}
scroller-both.tsx
import React from 'react';
import { Scroller } from '@vaadin/react-components/Scroller.js';
import img from '../../../../../src/main/resources/images/reindeer.jpg?url';
function Example() {
return (
// tag::snippet[]
<Scroller style={{ height: '300px', width: '100%' }}>
<img src={img} alt="A reindeer walking on a snowy lake shore at dusk" />
</Scroller>
// end::snippet[]
);
}
scroller-both.ts
import '@vaadin/scroller';
import { html, LitElement } from 'lit';
import { customElement } from 'lit/decorators.js';
import { applyTheme } from 'Frontend/generated/theme';
import img from '../../../../src/main/resources/images/reindeer.jpg?url';
@customElement('scroller-both')
export class Example extends LitElement {
protected override createRenderRoot() {
const root = super.createRenderRoot();
// Apply custom theme (only supported if your app uses one)
applyTheme(root);
return root;
}
protected override render() {
return html`
<!-- tag::snippet[] -->
<vaadin-scroller class="w-full" style="height: 300px">
<img src="${img}" alt="A reindeer walking on a snowy lake shore at dusk" />
</vaadin-scroller>
<!-- end::snippet[] -->
`;
}
}
None
Use None to hide overflowing content in either direction. No scrollbars are provided, and the clipped content is inaccessible. None is useful in fixed-size or fixed-layout scenarios where overflow would cause issues.
Theme Variants
Scroller has one theme variant: overflow-indicators.
This variant adds borders to indicate when content overflows the scroll container. For example, if more content is available by scrolling down, a bottom border appears. If content overflows at the top, a top border is shown, and so on for other directions.
You shouldn’t add padding to the scroller when using this variant, as it prevents the borders from appearing in the correct positions.