The Ultimate Guide to Web Images

Mastering Web Images

Welcome! This guide is designed for web designers and creators who want to stop guessing and start understanding how images work on the web. We'll demystify why images sometimes look stretched, blurry, or just plain wrong. The most common question is "How do I make my image fit a certain space?" By the end of this guide, you won't just know the answer—you'll understand the principles behind it, empowering you to solve any image challenge with confidence.

Use the navigation on the left (or the dropdown above on mobile) to explore the different topics. Each section includes interactive examples to help you learn by doing.

The Building Blocks: Pixels & Resolution

Before we talk about fitting images into boxes, we need to understand what an image is made of. Digital images are made of tiny squares called **pixels**. The number of pixels in an image determines its **resolution** or **dimensions** (e.g., 1920 pixels wide by 1080 pixels tall).

Resolution vs. Display Size

An image's resolution is its "true" size. You can display it at any size on a webpage, but if you display it larger than its true resolution, it will become blurry or **pixelated**. Let's see this in action.

This is a small 32x32 pixel image. See what happens when we force it to fill a large container.

Original 32x32px

A 32x32 pixel image

Stretched to 256x256px

A 32x32 pixel image stretched

Key Takeaway:

Always use an image that is at least as large as the largest space it will fill. If your container is 600px wide, your image should be at least 600px wide. You can always scale an image down without losing quality, but scaling up will make it look bad.

Choosing the Right Image Format

The file format of your image (like .jpg or .png) has a big impact on quality, file size, and features like transparency. Choosing the right one is crucial for a fast, good-looking website.

The Shape of Things: Aspect Ratios

The **aspect ratio** is the proportional relationship between an image's width and its height. It's written as two numbers separated by a colon, like 16:9. A square image has an aspect ratio of 1:1. This is different from resolution! An image that is 600x600 pixels and one that is 2000x2000 pixels both have a 1:1 aspect ratio.

When you try to fit an image into a container with a different aspect ratio, you either get empty space, or part of the image gets cropped. Let's see how that works.

Original Image (3:2 ratio)

placeholder image of mountains

Fit this image into a container with a:

Key Takeaway:

If you want your entire image to be visible, make sure your original image has the same aspect ratio as the container it's going into. If you don't care about cropping, you can use CSS to make it fill the space beautifully (we'll cover that next!).

Making It Fit: HTML & CSS

This is where the magic happens! Using HTML and CSS, we can tell the browser exactly how to display our images. Forget stretching and squashing—these tools give you full control.

Our Image Container

interactive image placeholder

<img id="sizing-image" src="..." style="

width: 100%; height: auto; object-fit: fill;

">

Pro Tip: The Holy Grail of Responsive Images

For most cases, this is the CSS you want: width: 100%;, height: auto;. This makes the image fill the width of its container while automatically adjusting its height to maintain the aspect ratio. To control how it fills a container of a specific height, object-fit: cover; is your best friend.

How Page Builders (like Elementor) Handle Images

Page builders like Elementor provide a user-friendly interface to manage images, but underneath, they're just applying the same HTML and CSS principles we've discussed. Understanding this helps you make better decisions in the builder.

1. Foreground Images (The Image Widget)

When you use an Image Widget, you're placing a standard <img> tag. Elementor gives you controls that translate to CSS properties.

Elementor Image Widget Panel

mockup preview
Image Size
Full ▾
Elementor's 'Image Size' setting lets you choose a pre-resized version of your image. Choosing 'Full' uses the original uploaded file. Choosing a smaller size (e.g., 'Medium') loads a smaller file, which is great for performance!

Style Tab
Width100 %
Height250 px
Setting Width and Height here directly applies CSS `width` and `height` properties. Be careful! This can cause stretching if the aspect ratio doesn't match.
Object FitCover ▾
This is your secret weapon! It's the CSS `object-fit` property. 'Cover' is fantastic for making an image fill a specific sized box without distortion. 'Contain' will fit the whole image inside.

2. Background Images

When you set a background image on a Section or Column, you're not using an <img> tag. Instead, CSS properties like background-image and background-size are used. The controls look different but achieve similar results.

Elementor Section Style Panel

Background
Image: mountain.jpg
PositionCenter Center ▾
This is the CSS `background-position` property. It controls the focal point of the image when it needs to be cropped to fit.
SizeCover ▾
This is the CSS `background-size` property. 'Cover' makes the image fill the entire section, cropping as needed. 'Contain' shows the whole image, possibly leaving empty space. 'Auto' shows it at its original size.
RepeatNo-repeat ▾

Common Mistakes & How to Fix Them

Let's look at some common image problems and the simple solutions to fix them. Click on each card to see the fix.

Problem: Stretched or Squashed Image

The image is distorted because a specific width and height were set that don't match its aspect ratio.

stretched image

Solution: Use `object-fit` or `auto` height

Option A: Set height to `auto` and let the browser figure it out.
Option B: Use `object-fit: cover` to fill the box without distortion.

fixed image

Problem: Blurry or Pixelated Image

A small image is being displayed in a large container, forcing the browser to stretch it beyond its original resolution.

blurry image

Solution: Use a Higher Resolution Image

Upload an image that is at least as wide as the largest container it will fill. Here, we've replaced the 100px image with a 400px one.

crisp image

Contact Us

WhatsApp whatsapp