Bird
Raised Fist0
HTMLmarkup~5 mins

Image sizing basics in HTML - Cheat Sheet & Quick Revision

Choose your learning style10 modes available
Recall & Review
beginner
What attribute controls the width of an image in HTML?
The width attribute controls the width of an image in HTML. You can set it in pixels or as a percentage.
Click to reveal answer
beginner
How do you keep an image's aspect ratio when resizing it?
To keep the aspect ratio, set only width or height, not both. The browser adjusts the other dimension automatically.
Click to reveal answer
beginner
What CSS property can you use to control image size?
You can use the CSS properties width and height to control image size. For example, img { width: 50%; height: auto; }.
Click to reveal answer
beginner
What happens if you set both width and height attributes to different proportions than the original image?
The image will stretch or squash, changing its original shape and possibly looking distorted.
Click to reveal answer
intermediate
Why is it better to use CSS for image sizing instead of HTML attributes?
Using CSS separates content from design, making it easier to update styles and keep HTML clean. CSS also offers more control and responsiveness.
Click to reveal answer
Which attribute sets the width of an image in HTML?
Awidth
Bsize
Clength
Dscale
If you want to keep an image's shape, what should you do when resizing?
ASet both width and height to new values
BSet only width or only height
CSet width and height to zero
DUse the <code>size</code> attribute
Which CSS property is used to control image height?
Amargin
Bfont-size
Cheight
Dpadding
What is the visual effect of setting width and height to values that don't match the image's original ratio?
AImage stretches or squashes
BImage becomes blurry
CImage disappears
DImage stays the same
Why is CSS preferred over HTML attributes for image sizing?
ACSS is faster to write
BHTML attributes don't work in modern browsers
CCSS makes images load faster
DCSS allows better control and responsiveness
Explain how to resize an image in HTML while keeping its original shape.
Think about which attribute to set to avoid distortion.
You got /4 concepts.
    Describe the difference between resizing images using HTML attributes and CSS.
    Consider how design and content are managed.
    You got /4 concepts.

      Practice

      (1/5)
      1. Which HTML attribute is used to set the width of an image directly in the tag?
      easy
      A. width
      B. size
      C. length
      D. scale

      Solution

      1. Step 1: Identify image sizing attributes

        The width attribute is used in the <img> tag to set the image width in pixels or percentage.
      2. Step 2: Confirm correct attribute name

        Among the options, only width is a valid HTML attribute for image sizing.
      3. Final Answer:

        width -> Option A
      4. Quick Check:

        Image width attribute = width [OK]
      Hint: Use width or height attributes for quick sizing [OK]
      Common Mistakes:
      • Confusing size with width
      • Using CSS property names as HTML attributes
      • Trying to use scale which is not valid
      2. Which of the following is the correct way to set an image width to 200 pixels in HTML?
      easy
      A. <img src='photo.jpg' width='200px'>
      B. <img src='photo.jpg' style='width: 200'>
      C. <img src='photo.jpg' width='200'>
      D. <img src='photo.jpg' height='200px'>

      Solution

      1. Step 1: Understand HTML attribute value format

        In HTML, the width attribute expects a number representing pixels without units.
      2. Step 2: Check each option

        <img src='photo.jpg' width='200px'> uses '200px' which is invalid for the width attribute. <img src='photo.jpg' width='200'> correctly uses '200' without units. <img src='photo.jpg' style='width: 200'> uses CSS syntax incorrectly inside an attribute. <img src='photo.jpg' height='200px'> sets height, not width.
      3. Final Answer:

        <img src='photo.jpg' width='200'> -> Option C
      4. Quick Check:

        Width attribute value is number only [OK]
      Hint: Use numbers only for width/height attributes, no units [OK]
      Common Mistakes:
      • Adding 'px' units inside width or height attributes
      • Confusing CSS style syntax with HTML attributes
      • Setting height instead of width by mistake
      3. What will be the visual result of this HTML code?
      <img src='flower.jpg' width='150' height='100'>
      medium
      A. Image not shown due to invalid attributes
      B. Image shown with width 150px and height 100px, possibly distorted
      C. Image shown with height 100px, width auto to keep ratio
      D. Image shown with width 150px, height auto to keep ratio

      Solution

      1. Step 1: Understand width and height attributes together

        When both width and height are set, the image is forced to those exact dimensions, ignoring original proportions.
      2. Step 2: Predict visual effect

        Because the original image ratio may differ, forcing both width and height can distort the image shape.
      3. Final Answer:

        Image shown with width 150px and height 100px, possibly distorted -> Option B
      4. Quick Check:

        Both width and height set = fixed size, possible distortion [OK]
      Hint: Setting both width and height fixes size, may distort image [OK]
      Common Mistakes:
      • Assuming height auto adjusts when both attributes set
      • Thinking image keeps original ratio automatically
      • Believing invalid attributes cause image not to show
      4. Identify the error in this HTML code for sizing an image:
      <img src='cat.png' width='300' height='auto'>
      medium
      A. Using 'auto' in height attribute is invalid in HTML
      B. Using '300' without units in width attribute is invalid
      C. Missing closing slash in <img> tag
      D. No error, code is correct

      Solution

      1. Step 1: Check width attribute value

        The width attribute correctly uses the number '300' without units.
      2. Step 2: Check height attribute value

        Height attribute does not accept 'auto' as a value in HTML attributes; it only accepts numbers.
      3. Final Answer:

        Using 'auto' in height attribute is invalid in HTML -> Option A
      4. Quick Check:

        Height attribute must be number, not 'auto' [OK]
      Hint: Height and width attributes accept only numbers, no 'auto' [OK]
      Common Mistakes:
      • Using CSS values like 'auto' in HTML attributes
      • Thinking <img> needs closing slash in HTML5
      • Thinking width attribute requires 'px' units
      5. You want an image to always fill the width of its container but keep its height proportional. Which CSS style should you use?
      hard
      A. width: auto; height: auto;
      B. width: auto; height: 100%;
      C. width: 100px; height: 100px;
      D. width: 100%; height: auto;

      Solution

      1. Step 1: Understand responsive image sizing

        Setting width: 100% makes the image fill the container's width.
      2. Step 2: Maintain aspect ratio

        Setting height: auto lets the browser calculate height to keep the image's original proportions.
      3. Final Answer:

        width: 100%; height: auto; -> Option D
      4. Quick Check:

        Width 100% + height auto = responsive proportional image [OK]
      Hint: Use width 100% and height auto for proportional responsive images [OK]
      Common Mistakes:
      • Setting fixed height breaks aspect ratio
      • Using auto width with fixed height distorts image
      • Setting both width and height fixed loses responsiveness
      Recommended

      Ready to prove it?

      Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

      10 questions~5 mineasy hard