Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

HTML Introduction to HTML and CSS (2016) HTML: The Structural Foundation of Web Pages and Applications Image Tags

jordan Buckhalt
jordan Buckhalt
1,606 Points

CSS vs HTML image styling

I'm seeing that I can styling the size of an image with either the width and height attributes in HTML, or in CSS. Is one better or more preferable than the other?

1 Answer

Steven Parker
Steven Parker
231,261 Points

My approach may not be universal, but if I'm loading an image of a known size, I place the dimensions in the tag attributes. But I only do this for the image's actual size.

If i'm modifying the image, including displaying it in a size other than how it is stored, I will use CSS instead.

jordan Buckhalt
jordan Buckhalt
1,606 Points

That's a good rule of thumb to follow. Seems pretty logical. Thanks Steven!