Class Img


@Marshalled(typeName="img") public class Img extends HtmlElementVoid<Img>
DTO for an HTML <img> element.

The img element represents an image in the document. It is a void element that embeds an image into the page. The alt attribute is required for accessibility, providing alternative text for screen readers and when images cannot be displayed.

Examples:

import static org.apache.juneau.bean.html5.HtmlBuilder.*; // Simple image with alt text Img img1 = img() .src("photo.jpg") .alt("A beautiful sunset over the mountains"); // Image with dimensions and styling Img img2 = img() .src("logo.png") .alt("Company Logo") .width("200") .height("100") .class_("logo"); // Image with CORS and image map Img img3 = img() .src("https://example.com/image.jpg") .alt("Interactive image") .crossorigin("anonymous") .usemap("#imagemap"); // Responsive image with multiple sources Img img4 = img() .src("image-800w.jpg") .alt("Responsive image") .sizes("(max-width: 600px) 100vw, 50vw") .srcset("image-400w.jpg 400w, image-800w.jpg 800w");

The following convenience methods are provided for constructing instances of this bean:

See Also:
  • Constructor Details

    • Img

      public Img()
      Creates an empty Img element.
    • Img

      public Img(Object src)
      Creates an Img element with the specified src(Object) attribute.
      Parameters:
      src - The src(Object) attribute. Can be null, in which case the attribute is stored with a null value (not removed).
  • Method Details

    • alt

      public Img alt(String value)
      alt attribute.

      Specifies alternative text for the image. This text is displayed when the image cannot be loaded and is used by screen readers for accessibility.

      The alt text should be descriptive and convey the same information as the image.

      Parameters:
      value - Alternative text for the image. Can be null to unset the attribute.
      Returns:
      This object.
    • crossorigin

      public Img crossorigin(String value)
      crossorigin attribute.

      Specifies how the element handles cross-origin requests for CORS (Cross-Origin Resource Sharing).

      Possible values:

      • "anonymous" - Cross-origin requests are made without credentials
      • "use-credentials" - Cross-origin requests include credentials
      Parameters:
      value - How to handle cross-origin requests. Can be null to unset the attribute.
      Returns:
      This object.
    • height

      public Img height(Object value)
      height attribute.

      Vertical dimension.

      Parameters:
      value - The new value for this attribute. Typically a Number or String. Can be null to unset the attribute.
      Returns:
      This object.
    • ismap

      public Img ismap(Object value)
      ismap attribute.

      Whether the image is a server-side image map.

      This attribute uses deminimized values:

      • false - Attribute is not added
      • true - Attribute is added as "ismap"
      • Other values - Passed through as-is
      Parameters:
      value - The new value for this attribute. Typically a Boolean or String. Can be null to unset the attribute.
      Returns:
      This object.
    • src

      public Img src(Object value)
      src attribute.

      Address of the resource.

      The value can be of any of the following types: URI, URL, String. Strings must be valid URIs.

      URIs defined by UriResolver can be used for values.

      Parameters:
      value - The new value for this attribute. Typically a URL or String. Can be null, in which case the attribute is stored with a null value (not removed).
      Returns:
      This object.
    • usemap

      public Img usemap(String value)
      usemap attribute.

      Specifies the name of an image map to use with this image. The value should correspond to the name attribute of a map element that defines clickable areas on the image.

      The value should start with "#" followed by the name of the map element.

      Parameters:
      value - The name of the image map to use (e.g., "#mymap"). Can be null to unset the attribute.
      Returns:
      This object.
    • width

      public Img width(Object value)
      width attribute.

      Horizontal dimension.

      Parameters:
      value - The new value for this attribute. Typically a Number or String. Can be null to unset the attribute.
      Returns:
      This object.