How do I check the image's view mode in the image.html.twig template?
If you're using a Media entity, you can check the view mode in the media template: media.html.twig:
From the media.html.twig file documentation:


view_mode: View mode; for example, &quot;teaser&quot; or &quot;full&quot;.


This would let you add the class to the image parent &lt;div&gt;.
If you want to target only images, you can do this:
media--image.html.twig
And if you want to target only images with the view mode abc, you can do this:
media--image--abc.html.twig