How to make images responsive

On This Page What is a Responsive Image?Using Comparative UnitsJune 03, 2026 · 12 min read · Testing Guide

How to make images responsive

Web pages ofttimes break or look distort when images don ’ t adjust to different blind sizes and devices. Antiphonal images clear this challenge by adapting seamlessly to any declaration, ensuring ordered design, better user experience, and improved performance.

Overview

Responsive ikon are ikon that mechanically scale, resize, and adjust to fit different devices and screen resolutions without losing lineament or breaking the layout.

How to Make Images Responsive:

  • Using Media Queries:Define image behavior for different screen size through CSS breakpoints.
  • Using Relative Units:Set image width in part instead of fixed pixels so it scale fluidly with the container.
  • Images on a Fluid Layout:Place images inside flexible container so they adapt to the layout.
  • Understanding the max-width Property:Set max-width: 100 % to foreclose images from transcend their container size.
  • Images for Non-Supporting Browsers:Provide disengagement options to ensure compatibility across senior browsers.

This usher covers the best praxis for making image reactive.

What is a Responsive Image?

A responsive image is an persona that is optimize to adapt to different screen sizes and resolutions. When a website is accessed on different devices, the images should resize and adjust their layout to ensure that they seem good and stay amply visible. This is important for providing a seamless and engross user experience, regardless of the twist used to access the website.

In real-world usage, that means that the image should have the following attributes/abilities:

  • The image should be capable to supply crisply at different device-pixel-ratios. That means high-resolution screens expose high-resolution images, but low-res screens should not have to deal with the extra pixels.
  • In the case of a fluid (responsive) layout, icon need to stretch or squeeze to align with its changes.
  • For both the above cases, image will have to be made responsible in multiple declaration so that they can scale accordingly.

Different browsers support diverse image format. Newer formats like WebP may not be compatible with every browser, in which lawsuit images will experience to be made available in JPEG format as good.

Read More:

Using Relative Units

Here ’ s how you can apply different CSS techniques to ensure your images adjust seamlessly across device and screen sizes:

When an image is upload to a website, it has a default meridian and width that may not adapt to different.

To make an image responsive, simply set its width property in CSS utilise relative units (e.g., percentages) alternatively of rigid pel. This allows the image to scale dynamically, with the height align mechanically to maintain proportions.

Example:

img {breadth: 800px;}

The code above sets a fixed width of 800px. This ikon won ’ t be antiphonal as the unit is sheer and won ’ t adjust itself. However, look at the code below:

img {width: 70 %;}

With a comparative unit like 70 % in place, the image will be fluid and resize itself, whatever the blind sizing.

Must Read:

Using Media Queries

or CSS breakpoints are points delimitate in the codification. Website content responds to these points and adjusts itself to the screen size to display the accurate layout. With CSS breakpoints in property, the website content will align itself with screen size and show itself in a way that please the eye and alleviate visual consumption.

Learn everything you need to know about.

Obviously, responsive picture require the use of media queries to resize themselves across to device screen size.

In the instance below, the image carries a 50 % width for any screen. In order to make them maximize to full size for any mobile devices, use media queries:

@ media but screen and (max-width: 560px) {img {width: 100 %;}}

By virtue of the medium interrogation above, any device with a blind size smaller than 480px will have the image take full-size along the blind ’ s width.

Also Read:

Images on a Fluid Layout

Creating responsive images on a fluid is a little more challenging. On most site, ikon are the heaviest elements and ask to start (and cease) laden before anything else. Therefore, browsers start out by scanning a web page ’ s HTML for image URLs and charge them. This happens before the browser builds the, puts the layout together, or loads external CSS.

Consequently, the browser needs to know the image beginning even before they detect the image ’ s rendered size.

Keep in head that the browser mechanically know the environments all web elements are rendering in: viewport size, users ’ screen resolution, etc. This information is used to define medium inquiry. Therefore, to align persona to a fluid layout, devs can too delineate the ikon ’ rendered sizing to the browser.

Let the browser know how many pixels are required by using the sizesattribute. Use thew descriptors in srcsetto communicate the turn of pel in each image rootage. Armed with this datum, the browser can select the smallest image source that will allow the image to look presentable within its viewport.

Here take an example in which there are three image sizes:

  • large.jpg (1024 × 768 pel)
  • medium.jpg (640 × 480 pixels)
  • small.jpg (320 × 240 pixels)

These images have to be placed in a flexible grid & # 8211; one that starts from a single column, but in larger viewports, transforms into three columns:

& lt; img srcset= '' large.jpg 1024w, medium.jpg 640w, small.jpg 320w '' sizes= '' (min-width: 36em) 33.3vw, 100vw '' src= '' small.jpg ''

The code usessrcset with w descriptorsto advert image sources & # 8211; which intercommunicate the actual pel widths of the referenced file to the browser.

In this example, but image breadth is defined, not height. In this particular case, images in the layout get breadth institute explicitly by CSS but not their peak. Most responsive images run to be the same, so this keeps things simple.

While the w descriptordelimit the act of pixel for each image beginning, thesize attributerelates to the browser how many pixels it needs by defining the image ’ s terminal rendered breadth. It volunteer the browser some datum about the page ’ s layout early on to help it pick an image rootage before it renders the page ’ s CSS code.

For autonomous testing across multiple user personas, check out SUSATest — it explores your app like 10 different real users.

Learn more:

Like what you are reading?

You can start discussing with our strife community

Understanding the max-width belongings

To make ikon responsive, it is mutual for developers and designers to use the max-width place. It defines the maximal width for an element; no factor can be wider than its max-width value.

That mean that if an persona carries the max-width of 800px and is being render on a screen size of but 360px, the device won ’ t display the complete image due to lack of space.

img {max-width: 100 %; breadth: 800px; // assume this is the nonpayment size}

By defining the max-width and lay it to 100 %, the 800px persona will shrivel to fit the space on the 360px device. Using a proportional unit (as shown above) will make the image fluid on any device less than 800px.

However, if the screen sizing is larger than 800px, the image will not expand to fit the like. This adversely impact its reactivity. This is where the max-width holding fall short.

Read More:

Images for Non-Supporting Browsers

Consider an representative where an image ’ s format is uncongenial with certain browser. This usually bulge up when older browser get to render images in raw format. In such cases, use the codification below:

& lt; picture & gt; & lt; source type= '' image/svg '' src= '' logo.svg '' / & gt; & lt; source type= '' image/png '' src= '' logo.png '' / & gt; & lt; img src= '' logo.gif '' alt= '' Responsive '' / & gt; & lt; /picture & gt;

Note: Replace alt= & # 8221; Responsive & # 8221; with the relevant image name.

In case the browser can not decipher the image/svgmedia character, it skips the inaugural source. If it can & # 8217; t work withimage/png, then it ends up using the.gif file.

Also Read:

How to make background persona responsive

Here ’ s how to create responsive background images with CSS:

  • Use the background-size property to encompass the viewport. Give this property a cover value that will tell a browser to scale the background image ’ s heights and width so that they forever remain equal to or outstanding than the height/width of the device viewport.
  • Use a media query to offer scaled-down versions of the background image for mobile gimmick blind. This is an optional footstep; given the far-flung usage of mobile devices, it should be contain into the process.

Example:

& lt;! doctype html & gt; & lt; html & gt; & lt; body & gt; ... Write your content hither ... & lt; /body & gt; & lt; /html & gt;

The background image goes in the body element so that it always continue the full browser viewport.

Note that the codification will also act perfectly on block-level elements (a div or form). As long as the height and width of the block-level container is fluid, the background icon will scale in order to cover the container in its entirety.

Now, announce the style rule for the body element with:

body {/ * Location of the persona * / background-image: url (images/background-photo.jpg); / * Background image is center vertically and horizontally at all clip * / background-position: eye center; / * Background ikon do n't tile * / background-repeat: no-repeat; / * Background image is secure in the viewport so that it does n't move when the substance 's meridian is great than the picture 's height * / background-attachment: fixed; / * This is what get the background image rescale based on the container 's sizing * / background-size: cover; / * Set a background color while the ground image is loading * / background-color: # F8FAFD;}

A few note on the code

Pay particular attention to:

background-size: cover;

This property/value pair teach the browser to set the background image so that its height and width are adequate to the height and breadth of the element; here, the body element.

However, if the background image is smaller than the body element, the browser will programmatically expand the image attribute. Magnifying an image beyond its natural dimension usually get it to degrade. This scenario normally bulge up on high-res screens or on page with far too much content.

To obviate this, try to use an image large enough for most screen sizes and resolutions.

background-position: center heart;

This is used to ensure that the background image always continue at the center of the viewport.

background-attachment: limit;

A scroll bar appears in suit where the content height is more than that of the visible viewport. But the background image must abide in its place even if the user scrolls downwards. Setting the background-attachment property (as done above) ensures this.

Learn More:

Test Image Responsiveness on Real Devices

Ensuring images adapt correctly across devices requires testing on real screen, not just emulators.

BrowserStack Liveprovide instant access to a huge range of existent devices and browser, helping you verify responsiveness with precision.

Why Use BrowserStack for Testing Responsive Images?

  • Test on : Access 3,500+ existent browsers and deviceto check how images render across different blind sizes.
  • Instant Access: No setup required—just choose a gimmick, enter your website URL, and part testing.
  • Accurate Results: Emulators and simulator can ’ t copy real-world behavior—test on actual device for reliable results.
  • Antiphonal Design Checker: Quickly preview your website on multiple devices and ensure breakpoints work as destine.
  • : Verify ikon scaling across browsers, including Chrome, Firefox, Safari, and Edge.

Talk to an Expert

Conclusion

Making images responsive ensures they scale properly across different screen sizes, improving user experience and website performance. Flexible sizing, proportional units, and proper testing can conserve ikon quality and layout consistency across devices.

Implementing these best practices helps make a visually invoke and accessible website for all exploiter.

Once implemented, it & # 8217; s all-important to test responsiveness on real devices.BrowserStack Liveprovides accessreal browser and devices, allowing you to verify how images interpret across.

Frequently Asked Questions

1. How can an image be made responsive?

An image can be made antiphonal by apply CSS and setting the width of the persona to be a share of its parent container, rather than a fixed pel value. This way, when the sizing of the parent container alteration (e.g. due to different screen sizes), the sizing of the image will also change proportionally.

img {max-width: 100 %; height: automobile;}

In this example, the max-width property is set to 100 %, which means that the persona will take up the entire breadth of its parent container, but won & # 8217; t exceed it. The height property is set to auto, which means that the height of the image will adjust mechanically to maintain the aspect ratio of the original image.

2. What is responsive image in HTML?

Responsive picture in HTML are picture that mechanically adjust their size establish on the size of the screen or the container they are expose in, provide an optimal viewing experience on different devices with varying screen sizes.

This can be accomplish using CSS, by position the width of the picture to a percentage of its parent container, and allowing the height to adjust mechanically to hold the aspect ratio of the original image.

3. Why are responsive images important?

  1. Improved user experience: By adapting to different blind sizes and devices, responsive icon ensure that exploiter are able to view picture in a open and well clear formatting, regardless of the device they are using.
  2. Better approachability: Reactive images make it easier for users with ocular impairments to access and understand images on a site, as they can be resize to gibe the user & # 8217; s preferred font size and screen sizing.
  3. Improved SEO: Search engines prefer websites that are optimise for different devices and blind sizes, and responsive ikon are a key aspect of this optimization.
  4. Faster page load clip: By using thesrcset and sizesattributes, you can specify different versions of the same image for different screen sizes and device, allowing the browser to choose the most appropriate image for the current blind size, amend load times and performance.
  5. Better user engagement:A smooth and consistent user experience across different device and screen sizes can lead to increased user battle and a lower bounce rate.

Overall, antiphonal images play an significant role in ensuring that a website is optimized for different device and blind sizes, providing a better user experience and improving the overall performance of a website.

4. How do I size a background image in CSS?

You can sizing a background image in CSS using thecover or contain property or by setting specific width and elevation value.

  1. Using the & # 8220; cover & # 8221; holding: This value will automatically scale the background ikon to be as large as potential so that the background area is totally covered while sustain its aspect ratio. Example: background-size: screen;
  2. Using the & # 8220; contain & # 8221; holding: This value will scale the icon to fit the container while conserve its aspect ratio, and will show any empty infinite smother the image. Example: background-size: contain;
  3. Setting specific width and elevation values: This method allow you to delimitate the exact dimensions of the background image in pixels, which can be useful if you need to fit the ikon into a specific infinite on your webpage. Example: background-size: 100px 50px;
Tags
77,000+ Views

# Ask-and-Contributeabout this issue with our Discord community.

Related Guides

Automate This With SUSA

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed.

Try SUSA Free

Test Your App Autonomously

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.

Try SUSA Free