pub struct Img<'life> {Show 30 fields
pub accesskey: Option<&'life str>,
pub alt: Option<&'life str>,
pub autocapitalize: Option<&'life str>,
pub autofocus: Option<bool>,
pub class: Option<&'life str>,
pub contenteditable: Option<&'life str>,
pub contextmenu: Option<&'life str>,
pub crossorigin: Option<&'life str>,
pub data: Option<BTreeMap<&'life str, &'life str>>,
pub decoding: Option<&'life str>,
pub dir: Option<&'life str>,
pub draggable: Option<&'life str>,
pub elementtiming: Option<&'life str>,
pub enterkeyhint: Option<&'life str>,
pub exportparts: Option<&'life str>,
pub fetchpriority: Option<&'life str>,
pub height: Option<&'life str>,
pub hidden: Option<bool>,
pub id: Option<&'life str>,
pub inert: Option<&'life str>,
pub inputmode: Option<&'life str>,
pub is: Option<&'life str>,
pub ismap: Option<&'life str>,
pub loading: Option<&'life str>,
pub referrerpolicy: Option<&'life str>,
pub sizes: Option<&'life str>,
pub src: Option<&'life str>,
pub srcset: Option<&'life str>,
pub usemap: Option<&'life str>,
pub width: Option<&'life str>,
}
Expand description
The <img>
HTML element embeds an image into the document.
More information: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img
Fields§
§accesskey: Option<&'life str>
Provides a hint for generating a keyboard shortcut for the current element. This attribute consists of a space-separated list of characters. The browser should use the first one that exists on the computer keyboard layout.
alt: Option<&'life str>
Defines an alternative text description of the image.
Note: Browsers do not always display images. There are a number of situations in which a browser might not display images, such as:
- Non-visual browsers (such as those used by people with visual impairments)
- The user chooses not to display images (saving bandwidth, privacy reasons)
- The image is invalid or an unsupported type
In these cases, the browser may replace the image with the text in the element's alt
attribute. For these reasons and others, provide a useful value for alt
whenever possible.
Setting this attribute to an empty string (alt=""
) indicates that this image is not a key part of the content (it's decoration or a tracking pixel), and that non-visual browsers may omit it from rendering. Visual browsers will also hide the broken image icon if the alt
is empty and the image failed to display.
This attribute is also used when copying and pasting the image to text, or saving a linked image to a bookmark.
autocapitalize: Option<&'life str>
Controls whether and how text input is automatically capitalized as it is entered/edited by the user. It can have the following values:
off
ornone
, no autocapitalization is applied (all letters default to lowercase)on
orsentences
, the first letter of each sentence defaults to a capital letter; all other letters default to lowercasewords
, the first letter of each word defaults to a capital letter; all other letters default to lowercasecharacters
, all letters should default to uppercase
autofocus: Option<bool>
Indicates that an element is to be focused on page load, or as soon as the <dialog>
it is part of is displayed. This attribute is a boolean, initially false.
class: Option<&'life str>
A space-separated list of the classes of the element. Classes allow CSS and JavaScript to select and access specific elements via the class selectors or functions like the method Document.getElementsByClassName()
.
contenteditable: Option<&'life str>
An enumerated attribute indicating if the element should be editable by the user. If so, the browser modifies its widget to allow editing. The attribute must take one of the following values:
true
or the empty string, which indicates that the element must be editable;false
, which indicates that the element must not be editable.
crossorigin: Option<&'life str>
Indicates if the fetching of the image must be done using a CORS request. Image data from a CORS-enabled image returned from a CORS request can be reused in the <canvas>
element without being marked "tainted".
If the crossorigin
attribute is not specified, then a non-CORS request is sent (without the Origin
request header), and the browser marks the image as tainted and restricts access to its image data, preventing its usage in <canvas>
elements.
If the crossorigin
attribute is specified, then a CORS request is sent (with the Origin
request header); but if the server does not opt into allowing cross-origin access to the image data by the origin site (by not sending any Access-Control-Allow-Origin
response header, or by not including the site's origin in any Access-Control-Allow-Origin
response header it does send), then the browser blocks the image from loading, and logs a CORS error to the devtools console.
Allowed values:
anonymous
-
A CORS request is sent with credentials omitted (that is, no cookies, X.509 certificates, or
Authorization
request header). use-credentials
-
The CORS request is sent with any credentials included (that is, cookies, X.509 certificates, and the
Authorization
request header). If the server does not opt into sharing credentials with the origin site (by sending back theAccess-Control-Allow-Credentials: true
response header), then the browser marks the image as tainted and restricts access to its image data.
If the attribute has an invalid value, browsers handle it as if the anonymous
value was used. See CORS settings attributes for additional information.
data: Option<BTreeMap<&'life str, &'life str>>
Forms a class of attributes, called custom data attributes, that allow proprietary information to be exchanged between the HTML and its DOM representation that may be used by scripts. All such custom data are available via the HTMLElement
interface of the element the attribute is set on. The HTMLElement.dataset
property gives access to them.
decoding: Option<&'life str>
Provides an image decoding hint to the browser. Allowed values:
sync
-
Decode the image synchronously, for atomic presentation with other content.
async
-
Decode the image asynchronously, to reduce delay in presenting other content.
auto
-
Default: no preference for the decoding mode. The browser decides what is best for the user.
dir: Option<&'life str>
An enumerated attribute indicating the directionality of the element's text. It can have the following values:
ltr
, which means left to right and is to be used for languages that are written from the left to the right (like English);rtl
, which means right to left and is to be used for languages that are written from the right to the left (like Arabic);auto
, which lets the user agent decide. It uses a basic algorithm as it parses the characters inside the element until it finds a character with a strong directionality, then it applies that directionality to the whole element.
draggable: Option<&'life str>
An enumerated attribute indicating whether the element can be dragged, using the Drag and Drop API. It can have the following values:
true
, which indicates that the element may be draggedfalse
, which indicates that the element may not be dragged.
elementtiming: Option<&'life str>
Marks the image for observation by the PerformanceElementTiming
API. The value given becomes an identifier for the observed image element. See also the elementtiming
attribute page.
enterkeyhint: Option<&'life str>
Hints what action label (or icon) to present for the enter key on virtual keyboards.
exportparts: Option<&'life str>
Used to transitively export shadow parts from a nested shadow tree into a containing light tree.
fetchpriority: Option<&'life str>
Provides a hint of the relative priority to use when fetching the image. Allowed values:
high
-
Signals a high-priority fetch relative to other images.
low
-
Signals a low-priority fetch relative to other images.
auto
-
Default: Signals automatic determination of fetch priority relative to other images.
height: Option<&'life str>
The intrinsic height of the image, in pixels. Must be an integer without a unit.
Note: Including height
and width
enables the aspect ratio of the image to be calculated by the browser prior to the image being loaded. This aspect ratio is used to reserve the space needed to display the image, reducing or even preventing a layout shift when the image is downloaded and painted to the screen. Reducing layout shift is a major component of good user experience and web performance.
An enumerated attribute indicating that the element is not yet, or is no longer, relevant. For example, it can be used to hide elements of the page that can't be used until the login process has been completed. The browser won't render such elements. This attribute must not be used to hide content that could legitimately be shown.
id: Option<&'life str>
Defines a unique identifier (ID) which must be unique in the whole document. Its purpose is to identify the element when linking (using a fragment identifier), scripting, or styling (with CSS).
inert: Option<&'life str>
A boolean value that makes the browser disregard user input events for the element. Useful when click events are present.
inputmode: Option<&'life str>
Provides a hint to browsers about the type of virtual keyboard configuration to use when editing this element or its contents. Used primarily on <input>
elements, but is usable on any element while in contenteditable
mode.
is: Option<&'life str>
Allows you to specify that a standard HTML element should behave like a registered custom built-in element (see Using custom elements for more details).
ismap: Option<&'life str>
This Boolean attribute indicates that the image is part of a server-side map. If so, the coordinates where the user clicked on the image are sent to the server.
loading: Option<&'life str>
Indicates how the browser should load the image:
eager
-
Loads the image immediately, regardless of whether or not the image is currently within the visible viewport (this is the default value).
lazy
-
Defers loading the image until it reaches a calculated distance from the viewport, as defined by the browser. The intent is to avoid the network and storage bandwidth needed to handle the image until it's reasonably certain that it will be needed. This generally improves the performance of the content in most typical use cases.
Note: Loading is only deferred when JavaScript is enabled. This is an anti-tracking measure, because if a user agent supported lazy loading when scripting is disabled, it would still be possible for a site to track a user's approximate scroll position throughout a session, by strategically placing images in a page's markup such that a server can track how many images are requested and when.
referrerpolicy: Option<&'life str>
A string indicating which referrer to use when fetching the resource:
no-referrer
: TheReferer
header will not be sent.no-referrer-when-downgrade
: TheReferer
header will not be sent to origins without TLS (HTTPS).origin
: The sent referrer will be limited to the origin of the referring page: its scheme, host, and port.origin-when-cross-origin
: The referrer sent to other origins will be limited to the scheme, the host, and the port. Navigations on the same origin will still include the path.same-origin
: A referrer will be sent for same origin, but cross-origin requests will contain no referrer information.strict-origin
: Only send the origin of the document as the referrer when the protocol security level stays the same (HTTPS→HTTPS), but don't send it to a less secure destination (HTTPS→HTTP).strict-origin-when-cross-origin
(default): Send a full URL when performing a same-origin request, only send the origin when the protocol security level stays the same (HTTPS→HTTPS), and send no header to a less secure destination (HTTPS→HTTP).unsafe-url
: The referrer will include the origin and the path (but not the fragment, password, or username). This value is unsafe, because it leaks origins and paths from TLS-protected resources to insecure origins.
sizes: Option<&'life str>
One or more strings separated by commas, indicating a set of source sizes. Each source size consists of:
- A media condition. This must be omitted for the last item in the list.
- A source size value.
Media Conditions describe properties of the viewport, not of the image. For example, (max-height: 500px) 1000px
proposes to use a source of 1000px width, if the viewport is not higher than 500px.
Source size values specify the intended display size of the image. User agents use the current source size to select one of the sources supplied by the srcset
attribute, when those sources are described using width (w
) descriptors. The selected source size affects the intrinsic size of the image (the image's display size if no CSS styling is applied). If the srcset
attribute is absent, or contains no values with a width descriptor, then the sizes
attribute has no effect.
src: Option<&'life str>
The image URL. Mandatory for the <img>
element. On browsers supporting srcset
, src
is treated like a candidate image with a pixel density descriptor 1x
, unless an image with this pixel density descriptor is already defined in srcset
, or unless srcset
contains w
descriptors.
srcset: Option<&'life str>
One or more strings separated by commas, indicating possible image sources for the user agent to use. Each string is composed of:
- A URL to an image
- Optionally, whitespace followed by one of:
- A width descriptor (a positive integer directly followed by
w
). The width descriptor is divided by the source size given in thesizes
attribute to calculate the effective pixel density. - A pixel density descriptor (a positive floating point number directly followed by
x
).
- A width descriptor (a positive integer directly followed by
If no descriptor is specified, the source is assigned the default descriptor of 1x
.
It is incorrect to mix width descriptors and pixel density descriptors in the same srcset
attribute. Duplicate descriptors (for instance, two sources in the same srcset
which are both described with 2x
) are also invalid.
If the srcset
attribute uses width descriptors, the sizes
attribute must also be present, or the srcset
itself will be ignored.
The user agent selects any of the available sources at its discretion. This provides them with significant leeway to tailor their selection based on things like user preferences or bandwidth conditions. See our Responsive images tutorial for an example.
usemap: Option<&'life str>
§width: Option<&'life str>
The intrinsic width of the image in pixels. Must be an integer without a unit.
Trait Implementations§
source§impl<'life> Ord for Img<'life>
impl<'life> Ord for Img<'life>
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere Self: Sized,
source§impl<'life> PartialEq<Img<'life>> for Img<'life>
impl<'life> PartialEq<Img<'life>> for Img<'life>
source§impl<'life> PartialOrd<Img<'life>> for Img<'life>
impl<'life> PartialOrd<Img<'life>> for Img<'life>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more