Right, let's get that picture onto your webpage.
You've got the image, you've got the HTML file, and you just want them to play nicely together. I get it. I've been there. Sometimes you just need the quick-and-dirty method without getting lost in a sea of technical jargon.
So, let's cut to the chase. The single most important piece of code you need is the humble <img> tag. This little tag is the workhorse of web visuals. It's the fundamental building block for pretty much every image you see online. Simple, right?
Your First HTML Image Tag
Think of the <img> tag as giving your web browser a really simple set of instructions. To work, it needs two critical bits of information: what to show and a description of what it's showing. These are handled by two "attributes" that sit inside the tag.
src: This is short for "source." It’s the file path or URL that points directly to your image file. It’s like telling the browser, "Go fetch the picture from this exact spot."alt: This stands for "alternative text." This is the text description that shows up if the image fails to load for some reason. But more importantly… it's what screen readers announce to visually impaired users, making your site accessible to everyone.
Here’s how it all comes together. You can drop this snippet right into your HTML file and see the magic happen.

Before we go any further, let's quickly break that <img> tag down. It's simple, but knowing the parts makes a world of difference. Trust me on this.
Anatomy of the HTML Image Tag
Here’s a quick reference table for the essential attributes you'll find yourself using all the time.
| Attribute | What It Does | Example Usage |
|---|---|---|
src |
Specifies the source or path to the image file. This is mandatory. | src="images/sunset.webp" |
alt |
Provides alternative text for accessibility and for when the image can't be displayed. | alt="A vibrant orange sunset over the ocean" |
width |
Sets the display width of the image in pixels. | width="600" |
height |
Sets the display height of the image in pixels. | height="400" |
Getting these basics right from the start will save you a ton of headaches later, especially with annoying layout shifts and accessibility stuff.
A quick but important thought… please don't skip the
alttext. It feels like such a small thing, but it's massive for making the web usable for everyone. It’s not just about SEO; it’s about being inclusive. And that's always a win.
Visuals are everything for keeping people engaged. Here in Australia, data shows that adding images to a website can lead to a 94% increase in views compared to pages that are just plain text. It just goes to show how powerful a simple <img> tag can be. You can find out more about Australian web design statistics and see for yourself how visuals really do make a difference.
So, you’ve added an image, and it looks brilliant on your big desktop monitor. Then you check it on your phone… and it’s a complete mess.
It’s either so massive you have to scroll sideways to see it all, or it’s shrunk down to a tiny, unreadable speck. Don't worry, this is an incredibly common frustration. It trips up just about everyone at some point. It’s a classic rite of passage in web design.
This is exactly why we need to talk about "responsive images". It's a fancy term that just means making your images look great everywhere, on every device.
The Magic of Srcset
The real hero for making images responsive is a clever little attribute called srcset. Think of it like this: instead of giving the browser just one image, you’re handing it a whole menu of options. You might provide a small version, a medium one, and a large one. Then you let the browser pick the perfect size for the job.
This is way more efficient. A phone on a patchy 4G connection has no business downloading a huge image file designed for a massive 4K desktop display. By offering choices, you let the browser grab only what it needs, which makes your site load a whole lot faster. And that makes your visitors happy.
The flowchart below shows the basic process of adding an image, which is the foundation that srcset builds upon.

This visualises the core components. Responsive techniques like srcset are just extra instructions you add right inside that same <img> tag to make it a bit smarter.
Getting Responsive Right is Critical
This isn't just a "nice-to-have" anymore. Especially here in Australia. As of early 2025, Australia had 34.4 million active cellular mobile connections. That's an incredible 128% of the total population. Mobiles now account for almost half (48.9%) of all time spent online.
That means a huge chunk of your audience is looking at your site on a small screen. A really big chunk. Using srcset properly isn’t just good practice; it's essential for performance and user experience.
When You Need Even More Control
Sometimes, just offering different sizes of the same image isn't quite enough. Let's say you want to show a wide, sweeping landscape photo on a desktop, but a cropped, vertical version on a mobile phone to better fit the screen's orientation. This is a classic art direction problem.
For that next level of control, you'll want to reach for the <picture> element.
The <picture> element essentially acts as a wrapper around your <img> tag, allowing you to define different image sources based on specific conditions like screen width. It gives you the ultimate power to dictate exactly which image file gets displayed and when.
This might sound a bit complex at first, but it’s one of those concepts that really clicks once you try it out. My advice? Start with
srcset—it’ll cover you in most situations. Only reach for the<picture>element when you need that extra level of artistic control for different screen sizes.
Optimising Images for a Lightning-Fast Website
Have you ever landed on a website and just… waited? And then waited some more while a little wheel spins endlessly? Chances are, huge, unoptimised images were the culprit.
This is one of the biggest (and most common) mistakes people make, and it can absolutely tank your user engagement before it even starts. Let's face it, nobody has the patience for a slow website anymore. So, let's get practical about making your images lean and fast without turning them into a pixelated mess.
Choosing the Right File Format
First things first, not all image formats are created equal. You wouldn't use a sledgehammer to hang a picture frame, would you? It's the same idea here. Picking the right tool for the job makes all the difference.
Here’s a simple breakdown of the main players:
- JPEG (or JPG): This is your go-to for photographs. It’s fantastic at handling complex colours and gradients, like a picture of a sunset or a detailed product shot. It uses "lossy" compression, which cleverly discards tiny bits of data to keep file sizes small.
- PNG: Perfect for graphics with sharp lines, text, or transparent backgrounds. Think logos, icons, or diagrams where crisp edges are non-negotiable. It uses "lossless" compression, so the quality is perfect, but the file sizes can be much larger than JPEGs.
- WebP: This is the modern superstar of image formats. It offers the best of both worlds, providing excellent quality with significantly smaller file sizes than both JPEG and PNG. Most modern browsers support it, making it a brilliant choice for just about everything.
Compressing and Resizing Your Images
Once you've settled on a format, the next crucial step is compression. Think of it like packing a suitcase efficiently—you want to fit everything you need without the extra weight slowing you down.
Image compression tools, many of which are free online, shrink your image's file size without a noticeable drop in quality. It's also vital to resize your images to the exact dimensions they'll be displayed on your site. There's no point uploading a massive 5000-pixel wide photo if it's only going to be shown in a 600-pixel wide column. That’s just wasted data. For an online store, getting this right is key, as covered in the ultimate guide to WooCommerce website design.
To ensure your images are not only fast but also look their best, you might want to look into AI-powered image enhancement techniques. These tools can upscale and clarify images, which is especially helpful after they've been compressed.
Remember this: The goal is to find the perfect balance between the smallest possible file size and a quality level that still looks fantastic to the human eye. It's a bit of an art, but one that pays huge dividends in website speed.
A Game Changer Called Lazy Loading
Finally, let's talk about a simple but brilliant trick: lazy loading.
By adding one tiny attribute to your image tag (loading="lazy"), you tell the browser not to load an image until it’s about to scroll into view. This makes the initial page load feel incredibly quick, because the browser isn't trying to download every single image on the page all at once. It’s a massive win for user experience and couldn't be easier to implement.
Beyond the Basics: Advanced Image Techniques
Alright, you've mastered the fundamentals. Your images are optimised, responsive, and looking sharp. That's a huge step.
Now, let's explore some more advanced techniques that can add a layer of interactivity and professional polish to your web pages.

Making an Image a Clickable Link
This is one of the most common and useful tricks in the book. You see it everywhere—a product gallery where clicking an image takes you to the product detail page, or a portfolio where each thumbnail links to a full case study.
The good news is, it's incredibly simple to do. You just need to wrap your <img> tag inside an <a> (anchor) tag, which is the standard HTML element for creating links.
It looks like this:
And just like that, your static picture becomes a clickable gateway. Easy, right?
Using CSS for Background Images
Sometimes, an image isn't the main content; it's more like digital wallpaper. It’s there to set a mood or add some visual texture, but the text sitting on top is the real hero.
For these scenarios, we pivot from HTML to CSS and use a background image. This is the go-to method for creating those big, impressive "hero" sections you see at the top of so many homepages.
Here’s the core distinction to remember:
Use HTML
<img>tags for content. If the image is crucial for understanding the page—like a product photo or a diagram—it needs to be an<img>tag. This gives it properalttext and helps search engines understand what it is.Use CSS
background-imagefor decoration. If you could remove the image and the page would still make perfect sense, it's a job for CSS.
By defining the image in your CSS file instead of your HTML, you create a cleaner separation between your content and your styling. For developers looking to speed up their workflow, some newer AI-powered screenshot to code tools can even automate parts of this, converting a visual design directly into code.
A Quick Word on Image Maps
I have to mention this one, even if it feels a bit old-school these days. An image map allows you to define multiple clickable "hotspots" within a single image. Think of a map of Australia where clicking on each state brings up more information.
Setting them up is more involved, requiring coordinates and <map> and <area> tags, and frankly, you won't need it for 99% of projects. But for those rare, specific use cases like an interactive diagram or a custom floor plan, it can be a real lifesaver. It’s a classic technique to keep in your back pocket… just in case.
Putting It All Together on Your Platform
Okay, knowing the raw HTML code is one thing. But how does this all translate to the platform you’re actually using every day? It’s a fair question, because this is where the theory gets real.
You’ve got the principles down, and now it’s just a matter of finding where your platform cleverly tucks them away. Think of it like knowing how a car engine works. You don’t need to build it from scratch every time you drive, you just need to know where to put the key.
Working with WordPress
If you’re one of the millions using WordPress, you're in luck. It does a lot of the heavy lifting for you.
When you upload an image to the Media Library, you’ll see fields for Alt Text, Title, and Description right there in the interface. That’s your alt attribute, just with a friendlier face.
WordPress also automatically creates several different sizes of your uploaded image, which it then uses to build a srcset for you. This means responsive images are basically handled without you needing to touch a line of code. For most people, a well-designed WordPress website design handles all of this behind the scenes, ensuring your images are both accessible and fast.
Navigating Shopify and E-commerce
For the Shopify crowd, things are a little different but just as manageable. When you add a product image, the uploader has a dedicated spot to "Add alt text." Don't skip this. It’s absolutely vital for both accessibility and for Google Images to understand what you’re selling.
Want more advanced control, like customising how images are lazy loaded or implementing the <picture> element for different crops on mobile? You’ll need to dip into your theme’s code. This usually means editing the Liquid files (like product-template.liquid). It’s definitely more hands-on, but it gives you total control over how your product images perform.
Page Builders Like Elementor or Squarespace
What if you're using a visual page builder like Elementor or Squarespace? Good news. These tools are all built on the same HTML principles we've been talking about—they just give you a visual interface to manage them.
Think of it this way: the page builder is like a friendly robot that writes the HTML for you based on the buttons you click and the settings you choose.
When you add an image widget in Elementor or an image block in Squarespace, dig into its settings. You'll find fields for alt text, options to turn the image into a link, and often a simple toggle switch for lazy loading. They’ve taken the raw code and turned it into user-friendly controls, so you can apply everything you've learned without writing a single tag yourself.
Got Questions About HTML Images?
As you start putting all this into practice, you'll inevitably run into a few tricky spots. It happens to the best of us. Let's walk through some of the most common questions that pop up, so you can solve them like a pro.
It’s one thing to follow a guide, but another to really understand the why behind the code. These are the kinds of questions that separate beginners from developers who really know their stuff.
What's the Difference Between an Absolute and a Relative Image Path?
This is a classic, and honestly, a point of confusion for almost everyone when they're starting out. Getting this right is fundamental.
Think of it like giving a friend directions to your favourite cafe.
A relative path is like saying, "it's the shop next door." The location is relative to where you both are right now. In your code, this looks something like src="images/koala.jpg". This is the go-to method for images on your own website. Why? Because if you ever move your entire project to a new server, all the links between your files remain intact. Everything just works.
An absolute path, on the other hand, is like giving the full street address: 123 Main Street, Sydney, NSW 2000. It's the complete, unambiguous URL, like src="https://www.someotherwebsite.com.au/images/koala.jpg". You’ll use this when you need to pull in an image that’s hosted on a completely different server, like from a Content Delivery Network (CDN) or another website.
My advice? Stick with relative paths 99% of the time for your own site's images. They're far more robust and will save you a world of headaches down the track.
Why Isn't My Image Showing Up?
Ah, the dreaded broken image icon. We've all been there. You stare at the screen, absolutely convinced the code is perfect, but all you get is that sad little placeholder.
Nine times out of ten, the culprit is a tiny mistake in the file path you've provided in the src attribute.
Here’s a quick troubleshooting checklist:
- Check the spelling: Double-check, then triple-check the spelling of the folder and the image filename. One wrong letter is all it takes.
- Case sensitivity is key: Most web servers treat
MyImage.JPGandmyimage.jpgas two completely different files. Be consistent and precise. - Verify the path: Are you sure the image is in the folder you think it is? A simple test is to copy the full image path and paste it into your browser's address bar. If the image doesn't load there, your HTML has no chance.
Can I Use CSS to Add an Image Instead of HTML?
Yes, absolutely! And knowing when to use CSS versus HTML for images is a real sign you're levelling up your web development skills. It all boils down to one simple question: is the image content or decoration?
Use the HTML <img ...> tag for images that are content. Think of a product photo on an online store, a chart in a blog post, or a team member’s headshot. If removing the image would make the page harder to understand, it belongs in your HTML. This also allows you to add crucial alt text for screen readers and search engines.
Use the CSS background-image property for images that are purely decorative. This is perfect for background patterns, subtle textures, or that big, atmospheric hero image behind your main heading. If the image could disappear and the meaning of the page would be exactly the same, it’s a job for CSS.
We hope this guide has armed you with the confidence and knowledge to handle images in HTML with ease. If you're ready to build a truly professional online presence, the team at Wise Web is here to help. Visit us at wiseweb.com.au to see how we can bring your digital vision to life.


