Class Img


@Bean(typeName="img") public class Img extends HtmlElementVoid
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

  • 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:
      alt - Alternative text for the image.
      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:
      crossorigin - How to handle cross-origin requests.
      Returns:
      This object.
    • height

      public Img height(Object value)
      height attribute.

      Vertical dimension.

      Parameters:
      height - The new value for this attribute. Typically a Number or String.
      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:
      ismap - The new value for this attribute. Typically a Boolean or String.
      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:
      src - The new value for this attribute. Typically a URL or String.
      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:
      usemap - The name of the image map to use (e.g., "#mymap").
      Returns:
      This object.
    • width

      public Img width(Object value)
      width attribute.

      Horizontal dimension.

      Parameters:
      width - The new value for this attribute. Typically a Number or String.
      Returns:
      This object.
    • _class

      public Img _class(String value)
      Description copied from class: HtmlElement
      class attribute.

      Specifies one or more CSS class names for the element, separated by spaces. These classes can be used for styling and JavaScript selection.

      Overrides:
      _class in class HtmlElementVoid
      Returns:
      This object.
    • accesskey

      public Img accesskey(String value)
      Description copied from class: HtmlElement
      accesskey attribute.

      Defines a keyboard shortcut to activate or focus an element. The value should be a single character that, when pressed with a modifier key (usually Alt), activates the element.

      Overrides:
      accesskey in class HtmlElementVoid
      Returns:
      This object.
    • contenteditable

      public Img contenteditable(Object value)
      Description copied from class: HtmlElement
      contenteditable attribute.

      Indicates whether the element's content is editable by the user.

      Possible values:

      • "true" or empty string - Element content is editable
      • "false" - Element content is not editable
      • "plaintext-only" - Element content is editable, but rich text formatting is disabled
      Overrides:
      contenteditable in class HtmlElementVoid
      Returns:
      This object.
    • dir

      public Img dir(String value)
      Description copied from class: HtmlElement
      dir attribute.

      Specifies the text direction of the element's content.

      Possible values:

      • "ltr" - Left-to-right text direction
      • "rtl" - Right-to-left text direction
      • "auto" - Browser determines direction based on content
      Overrides:
      dir in class HtmlElementVoid
      Returns:
      This object.
    • hidden

      public Img hidden(Object value)
      Description copied from class: HtmlElement
      hidden attribute.

      This attribute uses deminimized values:

      • false - Attribute is not added
      • true - Attribute is added as "hidden"
      • Other values - Passed through as-is
      Overrides:
      hidden in class HtmlElementVoid
      Returns:
      This object.
    • id

      public Img id(String value)
      Description copied from class: HtmlElement
      id attribute.

      Specifies a unique identifier for the element. The ID must be unique within the document and can be used for CSS styling, JavaScript selection, and anchor links.

      Overrides:
      id in class HtmlElementVoid
      Returns:
      This object.
    • lang

      public Img lang(String value)
      Description copied from class: HtmlElement
      lang attribute.

      Specifies the primary language of the element's content using a language tag. This helps with accessibility, search engines, and browser features like spell checking.

      Overrides:
      lang in class HtmlElementVoid
      Returns:
      This object.
    • onabort

      public Img onabort(String value)
      Description copied from class: HtmlElement
      onabort attribute.

      Event handler for when an operation is aborted (e.g., image loading is cancelled).

      Overrides:
      onabort in class HtmlElementVoid
      Returns:
      This object.
    • onblur

      public Img onblur(String value)
      Description copied from class: HtmlElement
      onblur attribute.

      Event handler for when the element loses focus.

      Note:

      If your HTML serializer is configured to use single quotes for attribute values, you should use double quotes in your JavaScript code, and vice versa. Otherwise, the quotes will be converted to HTML entities. For example:

      • If using single quotes for attributes: onblur("validate(\"email\")")
      • If using double quotes for attributes: onblur("validate('email')")
      Overrides:
      onblur in class HtmlElementVoid
      Returns:
      This object.
    • oncancel

      public Img oncancel(String value)
      Description copied from class: HtmlElement
      oncancel attribute.

      Event handler for when a dialog is cancelled.

      Overrides:
      oncancel in class HtmlElementVoid
      Returns:
      This object.
    • oncanplay

      public Img oncanplay(String value)
      Description copied from class: HtmlElement
      oncanplay attribute.

      Event handler for when the media can start playing (enough data has been buffered).

      Overrides:
      oncanplay in class HtmlElementVoid
      Returns:
      This object.
    • oncanplaythrough

      public Img oncanplaythrough(String value)
      Description copied from class: HtmlElement
      oncanplaythrough attribute.

      Event handler for when the media can play through to the end without buffering.

      Overrides:
      oncanplaythrough in class HtmlElementVoid
      Returns:
      This object.
    • onchange

      public Img onchange(String value)
      Description copied from class: HtmlElement
      onchange attribute.

      Event handler for when the value of a form element changes and loses focus.

      Note:

      If your HTML serializer is configured to use single quotes for attribute values, you should use double quotes in your JavaScript code, and vice versa. Otherwise, the quotes will be converted to HTML entities. For example:

      • If using single quotes for attributes: onchange("validate(\"field\")")
      • If using double quotes for attributes: onchange("validate('field')")
      Overrides:
      onchange in class HtmlElementVoid
      Returns:
      This object.
    • onclick

      public Img onclick(String value)
      Description copied from class: HtmlElement
      onclick attribute.

      Event handler for when the element is clicked.

      Note:

      If your HTML serializer is configured to use single quotes for attribute values, you should use double quotes in your JavaScript code, and vice versa. Otherwise, the quotes will be converted to HTML entities. For example:

      • If using single quotes for attributes: onclick("alert(\"Hello\")")
      • If using double quotes for attributes: onclick("alert('Hello')")
      Overrides:
      onclick in class HtmlElementVoid
      Returns:
      This object.
    • oncuechange

      public Img oncuechange(String value)
      Description copied from class: HtmlElement
      oncuechange attribute.

      Event handler for when a text track cue changes.

      Overrides:
      oncuechange in class HtmlElementVoid
      Returns:
      This object.
    • ondblclick

      public Img ondblclick(String value)
      Description copied from class: HtmlElement
      ondblclick attribute.

      Event handler for when the element is double-clicked.

      Overrides:
      ondblclick in class HtmlElementVoid
      Returns:
      This object.
    • ondurationchange

      public Img ondurationchange(String value)
      Description copied from class: HtmlElement
      ondurationchange attribute.

      Event handler for when the duration of the media changes.

      Overrides:
      ondurationchange in class HtmlElementVoid
      Returns:
      This object.
    • onemptied

      public Img onemptied(String value)
      Description copied from class: HtmlElement
      onemptied attribute.

      Event handler for when the media element becomes empty (e.g., network error).

      Overrides:
      onemptied in class HtmlElementVoid
      Returns:
      This object.
    • onended

      public Img onended(String value)
      Description copied from class: HtmlElement
      onended attribute.

      Event handler for when the media playback reaches the end.

      Overrides:
      onended in class HtmlElementVoid
      Returns:
      This object.
    • onerror

      public Img onerror(String value)
      Description copied from class: HtmlElement
      onerror attribute.

      Event handler for when an error occurs (e.g., failed resource loading).

      Overrides:
      onerror in class HtmlElementVoid
      Returns:
      This object.
    • onfocus

      public Img onfocus(String value)
      Description copied from class: HtmlElement
      onfocus attribute.

      Event handler for when the element receives focus.

      Note:

      If your HTML serializer is configured to use single quotes for attribute values, you should use double quotes in your JavaScript code, and vice versa. Otherwise, the quotes will be converted to HTML entities. For example:

      • If using single quotes for attributes: onfocus("highlight(\"field\")")
      • If using double quotes for attributes: onfocus("highlight('field')")
      Overrides:
      onfocus in class HtmlElementVoid
      Returns:
      This object.
    • oninput

      public Img oninput(String value)
      Description copied from class: HtmlElement
      oninput attribute.

      Event handler for when the value of an input element changes (fires on every keystroke).

      Overrides:
      oninput in class HtmlElementVoid
      Returns:
      This object.
    • oninvalid

      public Img oninvalid(String value)
      Description copied from class: HtmlElement
      oninvalid attribute.

      Event handler for when form validation fails.

      Overrides:
      oninvalid in class HtmlElementVoid
      Returns:
      This object.
    • onkeydown

      public Img onkeydown(String value)
      Description copied from class: HtmlElement
      onkeydown attribute.

      Event handler for when a key is pressed down.

      Overrides:
      onkeydown in class HtmlElementVoid
      Returns:
      This object.
    • onkeypress

      public Img onkeypress(String value)
      Description copied from class: HtmlElement
      onkeypress attribute.

      Event handler for when a key is pressed (deprecated, use onkeydown instead).

      Overrides:
      onkeypress in class HtmlElementVoid
      Returns:
      This object.
    • onkeyup

      public Img onkeyup(String value)
      Description copied from class: HtmlElement
      onkeyup attribute.

      Event handler for when a key is released.

      Overrides:
      onkeyup in class HtmlElementVoid
      Returns:
      This object.
    • onload

      public Img onload(String value)
      Description copied from class: HtmlElement
      onload attribute.

      Event handler for when the element and its resources have finished loading.

      Note:

      If your HTML serializer is configured to use single quotes for attribute values, you should use double quotes in your JavaScript code, and vice versa. Otherwise, the quotes will be converted to HTML entities. For example:

      • If using single quotes for attributes: onload("init(\"config\")")
      • If using double quotes for attributes: onload("init('config')")
      Overrides:
      onload in class HtmlElementVoid
      Returns:
      This object.
    • onloadeddata

      public Img onloadeddata(String value)
      Description copied from class: HtmlElement
      onloadeddata attribute.

      Event handler for when the first frame of media has finished loading.

      Overrides:
      onloadeddata in class HtmlElementVoid
      Returns:
      This object.
    • onloadedmetadata

      public Img onloadedmetadata(String value)
      Description copied from class: HtmlElement
      onloadedmetadata attribute.

      Event handler for when metadata (duration, dimensions, etc.) has been loaded.

      Overrides:
      onloadedmetadata in class HtmlElementVoid
      Returns:
      This object.
    • onloadstart

      public Img onloadstart(String value)
      Description copied from class: HtmlElement
      onloadstart attribute.

      Event handler for when the browser starts loading the media.

      Overrides:
      onloadstart in class HtmlElementVoid
      Returns:
      This object.
    • onmousedown

      public Img onmousedown(String value)
      Description copied from class: HtmlElement
      onmousedown attribute.

      Event handler for when a mouse button is pressed down on the element.

      Overrides:
      onmousedown in class HtmlElementVoid
      Returns:
      This object.
    • onmouseenter

      public Img onmouseenter(String value)
      Description copied from class: HtmlElement
      onmouseenter attribute.

      Event handler for when the mouse pointer enters the element (does not bubble).

      Overrides:
      onmouseenter in class HtmlElementVoid
      Returns:
      This object.
    • onmouseleave

      public Img onmouseleave(String value)
      Description copied from class: HtmlElement
      onmouseleave attribute.

      Event handler for when the mouse pointer leaves the element (does not bubble).

      Overrides:
      onmouseleave in class HtmlElementVoid
      Returns:
      This object.
    • onmousemove

      public Img onmousemove(String value)
      Description copied from class: HtmlElement
      onmousemove attribute.

      Event handler for when the mouse pointer moves over the element.

      Overrides:
      onmousemove in class HtmlElementVoid
      Returns:
      This object.
    • onmouseout

      public Img onmouseout(String value)
      Description copied from class: HtmlElement
      onmouseout attribute.

      Event handler for when the mouse pointer moves out of the element (bubbles).

      Overrides:
      onmouseout in class HtmlElementVoid
      Returns:
      This object.
    • onmouseover

      public Img onmouseover(String value)
      Description copied from class: HtmlElement
      onmouseover attribute.

      Event handler for when the mouse pointer moves over the element (bubbles).

      Note:

      If your HTML serializer is configured to use single quotes for attribute values, you should use double quotes in your JavaScript code, and vice versa. Otherwise, the quotes will be converted to HTML entities. For example:

      • If using single quotes for attributes: onmouseover("showTooltip(\"info\")")
      • If using double quotes for attributes: onmouseover("showTooltip('info')")
      Overrides:
      onmouseover in class HtmlElementVoid
      Returns:
      This object.
    • onmouseup

      public Img onmouseup(String value)
      Description copied from class: HtmlElement
      onmouseup attribute.

      Event handler for when a mouse button is released over the element.

      Overrides:
      onmouseup in class HtmlElementVoid
      Returns:
      This object.
    • onmousewheel

      public Img onmousewheel(String value)
      Description copied from class: HtmlElement
      onmousewheel attribute.

      Event handler for when the mouse wheel is rotated over the element (deprecated, use onwheel).

      Overrides:
      onmousewheel in class HtmlElementVoid
      Returns:
      This object.
    • onpause

      public Img onpause(String value)
      Description copied from class: HtmlElement
      onpause attribute.

      Event handler for when media playback is paused.

      Overrides:
      onpause in class HtmlElementVoid
      Returns:
      This object.
    • onplay

      public Img onplay(String value)
      Description copied from class: HtmlElement
      onplay attribute.

      Event handler for when media playback starts.

      Overrides:
      onplay in class HtmlElementVoid
      Returns:
      This object.
    • onplaying

      public Img onplaying(String value)
      Description copied from class: HtmlElement
      onplaying attribute.

      Event handler for when media playback starts after being paused or delayed.

      Overrides:
      onplaying in class HtmlElementVoid
      Returns:
      This object.
    • onprogress

      public Img onprogress(String value)
      Description copied from class: HtmlElement
      onprogress attribute.

      Event handler for when the browser is downloading media data.

      Overrides:
      onprogress in class HtmlElementVoid
      Returns:
      This object.
    • onratechange

      public Img onratechange(String value)
      Description copied from class: HtmlElement
      onratechange attribute.

      Event handler for when the playback rate of media changes.

      Overrides:
      onratechange in class HtmlElementVoid
      Returns:
      This object.
    • onreset

      public Img onreset(String value)
      Description copied from class: HtmlElement
      onreset attribute.

      Event handler for when a form is reset.

      Overrides:
      onreset in class HtmlElementVoid
      Returns:
      This object.
    • onresize

      public Img onresize(String value)
      Description copied from class: HtmlElement
      onresize attribute.

      Event handler for when the element is resized.

      Overrides:
      onresize in class HtmlElementVoid
      Returns:
      This object.
    • onscroll

      public Img onscroll(String value)
      Description copied from class: HtmlElement
      onscroll attribute.

      Event handler for when the element's scrollbar is scrolled.

      Overrides:
      onscroll in class HtmlElementVoid
      Returns:
      This object.
    • onseeked

      public Img onseeked(String value)
      Description copied from class: HtmlElement
      onseeked attribute.

      Event handler for when a seek operation completes.

      Overrides:
      onseeked in class HtmlElementVoid
      Returns:
      This object.
    • onseeking

      public Img onseeking(String value)
      Description copied from class: HtmlElement
      onseeking attribute.

      Event handler for when a seek operation begins.

      Overrides:
      onseeking in class HtmlElementVoid
      Returns:
      This object.
    • onselect

      public Img onselect(String value)
      Description copied from class: HtmlElement
      onselect attribute.

      Event handler for when text is selected in the element.

      Overrides:
      onselect in class HtmlElementVoid
      Returns:
      This object.
    • onshow

      public Img onshow(String value)
      Description copied from class: HtmlElement
      onshow attribute.

      Event handler for when a context menu is shown.

      Overrides:
      onshow in class HtmlElementVoid
      Returns:
      This object.
    • onstalled

      public Img onstalled(String value)
      Description copied from class: HtmlElement
      onstalled attribute.

      Event handler for when media loading is stalled.

      Overrides:
      onstalled in class HtmlElementVoid
      Returns:
      This object.
    • onsubmit

      public Img onsubmit(String value)
      Description copied from class: HtmlElement
      onsubmit attribute.

      Event handler for when a form is submitted.

      Note:

      If your HTML serializer is configured to use single quotes for attribute values, you should use double quotes in your JavaScript code, and vice versa. Otherwise, the quotes will be converted to HTML entities. For example:

      • If using single quotes for attributes: onsubmit("return validate(\"form\")")
      • If using double quotes for attributes: onsubmit("return validate('form')")
      Overrides:
      onsubmit in class HtmlElementVoid
      Returns:
      This object.
    • onsuspend

      public Img onsuspend(String value)
      Description copied from class: HtmlElement
      onsuspend attribute.

      Event handler for when media loading is suspended.

      Overrides:
      onsuspend in class HtmlElementVoid
      Returns:
      This object.
    • ontimeupdate

      public Img ontimeupdate(String value)
      Description copied from class: HtmlElement
      ontimeupdate attribute.

      Event handler for when the current playback position changes.

      Overrides:
      ontimeupdate in class HtmlElementVoid
      Returns:
      This object.
    • ontoggle

      public Img ontoggle(String value)
      Description copied from class: HtmlElement
      ontoggle attribute.

      Event handler for when a details element is opened or closed.

      Overrides:
      ontoggle in class HtmlElementVoid
      Returns:
      This object.
    • onvolumechange

      public Img onvolumechange(String value)
      Description copied from class: HtmlElement
      onvolumechange attribute.

      Event handler for when the volume of media changes.

      Overrides:
      onvolumechange in class HtmlElementVoid
      Returns:
      This object.
    • onwaiting

      public Img onwaiting(String value)
      Description copied from class: HtmlElement
      onwaiting attribute.

      Event handler for when media playback stops to buffer more data.

      Overrides:
      onwaiting in class HtmlElementVoid
      Returns:
      This object.
    • spellcheck

      public Img spellcheck(Object value)
      Description copied from class: HtmlElement
      spellcheck attribute.

      Indicates whether the element should have its spelling and grammar checked.

      Possible values:

      • "true" - Enable spell checking for this element
      • "false" - Disable spell checking for this element
      Overrides:
      spellcheck in class HtmlElementVoid
      Returns:
      This object.
    • style

      public Img style(String value)
      Description copied from class: HtmlElement
      style attribute.

      Specifies inline CSS styles for the element. The value should be valid CSS property-value pairs separated by semicolons.

      Overrides:
      style in class HtmlElementVoid
      Returns:
      This object.
    • tabindex

      public Img tabindex(Object value)
      Description copied from class: HtmlElement
      tabindex attribute.

      Specifies the tab order of the element when navigating with the keyboard.

      Possible values:

      • Positive integer - Element is focusable and participates in tab order
      • "0" - Element is focusable but not in tab order
      • Negative integer - Element is not focusable
      Overrides:
      tabindex in class HtmlElementVoid
      Returns:
      This object.
    • title

      public Img title(String value)
      Description copied from class: HtmlElement
      title attribute.

      Specifies additional information about the element, typically displayed as a tooltip when the user hovers over the element.

      Overrides:
      title in class HtmlElementVoid
      Returns:
      This object.
    • translate

      public Img translate(Object value)
      Description copied from class: HtmlElement
      translate attribute.

      Specifies whether the element's content should be translated when the page is localized.

      Possible values:

      • "yes" - Content should be translated (default)
      • "no" - Content should not be translated
      Overrides:
      translate in class HtmlElementVoid
      Returns:
      This object.