Right, let's get that first image showing up on your page. Honestly, adding visuals is one of the most satisfying parts of building a website. It’s that exact moment when a plain, boring document suddenly starts to feel like a real, breathing, engaging experience.
The Absolute Basics: Getting Your First Image on the Page

Let's be real. A webpage without images is just a wall of text. It's lifeless. You've probably been there yourself… you've coded something up, taken a step back, and thought, "This really, really needs a picture." But then the code comes into play, and it can feel a bit… much.
I have stared at that dreaded broken image icon more times than I can count, wondering what on earth I did wrong. Seriously. It’s a rite of passage for anyone learning this stuff. But trust me, getting it right is a fantastic quick win. It feels so good.
The magic all comes down to a single HTML tag: <img>. We’re going to cover the two absolute essentials you need to make it work.
The Two Must-Have Attributes: src and alt
To get an image to show up, you need to give the browser two key pieces of information. Think of it like you're answering two simple questions… what image to show, and what it is for anyone who can't see it.
src(Source): This tells the browser where to find the image file. It's the path to your picture, whether it's sitting in a folder on your computer or hosted on another website.alt(Alternative Text): This provides a text description of the image. It's so, so important for accessibility, and it also shows up if the image fails to load for some reason. A real lifesaver.
Getting this right is a huge deal. It’s a foundational part of good web design because visuals make an enormous impact. Did you know that websites with high-quality images can see up to a 94% increase in views compared to those that are purely text-based? It just goes to show how much we all connect with what we can see.
Don’t just build pages; create experiences. A single, well-placed image is often the first step in turning a document into a destination.
Let's dive into the specifics of these attributes and how to use them properly.
The Core <img> Tag Attributes
To really nail this, it helps to have a quick reference for the essential parts of the <img> tag. These are the bits you'll be using every single time you add a picture. No exceptions.
| Attribute | What It Does | Why It Is Essential |
|---|---|---|
src |
Specifies the path (URL) to the image file. | Without it, the browser has no idea which image to display. It’s the bare minimum. |
alt |
Provides a text description of the image for screen readers and search engines. | It ensures your site is accessible and provides context if the image breaks. |
While there are other attributes we can use, src and alt are the non-negotiables. Getting them right from the very start will save you a lot of headaches down the road and make your website better for everyone.
The Building Blocks of an HTML Image
Alright, let's pull back the curtain and look at the code. I promise it’s a lot simpler than you might think. The star of the show is the <img> tag. It's a bit of a loner in the HTML world. It’s what we call a self-closing tag, which just means it doesn't need a partner </img> tag to wrap things up. Easy.
But an <img> tag on its own is useless. It needs specific instructions, which we provide using attributes. Think of them as essential commands that tell the browser exactly what image to display and how to handle it.
The Source of It All: The src Attribute
First up, and the most crucial piece of the puzzle, is the src attribute. It’s short for ‘source’, and it does exactly what it says on the tin: it points the browser to the image file's location. It’s the answer to the fundamental question, "Where is the picture you want me to show?"
You’ve got a couple of ways to specify the source:
- Linking to an online image: You can use the full web address (URL) of a picture that’s already hosted somewhere online. This is quick and easy, sure, but I'd generally advise against it for professional work. If that other website moves or deletes the image, you're left with a broken picture on your page. Not a good look.
- Linking to a local file: This is the standard, reliable method. You save the image within your website’s project folder (a common practice is to create an ‘images’ folder) and link to it from there. The path might look something like
src="images/golden-retriever.jpg". This way, you’re in complete control.
The Non-Negotiable alt Attribute
Next, we have the alt attribute, which stands for ‘alternative text’. This one is absolutely essential. If you take one thing away from this guide, it's to never, ever skip the alt text. It provides a text description of your image, and it serves a few critical purposes.
For starters, it's the backbone of web accessibility. Screen readers announce this text to visually impaired users, allowing them to understand the visual content on your page. It’s also a huge plus for your SEO, because it gives search engines like Google valuable context about what your image contains. And, if for some reason your image fails to load, this text will appear in its place.
A good
alttext is your image's voice. It should describe the image clearly and concisely, almost as if you were explaining it to someone over the phone. For instance:alt="A golden retriever puppy chasing a red ball on a green lawn."
Finally, let's talk about the width and height attributes. While not as mission-critical as alt, they are highly recommended. By defining the image dimensions, you’re telling the browser to reserve the correct amount of space for the picture before it even finishes loading.
This simple step prevents that annoying page-jump effect where content shifts around as images pop in. It's a small detail that makes a huge difference to the user experience.
Making Images Work on Any Device
Getting an image to show up is just the first step. The real art is making it look sharp on a massive desktop monitor and a tiny phone screen without breaking your layout. It’s a common hurdle, believe me. If you just lock in a fixed width like width="800", that image is going to spill right off the screen on a mobile phone.
On the flip side, it might look comically small on a big 4K display. This is exactly why responsive design is so important.
A Simple Trick for a Big Win
One of the quickest and most effective fixes is a single line of CSS: max-width: 100%. This little gem tells the browser to display the image at its natural size, but to never, ever let it grow wider than its parent container. It’s a beautifully simple solution that solves a lot of layout problems right away.
But true responsive design goes deeper than just fitting things on a screen. We have to think about performance. In Australia, mobile-first design isn’t just a buzzword; it’s a necessity. With 48.9% of all internet traffic coming from mobile devices and around 97% of Australians owning a smartphone, loading a huge desktop-sized image on a phone is a recipe for a slow site and a frustrated user. Nobody wants that.
The goal isn’t just to make images fit on different screens. It's about delivering the right size image to the right device to make your site fast and efficient for everyone.
This flowchart breaks down the essential attributes for getting your images right from the start.

It gives you a clear visual of the process: defining the image source (src), providing meaningful alternative text (alt), and setting the dimensions.
Upping Your Game with srcset
For those who want to take performance seriously, the srcset attribute and the <picture> element are absolute game-changers. Think of them as giving the browser a whole toolkit of images to choose from. You provide multiple versions of the same image… a small one for phones, a medium one for tablets, and a large one for desktops.
The browser then does the clever work of picking the most appropriate and efficient one to download based on the user's screen size and resolution. This can dramatically speed up your site on mobile networks, which is a massive win for user experience. It takes a little more effort to set up, but it's a hallmark of professional web development, especially when crafting sleek websites with modern tools. For instance, platforms like Framer for web design are built with this kind of performance in mind.
Optimising Your Images for a Faster Website

Ever found yourself tapping your fingers, waiting for a website to load, only to give up and click away? Chances are, you have. More often than not, the culprit behind that sluggish load time is a collection of massive, unoptimised images.
I've seen it countless times. Beautiful websites brought to a standstill by images that are way, way too big. But the good news is that getting this right is straightforward, and it makes a world of difference. It all comes down to three key areas.
Choosing the Right File Format
First things first, let's talk about file formats. Knowing when to use a JPEG versus a PNG or a next-gen format like WebP can feel a bit technical, but it's actually quite simple.
Here's a quick comparison to help you decide on the fly.
Choosing the Right Image Format
| Format | Best For | Key Feature |
|---|---|---|
| JPEG | Photographs and complex, multi-coloured images | Excellent compression for detailed visuals. |
| PNG | Logos, icons, and images needing transparency | Preserves crisp edges and transparent backgrounds. |
| WebP | A modern replacement for both JPEG and PNG | Superior compression, leading to smaller file sizes. |
Getting the format right is your first win. It's a foundational part of any quality WordPress website design because a site that looks good but loads slowly isn't really a good site at all.
Smart Compression and Loading
With your format chosen, the next step is compression. You can drastically reduce an image's file size, often without any noticeable drop in quality, using free online tools. I personally use TinyPNG all the time; it's a lifesaver. This quick drag-and-drop step pays huge dividends in performance.
Finally, there's a clever trick for loading your images. Modern browsers support a simple HTML attribute: loading="lazy". Adding this to your <img> tag tells the browser to wait until an image is about to scroll into view before downloading it. This makes the initial page load feel lightning-fast.
Optimising your images isn't just a technical task; it's a way of respecting your user's time. A faster website is a better website, period.
Putting these practices into action is also a crucial element in your wider SEO efforts. It's one of those fundamental strategies to outrank SEO competitors that many people overlook.
Common Image Problems and How to Fix Them
Sooner or later, it’s going to happen. You’ll refresh the page, full of hope, only to be greeted by that sad little broken image icon. It happens to every single one of us, I promise. It’s frustrating, but the fix is usually surprisingly simple.
Nine times out of ten, it’s a typo in the file path. Seriously. It feels like it should be something more complex, but it rarely is. So before you start pulling your hair out, take a deep breath and run through this quick mental checklist.
- Spelling: Did you spell the filename exactly right?
sunset.jpgis not the same asSunset.JPG. - Location: Is the image in the folder you think it is? A classic mistake is having the path as
images/photo.pngwhen the file is actually sitting right next to your HTML file. - Extension: Did you use the correct file extension? Double-check if it's a
.jpg,.png, or.webp.
Another common slip-up is uploading a massive, unoptimised image straight from your camera. I’ve done this myself… accidentally uploading a 5MB photo and then wondering why the page was taking an eternity to load. It slows everything down for your visitors.
The most common HTML errors are the simple ones we overlook. A single misplaced character in a file path can be the only thing standing between you and a perfect webpage. Check the small stuff first.
For troubleshooting other tricky issues, like an image that keeps showing up rotated incorrectly, it can be really helpful to look at its hidden data. For ensuring images are properly prepared for the web, knowing how to find metadata in photos can be extremely helpful.
And please, don't forget the alt text! It's so easy to skip when you're in a hurry, but leaving it empty hurts both accessibility and your SEO. Think of it as your image’s safety net.
Frequently Asked Questions About HTML Images
We've gone through a lot, but you're bound to have some lingering questions. Everyone hits a snag now and then, so let's clear up a few of the most common issues people face when adding images to their HTML.
Think of this as your quick-fire troubleshooting guide.
Can I Just Use an Image from Another Website?
While you technically can point your src attribute to an image hosted on someone else's website, it's a practice called "hotlinking," and it's a terrible idea. I strongly advise against it for two big reasons.
First off, you’re stealing their bandwidth. Every time your page loads that image, their server does the work. More importantly, you have zero control. If the other site takes the image down, renames the file, or changes its location, you're instantly left with a broken image icon on your page.
The only reliable way is to host the images yourself. Always download them (after making sure you have the legal rights, of course!) and upload them to your own server. It's the professional approach and saves you from future headaches.
What’s the Difference Between an <img> Tag and a CSS Background Image?
Great question. Getting this right is a sign of a thoughtful developer, and the answer boils down to one simple concept: is the image content or is it decoration?
-
Use an
<img>tag for content. If the image provides information, like a product shot, a diagram, or a staff photo, it belongs in an<img>tag. This is crucial because it allows you to addalttext, making it accessible to screen readers and understandable to search engines. -
Use a CSS
background-imagefor decoration. If the image is just for looks, like a subtle repeating pattern or a decorative header image, then it belongs in your CSS. These images are purely presentational and don't add to the meaning of the page.
Here’s a quick gut check: if you removed the image, would the page lose any of its meaning? If yes, it’s an
<img>tag. If no, it’s a CSS background.
Should I Always Specify Width and Height Attributes?
Yes, absolutely. This is one of those small details that has a massive impact on how your page feels to a user. When you include width and height attributes, the browser knows the image's dimensions before it even starts downloading.
This means it can reserve the exact amount of space for it in the layout right away. Without those attributes, the browser loads all the text first, and then… BAM… everything on the page suddenly shoves itself around to make room when the image finally appears.
That annoying jump is called Cumulative Layout Shift (CLS), and it's a core metric search engines use to judge user experience. Preventing it is a simple fix that makes your site look far more polished and stable.
Hopefully, this guide has given you the confidence to master images on your website. If you're looking to take the next step and create a truly exceptional online presence, the team at Wise Web is here to help. We specialise in building beautiful, high-performing websites that get results.
Ready to build something amazing? Check out our services at https://wiseweb.com.au.

