Let's be honest, staring at a wall of text on a screen is… well, it's boring. You've built your first HTML page, and while it's functional, it probably feels a bit flat. It’s missing that visual spark.
I've been there. My first website was just lines and lines of text, and I remember thinking, "How on earth do I get pictures in here?" That's where the HTML <img> tag comes in. It might sound a little technical, but I promise it's one of the most satisfying first steps you'll ever take. It's magic.
We're going to walk through this together. Not like a textbook, but like a real conversation. We'll start with the single line of code you need and then build on it. Think of this as your first big win… the moment your page goes from a document to something that feels alive.
Why Bother with Images at All?
It's about so much more than just making things look pretty. Images are a powerful tool for connection and engagement. They break up text, illustrate your points, and make the whole experience more enjoyable for your visitors. It’s a core principle of good web design.
In fact, getting visual is crucial. It’s projected that in 2025, Australian websites with compelling visual content will see a remarkable 94% increase in page views compared to those without. Crazy, right?
Adding images isn't just a technical step; it's a strategic one. It's the difference between a page people read and a page people experience.
So, what does this mean for you?
- Better Engagement: Images grab attention and can keep people on your page for longer.
- Clearer Communication: Sometimes a picture really is worth a thousand words, especially for explaining tricky ideas.
- Professional Polish: A well placed image makes your website feel more complete and trustworthy.
This guide is designed to give you that confidence. By the end, you won't just know how to add images in HTML; you'll understand why it's so important for creating a great user experience. Let's get started.
The Anatomy of the HTML Image Tag
Before we jump into the code, let's quickly break down the <img> tag itself. It's a single, self-closing tag, but it needs a couple of key instructions, called attributes, to tell the browser what to do.
The Core Anatomy of the HTML Image Tag
| Attribute | What It Does | Is It Required? |
|---|---|---|
src |
The "source" of the image. This is the file path or URL that points to your image file. | Yes |
alt |
"Alternative text". A short description of the image for screen readers and search engines. | Yes |
width |
Sets the display width of the image in pixels. | No |
height |
Sets the display height of the image in pixels. | No |
Basically, the src attribute tells the browser what to show, and the alt attribute describes it for users and systems that can't see it. The width and height attributes are optional but highly recommended for helping the page load smoothly. Don't worry, we'll get into all of that.
Adding Your First Image
Okay, enough theory. Let’s get an image onto your page. This is the fun part.

The most basic way to add an image is with the <img> tag, along with its two essential partners: the src and alt attributes. The src attribute is the path to your image file, and alt provides that crucial text description for accessibility and SEO.
Here’s what that looks like in practice. Find a spot in your HTML file’s <body> section and add this line of code:
<img src="images/my-first-image.jpg" alt="A photo of a golden retriever puppy playing in a field of grass.">
That's it! Save your file and open it in a web browser. You should now see your image right there on the page. It's a simple line of code, but it makes a huge difference, doesn't it?
Right, let's get our hands dirty and look at the code that brings your webpage to life with images. The main tool for this job is the <img> tag, and it's a little bit different from other HTML tags you might've used.

Unlike a paragraph tag (<p>) that needs an opening and closing tag to wrap around your text, the <img> tag is self-closing. It's a single, standalone instruction that tells the browser, "Put an image right here." No need for a separate </img> at the end. Which is nice and simple.
The most critical piece of this tag is the src attribute. You can think of src as being short for 'source'. This attribute is where you tell the browser the exact location of your image file… like giving it a map and an address all in one. If you mess this part up, the browser won't have a clue what to display.
Getting the Path Right
Honestly, the src attribute is where most beginners trip up. It all comes down to getting the file path correct, and you've got two ways to do it.
First, you can point to an image that's stored locally in your project folder alongside your HTML file. We call this a relative path.
<img src="images/logo.png">
In this snippet, the browser expects to find a folder named images in the same directory as the HTML file, and inside that folder, it looks for logo.png. It’s simple, as long as your folder structure is organised.
The other option is to use an image that's already hosted somewhere on the internet. This is known as an absolute path, which is just the full URL to the image.
<img src="https://some-other-website.com/images/photo.jpg">
This approach can be easier since you're just pasting a link. The downside? You're completely dependent on that other website to keep the image online. If they take it down, it disappears from your site too. Poof.
The
<img>tag has been a fundamental part of the web since its earliest days. Since HTML first introduced it in the early 1990s, Australian websites have transformed from basic text pages to the visually rich platforms we use today. You can read more about Australia’s digital evolution over on datareportal.com.
Why the Alt Attribute Is Non-Negotiable
Alright, let's have a serious chat about something that's incredibly important but often gets overlooked: the alt attribute. You’ll see it in every properly coded <img> tag, and for good reason. It’s not just optional filler.
Think of it as your image’s safety net. ‘Alt’ is short for ‘alternative text’, and it’s simply a concise description of what the image shows.
If your image ever fails to load… maybe because of a slow internet connection or a broken file path… this text pops up in its place. So, instead of a confusing empty box, your visitor knows exactly what was supposed to be there. It's a small detail that massively improves the user experience.
More Than Just a Plan B
But the alt attribute's role goes far beyond being a backup for broken images. It’s absolutely fundamental to web accessibility.
For people who use screen readers to navigate the web, the alt attribute is what gets read aloud, painting a picture of the visual content for them. Without it, they're left in the dark, missing out on a huge part of your message. Adding descriptive alt text isn't just a technical best practice; it's how you make your website inclusive and welcoming for everyone.
This tiny bit of text is what bridges the gap between visual content and universal understanding. It’s a simple act of inclusion that also happens to be great for your site's health.
And if that wasn't enough, search engines like Google can’t actually "see" images. They rely heavily on your Alt Text to figure out what a picture is about, which helps them understand the context of your entire page. Getting this right can give your SEO a nice, tangible boost, making it easier for people to find you in the first place.
Taming Your Images with Height and Width
So, you’ve added your image… and it’s massive. It’s taking up the whole screen, pushing all your lovely text out of the way and generally causing chaos. Don't worry, we’ve all been there. It’s a classic web developer rite of passage.
The good news is that you have full control over this. The quickest way to rein in a giant image is by using the height and width attributes directly inside your <img> tag. These attributes let you tell the browser the exact dimensions you want your image to be, usually specified in pixels.
Getting Your Layout Under Control
Let's look at a practical example. Say you want an image to be exactly 400 pixels wide and 300 pixels tall. Your code would look something like this:
<img src="images/big-image.jpg" alt="A large, detailed landscape photo" width="400" height="300">
Just by adding those two little attributes, you’ve instantly resized it on the page. Your layout suddenly looks much more organised and intentional, which is a huge win. This is the go-to fix when you need a quick solution to get things looking right.
Many content management systems, like those used in professional WordPress website design, often handle this for you, but it's essential to understand what’s happening behind the scenes.
Be careful, though. Using fixed pixel values like this can be a bit of a double edged sword. It solves the immediate problem, but it’s not always the best approach for the long run.
In a world where people view your site on phones, tablets, and huge desktop monitors, a fixed size image can cause new problems. What looks perfect on your laptop might be way too big for a phone screen, forcing users to scroll sideways.
Beyond just setting static dimensions, understanding how to effectively resize images for the web is crucial for both responsive design and faster loading times. This quick fix is great for now, but we'll soon explore smarter, more flexible ways to handle image sizing.
Making Images Look Great on Any Device
Let’s be real. We all browse the web on a mix of devices… sometimes on a big desktop monitor, other times scrolling on our phones while in line for a coffee. Your website visitors are no different.
An image that looks fantastic on a large screen can completely break the experience on a mobile phone. You've probably seen it before: the image spills out of the frame, forcing you to scroll sideways or pinch and zoom. It's clunky, frustrating, and a quick way to get someone to leave your site.
This is precisely where responsive design comes to the rescue. It's time to ditch those rigid height and width attributes we touched on earlier and embrace a smarter, more flexible approach using a bit of CSS.
The One Line CSS Game Changer
I'm about to show you a simple line of CSS that is, without a doubt, a game changer. It’s one of those tricks you learn once and then find yourself using on every single project from that day forward.
The magic snippet is max-width: 100%;.
When you apply this style to an image, you're giving the browser a simple instruction: "You can shrink to fit inside your container, but never, ever stretch bigger than your original size." This clever rule stops images from becoming pixelated and blurry if they're placed in a space wider than the image itself. It's an elegant fix for a very common headache.
This infographic breaks down the core idea of getting oversized images to behave within your layout.

The main takeaway here is about adaptability. Instead of forcing a fixed size, we're giving the image the rules it needs to adjust gracefully to its environment.
Going a Step Further with Srcset
While the max-width trick is fantastic for layout flexibility, we can take things to the next level. Given that 48.9% of web traffic in Australia comes from mobile devices, making sure your images load quickly is non-negotiable. For platforms that are built around a great user experience, like those crafted through professional Squarespace website design, optimising for mobile is a core principle. You can dig into this trend further with the latest social media statistics on sproutsocial.com.
This is where a more advanced HTML attribute, srcset, enters the picture.
The
srcsetattribute lets you give the browser a whole menu of different-sized versions of the same image. The browser then smartly picks the most suitable one to download based on the user's screen size and resolution. This saves bandwidth, speeds up your site, and makes for a much better mobile experience.
Working Through Common HTML Image Problems
As you get the hang of adding images to your HTML, you're going to run into a few hurdles. It happens to all of us! Think of this as your go-to guide for those little moments that make you scratch your head.
Let's walk through some of the most frequent questions and solve them together.
"Help! Why Isn't My Image Showing Up?"
This is the classic, number one problem, and don't worry, it's almost always an easy fix. Nine times out of ten, the culprit is a tiny typo in your src attribute’s file path.
Go back and carefully double-check your folder and file names. A single wrong letter can break the whole thing. It’s also worth remembering that paths are often case sensitive, meaning the server sees My_Image.JPG as a completely different file from my_image.jpg.
And, of course, make sure the image is actually in the folder you’re pointing to. It's a simple mistake to make, but a common one! Finally, check you haven't forgotten the file extension, like .png or .gif.
"What’s the Real Difference Between JPG, PNG, and SVG?"
That’s a fantastic question. Picking the right format is a game-changer for your website's performance and appearance.
-
JPGs are the workhorse for photography. If you have a detailed photo with millions of colours, a JPG will use clever compression to keep the file size manageable. This is crucial for faster page load times.
-
PNGs are your best friend for anything needing a transparent background. Think of a company logo you want to float over a coloured banner or a custom icon that shouldn't have a white box around it.
-
SVGs are in a league of their own. They aren't made of pixels; they're actually drawn with code. This means you can scale them up or down to any size imaginable, and they will always stay perfectly crisp. They're ideal for logos and icons that need to look sharp on every device.
"How Can I Get My Images to Load Faster?"
Nothing kills a user's experience like a slow-loading website, and heavy images are often to blame.
Your first line of defence is to compress your images before you upload them. There are plenty of free online tools that can dramatically shrink an image's file size without a noticeable drop in quality. It's a non-negotiable step.
Beyond that, always use the right tool for the job… don't save a simple icon as a massive JPG. For pages with a lot of images, you can also add the loading="lazy" attribute to your <img> tag. This is a neat trick that tells the browser not to load an image until someone is about to scroll it into view, which can make a huge difference to your initial page load speed.
Feeling like you'd rather have an expert handle the technical side of things? The team at Wise Web specialises in creating beautiful, high-performing websites that take the guesswork out of web design. Find out how we can help your business shine online at https://wiseweb.com.au.

