0

Fairly new at this, but what’s the benefit to defining image height/width in a linked Css over defining it inline attribute of the img tag? Everything I’m seeing points to defining the img size in Html as better since the browser will load the page faster with the proportions in mind without having to track them down elsewhere, but the whole point of separating the two is to keep things like sizes and colors outside the main html and clean up everything.

Thanks!

30ozSteak
  • 1
  • 1
  • 1
    https://stackoverflow.com/questions/640190/image-width-height-as-an-attribute-or-in-css – Alvin Apr 18 '18 at 13:45

2 Answers2

0

I would suggest:

  • 1) Define the original size value in HTML om the img tag.
  • 2) Add an "id" to your img tag in HTML
  • 3) With the "id" tag, add it as reference in CSS and adjust the size based on %.

The benefit of doing it like this is that you will control the size from CSS but anyhow have a standard size defined in HTML.

Toolbox
  • 2,333
  • 12
  • 26
0

Using inline style is hardly ever a good approach.

Using classes allows other developers to modify your code much easier. Also managing properties via classes is a standard everyone uses. Nobody will look for them coded inline.

There are really many reasons why you should define your styles somewhere else than inline. You should take a read here and search stackoverflow/google as this question has been asked many times before.

Kacper Cieluch
  • 437
  • 3
  • 16
  • However, what OP says is not exactly inline styling but html attributes. Could there be any benefit using them? https://stackoverflow.com/questions/640190/image-width-height-as-an-attribute-or-in-css – treecon Apr 18 '18 at 13:52
  • html attributes are still inline attributes. I've been working with cloudinary api where you could define html attributes to load specific type of image from the server - cropped, with borders etc - and that's the only case I would consider using html attributes. – Kacper Cieluch Apr 18 '18 at 13:57