question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

gatsby-image: Add the ability to have className on actual img element

See original GitHub issue

Summary

I have a requirement to add className to the actual <img> element to support microformats.

Currently GatsbyJs only has

  • ClassName - on the wrapper only
  • placeholderClassName - on the placeholder <img>

There is no support for the actual <img> element.

Basic example

<Img
  fluid={data['profilePic'].childImageSharp.fluid}
  alt={`Ben Shi`}
  className={'avatar'}
  imgClassName={'u-photo'}
/>

Motivation

In microformats u-photo is only valid on (<img src>) elements. gatsby-image both fixed and fluid does not support this. http://microformats.org/wiki/microformats-2-implied-properties

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:8
  • Comments:13 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
isaac-martincommented, Jul 21, 2020

We would like to be able to pass down the css generated by emotion to the img element and it is currently not possible with the current gatsby image component. Any update - to me it looks like the change suggested in #24161 would solve this?

1reaction
steffik02commented, Oct 13, 2020

Just thought I’d add that I need this functionality as well, or the ability to pass data attributes to the tag. I’m trying to add an attribute to prevent pinning to Pinterest with certain images and I can’t get the attribute on the actual img tag. If I could at least get a class name on there, then I could add the attribute with Javascript.

Read more comments on GitHub >

github_iconTop Results From Across the Web

React Gatsbyjs add class to gatsby-image based on aspect ratio
When I map over all my gallery images, I can grab the aspect ratio and add it to each gatsby-image-wrapper using className but...
Read more >
Gatsby Image plugin
The Gatsby Image plugin includes two components to display responsive images on your site ... The StaticImage component can take all image options...
Read more >
3 Ways to display images in Gatsby JS - YouTube
Plus I'll give you a hot tip on how to utilize bootstrap with Gatsby Img. If you want to jump around: 3:57 |...
Read more >
In Depth gatsby-image Tutorial - YouTube
In this video from my Gatsby Basics course I walk through how to use the Gatsby Image component in a number of different...
Read more >
Create a Lazy-Loading Image Component with React Hooks
A "load" event listener is added to the source img element so when it finishes loading, the state is updated and a "loaded"...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found