This link comes very close to my question, but seems to apply to syntax more than to actual rendered output:
I see that image height and width can be defined in the actual html img
tag, in fact the way I read it it should be defined there. However, I am wondering about what matters when it actually comes to how the image is displayed. If I insert the following code
<img src="images/academia_vs_business.png" width="740" height="382" alt="" />
with no css stlying applied to the image, will it be rendered at it's native width and height?
If I do add css styling to that image, as in
img {
width: 400px
}
Will it overrule the width
attribute of the html?
If I do not specify the height and width of an image in the html, is the only problem that I am not conveying the actual image size to a non-visual user agent or are there other problems (such as the browser can't allocate space for the imgs
during page load).
Isn't specifying size in the html tags redundant if the css is going to change image size anyway?
I guess this all could be summed up as the best practice to place and size images and I would love to hear others techniques.
It's usually better to use CSS to resize images in HTML. You can do this with the height and width properties. This image is resized using the CSS 'width' and 'height' properties.
We can resize the image by specifying the width and height of an image. A common solution is to use the max-width: 100%; and height: auto; so that large images do not exceed the width of their container. The max-width and max-height properties of CSS works better, but they are not supported in many browsers.
One of the simplest ways to resize an image in the HTML is using the height and width attributes on the img tag. These values specify the height and width of the image element. The values are set in px i.e. CSS pixels.
From the W3C website:
The UA may choose to honor presentational attributes in an HTML source document. If so, these attributes are translated to the corresponding CSS rules with specificity equal to 0, and are treated as if they were inserted at the start of the author style sheet. They may therefore be overridden by subsequent style sheet rules. In a transition phase, this policy will make it easier for stylistic attributes to coexist with style sheets.
See this answer to this question for more details
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With