Properly setting Class selectors in CSS

Does that mean we should always use inline styling for images or just use the html width and height attribute?

Or is this only limited to some specific coding?

I am just asking as I didn’t know about this before?

It is best practice to avoid in-line styling and keep CSS separate from HTML. It’s good to include height and width attributes on images so the browser can create the correct space for them in the layout before they have finished loading.
It is quite alright to have CSS setting image size that may override the attributes. Where an images is large enough that it won’t fit in a small screen you certainly should have CSS to resize the image and make it responsive.

1 Like

Is it still appropriate to use the html width and height attribute or are they trying to remove all html styling’s to only be used on CSS?

Will it still have the same effect if we used it in the style tags on the page, will it be faster or is it the same as applying external stylesheets?

The point is that both the height and width attributes are NOT styling attributes - they are there to give the browser information about the image it is to expect and reserve space for.

You ‘could’ alter those dimensions inside an inline style attribute, but best practice would be to move the styling task out into a separate CSS file.

Thanks alot :slight_smile:

I always thought of width and hight as a styling since html is all about putting the elements on the page everything else depends on css that includes measurements so I guess I just always thought of it a “styling”

But thanks for the tip on Images because I always only apply the src and alt to images and everything else beyond that was just CSS doing :slight_smile:

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.