Skip to main content
Render an image as HTML.

Usage

# Render an image from a local file
mo.image(src="path/to/image.png")
# Render an image from a URL
mo.image(
    src="https://marimo.io/logo.png",
    alt="Marimo logo",
    width=100,
    height=100,
    rounded=True,
    caption="Marimo logo",
)

Signature

mo.image(
    src: ImageLike,
    alt: Optional[str] = None,
    width: Optional[Union[int, str]] = None,
    height: Optional[Union[int, str]] = None,
    rounded: bool = False,
    style: Optional[dict[str, Any]] = None,
    caption: Optional[str] = None
) -> Html

Parameters

src
ImageLike
required
A path or URL to an image, a file-like object (opened in binary mode), or array-like object.
alt
Optional[str]
default:"None"
The alt text of the image.
width
Optional[Union[int, str]]
default:"None"
The width of the image in pixels or a string with units.
height
Optional[Union[int, str]]
default:"None"
The height of the image in pixels or a string with units.
rounded
bool
default:"False"
Whether to round the corners of the image.
style
Optional[dict[str, Any]]
default:"None"
A dictionary of CSS styles to apply to the image.
caption
Optional[str]
default:"None"
The caption of the image.

Returns

Html
An Html object.

Supported Input Types

The src parameter accepts:
  • str: Path or URL to an image
  • bytes: Image data as bytes
  • io.BytesIO: File-like object in binary mode
  • io.BufferedReader: Buffered file reader
  • Path: pathlib.Path object
  • Array-like objects: lists, numpy arrays, torch tensors, jax arrays, scipy sparse matrices
For array-like objects, the image will be normalized and converted to PNG format.

Build docs developers (and LLMs) love