Responsive Images


Responsive images are images that scale nicely to fit any browser size.

Using the width Property

If the CSS width property is set to 100%, the image will be responsive and scale up and down:

 

Responsive Image

When the CSS width property is set in a percentage value, the image will scale up and down when resizing the browser window. Resize the browser window to see the effect.

 

Example

<img src="/images/cat.jpg" style="width:100%;">

 

Notice that in the example above, the image can be scaled up to be larger than its original size. A better solution, in many cases, will be to use the max-width property instead.


Live Demo & Try it yourself! Read More » »

Using the max-width Property


Using the max-width Property

If the max-width property is set to 100%, the image will scale down if it has to, but never scale up to be larger than its original size:

 

Responsive Image

"max-width:100%" prevents the image from getting bigger than its original size. However, if you make the browser window smaller, the image will still scale down.

Resize the browser window to see the effect.

Example

<img src="/images/cat.jpg" style="max-width:100%;height:auto;">


Live Demo & Try it yourself! Read More » »

Show Different Images Depending on Browser Width


The HTML <picture> element allows you to define different images for different browser window sizes.

Resize the browser window to see how the image below changes depending on the width:

 

Show Different Images Depending on Browser Width

Resize the browser width and the image will change at 600px and 1500px.

Flowers

 


Live Demo & Try it yourself! Read More » »