Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8315865
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T21:13:40+00:00 2026-06-08T21:13:40+00:00

I noticed that if I only specify one dimension of an image, either using

  • 0

I noticed that if I only specify one dimension of an image, either using the width and height attributes on the img tag or using CSS, the browser automatically scales the other dimension proportionally.

For example, if I have a 100×150 image, and I specify width="50" or width:50px;, the browser automatically sets the height to 75 pixels.

Does this does this behavior apply to all browsers? Can I omit one just to save time? I’m preloading images with JavaScript and inserting them dynamically, so I don’t have to worry about the images affecting the layout while downloading.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T21:13:41+00:00Added an answer on June 8, 2026 at 9:13 pm

    Yes, this is part of the CSS2 specs:

    […] if ‘width’ has a computed value of ‘auto’, ‘height’ has some
    other computed value, and the element does have an intrinsic ratio;
    then the used value of ‘width’ is:

    (used height) * (intrinsic ratio)
    

    Defined CSS width or height will scale them properly in any CSS2 compliant browser (I tested it in IE6 and above).

    And I consider this a very useful feature. Assume I have a forum with 800px width layout and I allow users to upload images. Setting posts’ images to max-width:790px without a defined height (height:auto as per default) will automatically make them fit without breaking my layout while keeping the correct aspect ratio. Neat stuff. Note: max-width isn’t supported in IE6.

    Obviously, the same applies if you define a CSS height having width:auto.

    And here’s a Fiddle for testing. Apparently, HTML attributes will also scale properly in virtually all browsers. But I do still recommend doing the element styling with CSS, for the consistency and keeping the markup clean. Styling should be done through CSS.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When plotting in R using ggplot, I've noticed that sometimes if you don't specify
I noticed that when linking boost libraries in VS2010, I only need to specify
Working in Delphi7 just now, I noticed that not only a VarIsEmpty function exists,
I noticed in the Java 6 source code for String that hashCode only caches
I've noticed from here that the contents is only the header Revision 16532: /tags/3.3.2.SR1/samples/richfaces-demo/src/main/java/org/richfaces/demo/dataTableScroller
I noticed that there are two sets of Hadoop configuration parameters: one with mapred.*
I noticed that the first creation of an image from an uri takes pretty
I noticed that I can't combine --traditional options with the other one letter other
I've noticed that there are many static methods in FCL that affect only single
I'm testing some threading code, and using LinqPad I noticed that I'm able to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.