<Image> component. It allows displaying either a single image for all themes (src) or one image per light theme (src) and one image for the dark theme (darkSrc).
Additionally, you can specify the href property, making an image double as a clickable link. When doing so, the target property allows to change the browsing context of the link.
Finally, to adjust image dimensions in pixels, use height or width properties. By default, all images use 16:9 aspect ratio and set height to 342px and width to 608px.
Import
Usage
Show images using the<Image> component.
<Image> props
Implementation: image.jsx
The <Image> component accepts the following props:
src (required)
type: string
The image file URL. The file path should be given either relative to the current .mdx file’s location or absolute, assuming the root of the documentation repository is the / directory.
Examples:
<Image src="<IMAGE>" />— relative path to an image placed in the same folder as the current.mdxfile.<Image src="/resources/images/<IMAGE>" />— absolute path to an image in theresources/images/sub-folder.
alt
type: string default:
""
The textual replacement for the image. It is mandatory and incredibly useful for accessibility — screen readers read the attribute value out to their users so they know what the image means. Alt text is also displayed on the page if the image can’t be loaded for any reason, such as network errors, content blocking, or link rot.
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 attribute 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.
See more: alt attribute on the <img> image embed element, MDN.
darkSrc
type: string default:
src value
Similar to the src property, but specifies the image file URL for the dark theme only.
darkAlt
type: string default:
alt value
Similar to the alt property, but specifies the image file URL for the dark theme only.
href
type: string
The <a> anchor element wraps the image, making it clickable. The href property is a URL that the clickable image hyperlink points to.
See more: href attribute on the <a> anchor element, MDN.
target
type: "_self" | "_blank" | "_parent" | "_top" | "_unfencedTop" default:
"_self"
The <a> anchor element wraps the image, making it clickable. The target property specifies where to display the linked URL, as the name for a browsing context (a tab, window, or <iframe>).
The following types have special meanings for where to load the URL:
_self: the current browsing context. (Default)_blank: usually a new tab, but users can configure browsers to open a new window instead._parent: the parent browsing context of the current one. If there is no parent, behaves as_self._top: the topmost browsing context, i.e., the “highest” context that’s an ancestor of the current one. If there are no ancestors, behaves as_self._unfencedTop: allows embedded fenced frames to navigate the top-level frame.
target attribute on the <a> anchor element, MDN.
height
type: string | number default:
342 (pixels)
The intrinsic height of the image, in pixels. Must be specified without a unit and be within the inclusive range from 9 to 608.
If the width property is not set, then the width of the image is adjusted according to the current aspect ratio in respect to the new set height.
Examples:
<Image src="<IMAGE>" height="100" />— height of 100 pixels given in a string.<Image src="<IMAGE>" height={50 + 50} />— also the height of 100 pixels, but given as a number.
height attribute on the <img> image embed element, MDN.
width
type: string | number default:
608 (pixels)
The intrinsic width of the image, in pixels. Must be specified without a unit and be within the inclusive range from 9 to 608.
If the height property is not set, then the height of the image is adjusted according to the current aspect ratio in respect to the new set width.
Examples:
<Image src="<IMAGE>" width="100" />— width of 100 pixels given in a string.<Image src="<IMAGE>" width={50 + 50} />— also the width of 100 pixels, but given as a number.
width attribute on the <img> image embed element, MDN.
center
type: boolean default:
false
Whether to horizontally center the image.
Usage: <Image src="<IMAGE>" center={true}/>.
noZoom
type: boolean default:
false
Whether to disable the image zoom.
Usage: <Image src="<IMAGE>" noZoom={true}/>.