Popoola Fareedah
PRO
3 months ago
Popoolacountry asked

I'm confused about why height: auto; is used for an image.

Kelish Rai
Expert
3 months ago
Kelish Rai answered

I see you just completed the CSS Box Model project. If you're asking about height: auto;, I assume you're referring to this CSS rule:


.course-image {
    width: 160px;
    height: auto;
    margin-bottom: 16px;
}

The height: auto; rule allows images with the .course-image class to adjust their height automatically based on their width while maintaining their original aspect ratio.

Since we’ve only set the width, the image will scale proportionally—its height will adjust automatically to prevent distortion.

Hope this clears things up. If you have more questions, feel free to ask it below. I'm happy to help.

CSS
This question was asked as part of the Learn CSS course.