Image

The Image widget allows you to display images in your Preswald application. It’s a simple wrapper around the HTML <img> element that provides consistent styling and integration with the Preswald framework.

Properties

PropertyTypeRequiredDefaultDescription
srcstringYes-The URL or path to the image
altstringNoAlternative text for the image
classNamestringNoAdditional CSS classes to apply to the image

Basic Usage

import preswald as pw

def app():
    pw.image(src="https://example.com/image.jpg", alt="Example image")

pw.run(app)

Examples

Display a Local Image

import preswald as pw

def app():
    pw.image(src="./assets/local-image.png", alt="Local image")

pw.run(app)

Adding Custom Styling

import preswald as pw

def app():
    pw.image(
        src="https://example.com/image.jpg",
        alt="Styled image",
        className="rounded-lg shadow-md"
    )

pw.run(app)

Notes

  • The image widget supports common image formats like PNG, JPG, GIF, and SVG
  • Make sure the image source URL is accessible from your application
  • For local images, ensure the path is relative to your application’s root directory
  • The widget automatically applies responsive sizing while maintaining aspect ratio