r/HTML • u/No-Tea5041 • Sep 19 '26
What am I doing wrong?
No matter what numbers I enter, I always get it wrong. I even used smaller numbers for height and larger for width incase they got it mixed up. Their AI is telling me to do everything I am already doing
4
Upvotes
View all comments
Show parent comment
1
u/ArgoWizbang Sep 20 '26
The attributes absolutely should still be used, mostly because the attributes' main uses are not for styling but rather to help prevent layout shift. Having that information directly available in the
<img>tag allows the browser to quickly determine the image's aspect ratio and properly reserve space for the image before it finishes downloading thus reducing CLS. Then CSS comes into effect and determines how the image should actually be displayed. Sure, you can set the aspect ratio in the CSS instead but if you already for sure know the image's proper dimensions then putting that information in the HTML as well is just a good practice to hold on to.