Image is the workhorse of Pinterest. If you define Pinterest to be all about collecting ideas, then images are how we choose to represent those ideas. In response, we've added a few extra superpowers to the regular img tag to make it even more awesome.

Props

Component props
Name
Type
Default
alt
Required
string
-

Alt text read by screen readers. See MDN for more details.

naturalHeight
Required
number
-

Exact height of source image. See the Dimensions example for more details.

naturalWidth
Required
number
-

Exact width of source image. See the Dimensions example for more details.

src
Required
string
-

The URL for the image.

children
React.Node
-

Children content will be overlaid on the image. See the Overlay example for more details.

color
string
"transparent"

Used as a visual placeholder while the image is loading. See the Placeholders example for more details.

crossOrigin
"anonymous" | "use-credentials"
-

Specifies the CORS setting to use when retrieving the image. See MDN for more details.

decoding
"sync" | "async" | "auto"
-

Sends a hint to the browser specifying whether or not it is allowed to try to parallelize loading your image. See MDN for more details.

elementTiming
string
-

HTML attribute for performance profiling (see https://developer.mozilla.org/en-US/docs/Web/API/Element_timing_API). Note that it only works if the `fit` prop is not set to `"cover"` or `"contain"`.

fit
"contain" | "cover" | "none"
"none"

Sets how the image is resized to fit its container. See the Fit example for more details.
Note: this doesn't work with srcSet or sizes.

importance
"high" | "low" | "auto"
"auto"

Priority hints provide developers a way to indicate a resource's relative importance to the browser, allowing more control over the order resources are loaded (only available via Chrome Origin Trial). `"high"`: the developer considers the resource to be high priority. `"low"`: the developer considers the resource to be low priority. `auto` the developer does not indicate a preference.
Note that this feature is currently experimental; please see the attribute spec for more details.

loading
"eager" | "lazy" | "auto"
"auto"

Controls if loading the image should be deferred when it's off-screen. `"lazy"` defers the load until the image or iframe reaches a distance threshold from the viewport. `"eager"` loads the resource immediately. `"auto"` uses the default behavior, which is to eagerly load the resource. See the Lazy example for more details.

onError
() => void
-

Callback fired when the image loading has an error.

onLoad
() => void
-

Callback fired when the image successfully loads.

role
"img" | "presentation"
-

When Image is used purely as a presentational or decorative addition, the `role` should be set to "presentation" for better accessibility. See the Presentational Images with Role example for more details.

sizes
string
-

A comma-separated list of one or more strings indicating a set of source sizes.

srcSet
string
-

A comma-separated list of one or more strings indicating a set of possible image sources for the user agent to use.

Dimensions

One thing that might be unusual is that the width and the height of the
component are required, yet the image will scale to the size of its container.
This is so that the placeholder's size can be calculated before the image has
rendered.

While the exact dimensions supplied aren't used (only the ratio between them is
considered), you should always try to try to supply the exact dimensions of the
source image requested.

Placeholders

The color you pass into Image will be used to fill the placeholder that shows up
as an image loads. The example shown has an empty src prop provided so it remains
a placeholder.

Overlay

You can overlay content on an Image by passing it children.

Fit

In some cases, you may want to scale an image to fit into its container.
To achieve that, you can set fit to either "cover" or "contain", depending on the effect you wish to achieve.

"contain": This makes it so that the image is "contained" within its container. This means that the image is resized appropriately
such that the entire image can fit in the container, while maintaining its aspect ratio (think letterbox);

<Image alt="..." color="#000" fit="contain" src="..." />

"cover": This does the opposite of "contain" and tries to scale the image as large as possible so that the entire container is occupied,
while maintaining the aspect ratio of the image.

<Image alt="..." color="#000" fit="cover" src="..." />

Notes:

  • When using "cover"/"contain", naturalHeight and naturalWidth are ignored since the aspect ratio is handled by the browser.
  • In order for "cover"/"contain" to work properly, the container must have some sort of implicit height.

Lazy

You can delay loading images that are off-screen with the loading attribute. See MDN for more details.

Presentational Images with Role

Sometimes Images are purely presentational. For example, an Image used above an article title may be used to draw people's attention visually, but doesn't add any additional information or context about the article. In this case, the role should be set to "presentation" in order to inform screen readers and other assistive technology that this image does not need alternative text or any additional label.