class marimo.ui.form(element: UIElement[S, T], *, bordered: bool = True, loading: bool = False, submit_button_label: str = 'Submit', submit_button_tooltip: str | None = None, submit_button_disabled: bool = False, clear_on_submit: bool = False, show_clear_button: bool = False, clear_button_label: str = 'Clear', clear_button_tooltip: str | None = None, validate: Callable[[Mapping[str, Mapping[str, JSONType] | Sequence[JSONType] | str | int | float | bool | MIME | None] | Sequence[Mapping[str, JSONType] | Sequence[JSONType] | str | int | float | bool | MIME | None] | str | int | float | bool | MIME | None], str | None] | None = None, label: str = '', on_change: Callable[[T | None], None] | None = None)#

A submittable form linked to a UIElement.

Use a form to prevent sending UI element values to Python until a button is clicked.

The value of a form is the value of the underlying element the last time the form was submitted.


# Create a form with chaining
form = mo.ui.slider(1, 100).form()
# Create a form with multiple elements
form = ('''
    **Your form.**


    .form(show_clear_button=True, bordered=False)
# Instantiate a form directly
form = mo.ui.form(element=mo.ui.slider(1, 100))


  • value: the value of the wrapped element when the form’s submit button was last clicked

  • element: a copy of the wrapped element

Initialization Args.

  • element: the element to wrap

  • bordered: whether the form should have a border

  • loading: whether the form should be in a loading state

  • submit_button_label: the label of the submit button

  • submit_button_tooltip: the tooltip of the submit button

  • submit_button_disabled: whether the submit button should be disabled

  • clear_on_submit: whether the form should clear its contents after submitting

  • show_clear_button: whether the form should show a clear button

  • clear_button_label: the label of the clear button

  • clear_button_tooltip: the tooltip of the clear button

  • validate: a function that takes the form’s value and returns an error message if the value is invalid, or None if the value is valid

  • label: text label for the form

  • on_change: optional callback to run when this element’s value changes

Public methods

Inherited from UIElement

form([label, bordered, loading, ...])

Create a submittable form out of this UIElement.

Inherited from Html


Convert an HTML object with templated text into a UI element.


Center an item.






Create a callout containing this HTML element.


Wrap an object in a styled container.

Public Data Attributes:

Inherited from UIElement


The element’s current value.

Inherited from Html


A string of HTML representing this element.