WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

If I add an image to a post, WordPress hardcodes width and height attributes to the img tag.

I added max-width:100% to my CSS, but of course, if my browser window gets smaller, the resized image gets stretched in height.

What can I do about it?

Is there a way to:

A: Solve it with CSS (I would prefer that)?
B: Forbid WP to hardcode width and height?
C: Is there a common way of dealing with image widths, I'm not aware of?

share|improve this question
up vote 2 down vote accepted

A + C:

img.resize-proportionally {
    max-width: 100%;
    height: auto;

As an aside, for the above to work, you shouldn't attempt B.
Having width and height attributes in the img tag is good.

share|improve this answer
Thank you! I'm sorry, I should have tried this. I just thought, it wouldn't work, because height="XXX" would be "stronger". – Sebastian Starke Jul 11 '13 at 11:01

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.