Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I create a max-width and max-height effect on an image sent in an HTML email?

Tags:

css

html-email

My app sends out HTML emails containing one or more images of unknown size and width/height ratios. The effect I want is

<img style="max-width: 200px; max-height: 200px;" src="..." />

however, it seems like most email clients, including Gmail and Outlook 2010, ignore this css. Simply setting width and height doesn't work because the image is not square, and I don't know the size and ratio ahead of time.

like image 561
David Smith Avatar asked Mar 30 '11 12:03

David Smith


People also ask

How do you change the width and height of an image in HTML?

The height and width of an image can be set using height and width attribute. The height and width can be set in terms of pixels. The <img> height attribute is used to set the height of the image in pixels. The <img> width attribute is used to set the width of the image in pixels.

How do I change the maximum width of an image?

The max-width property sets a maximum width for an element, which does not allow the width of that element to be larger than its max-width value (but it can be smaller). Therefore, you can define a max-width property for the image and set it to 100%, which shrinks the image of 500px to the space of 360px.


1 Answers

With unknown sizes of images, the programmatic route will work: while processing/building your email, you'll have to peek at the dimensions of the images and set the height and width accordingly in the html.

This way you'll be sure to have correctly scaled images across all (or most:) ) clients.

like image 154
Groovetrain Avatar answered Sep 21 '22 07:09

Groovetrain