Skip to content

Using Gatsby Image with Picture tag? #7313

@deadcoder0904

Description

@deadcoder0904

Summary

I want to use gatsby-image with the picture tag. I need to use picture tag because I have different images for mobile, tablet & desktop resolutions.

Relevant information

This is the current way I do it. Is this the right approach?

<picture>
        <source
          media="(max-width: 560px)"
          srcSet={data.mobile.childImageSharp.fluid.src}
        />
        <source
          media="(max-width: 875px)"
          srcSet={data.tablet.childImageSharp.fluid.src}
        />
        <Img src={data.desktop.childImageSharp.fluid.src} />
</picture>

Because its used like this in the docs & I don't know if the method above is right

<Img resolutions={data.file.childImageSharp.resolutions} />

I need 2 things from what I'm doing:

  1. Optimized Images with Traced SVG in Pages
  2. Different Images for Mobile, Tablet & Desktop

Is it right what I'm doing or is there another approach?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions