If height
and width
are set, the space required for the image is reserved when the page is loaded.
However, without these attributes, the browser does not know the size of the image, and cannot reserve the appropriate space to it.
The effect will be that the page layout will change during loading.
...
Let’s say we have a page
<h1>Heading</h1>
<p>Introduction</p>
<img src="flower.jpg" alt="Flower">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore...</p>
Before the image is loaded > After the image is loaded
Since this image doesn’t have a height
and width
, it will show no layout till the HTML downloads the image. Once the image is downloaded the text after the image will jump to make way for the image on the page.
These layout shifts are very distracting for the user, suppose you are reading an interesting article and suddenly some images are downloaded and the jolt of the movement throws you off on the screen and you have to find where to start again.
So providing an appropriate height
and width
to the image was advisable.
The limitations of responsive images have been known for a long time and many workarounds, including the so-called padding-bottom hack, have been created to work around the issue.
This shows that padding percentages (including padding-bottom) are always based on the container width (to ensure consistent padding even if height and width differ).
This fact can be used to create a container where the height is set based on a width ratio.
But it has a few problems associated with it too:
And, let’s be honest — it’s a bit of a hack! So, we really should fix this properly, shouldn’t we?
aspect-ratio
img { width: 100%; height: auto; aspect-ratio: 16/9; }
intrinsicsize
<img intrinsicsize="400x400" style="width: 100%">
attr
<style>
img {
width: 100%;
height: auto;
aspect-ratio: attr(width) / attr(height);
}
</style>
<img src="flower.jpg" alt="" width="500" height="500">
Rather than hard-coding the aspect ratio
this uses the CSS attr
to calculate the aspect ratio using the width and height of the image
Because this is just a CSS attribute the proposal contained an added twist- this could be added to the user-agent stylesheet used by browsers so would not even require any changes from web developers to benefit from this.
Firefox did include this as an experiment which made the browser more performant. After Firefox's successful implementation and results many other browsers also started to implement this in their respective browsers- but not all YET!
There are a few limitations to this though:
Types of Rich Text Editors In the previous post I explained what are RTEs and why are they used, in this post, I am going to throw some light on the types of RTEs, and will make you familiar with the sample content format. https://fifo.im/p/35ghmd1uxln0
Rich Text Editor In recent years, the field of Content Creation and Representation on Digital platforms has seen massive disruption. This transition has shown how companies are racing to build the best experience for content creators in the enterprise domain and trying to find innovative ways to break the traditional molds of sharing and consuming content.