How to set FormLayout margins


I have a MainView extends FormLayout, the only view in the browser. There is no margin/padding, all elements are attached to the browser window frame. I put the FormLayout into a HorizontalLayout. Then scrollbars appears on the browsers content.

How To set margins/padding to the box of the FormLayout ?


I mean this. The buttons are attached to the window’s borders left and right. I want a gap there.

@PWA(name = "Project Base for Vaadin Flow with Spring", shortName = "Project Base")
public class MainView extends FormLayout {

    public MainView(@Autowired MessageBean bean) {
        Button button = new Button("Click me",
                e ->;
        Button button2 = new Button("Click me 2",
                e ->;


OK, found the solution by put the FormLayout into a HorizontalLayout and setMargin(false); setPadding(true) for the HorizontalLayout.