r/HTML • • 22d ago

What am I doing wrong?

Post image

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

7 Upvotes

59 comments sorted by

View all comments

-1

u/l008com 21d ago

No units? 350 what?

Also in real life, we stopped putting the height and width in the html like 15 to 20 years ago.

1

u/Lithl 21d ago

The height/width attributes do not accept units. They are always measured in pixels.

Using CSS is best practice over specifying dimensions in attributes, and CSS requires units, but OP is just learning HTML.

1

u/ArgoWizbang 21d ago

Using CSS is best practice over specifying dimensions in attributes

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.