So, you're trying to get a photo onto your web page? The good news is that it all starts with one simple line of HTML code: <img src="your-photo.jpg">. That's the heart of it, but to do it like a pro, we'll need to add an alt attribute for people who can't see the image.
Getting Your First Photo onto a Web Page
It sounds dead simple, doesn't it? Just pop a photo onto the page. Easy.
But if you're here, you've probably figured out it's not quite that simple. Maybe you're staring at a bit of code, wondering what on earth 'src' and 'alt' even mean. Trust me, you're not alone. This is one of those first hurdles that every single person hits when they start building stuff for the web.
And getting this part right is what separates a website that looks polished and professional from one that feels a bit… well, broken. We'll get you sorted. No jargon, I promise.
Why Are Images So Important, Anyway?
It might seem obvious, but visuals are the lifeblood of the modern web. They break up giant walls of text, grab a visitor's attention, and can explain a tricky idea in a split second. This isn't just a hunch; it’s a massive part of how people actually use the internet.
Just look at the Aussie market, for example.
Over 91% of content from Australian digital brands has visual stuff like photos and graphics. This isn't just for show either… 71.4% of these brands say that visually appealing content is absolutely vital to their marketing. Some businesses even plaster images on a staggering 80-90% of their website pages, as shown in Australian content marketing stats on redsearch.com.au.
Learning how to embed a photo in HTML isn’t just a techy chore. It's a fundamental skill for creating a website that actually connects with people.
Your Starting Point: The <img> Tag
Let's dive into the absolute basics. The <img> tag is the one you really need to know, and it's much less scary than it looks. It's what's called a "void" or "empty" element, which is just a fancy way of saying it doesn't need a closing tag like </img>. Easy.
Here’s a quick breakdown of its most important bits.
The Only HTML Image Tag You Need to Start
| Attribute | What It Means | Simple Example |
|---|---|---|
<img> |
This is the tag itself. It basically tells the browser, "Hey, an image goes here!" | <img ... > |
src |
Stands for "source." This is the most crucial part… it's the file path or URL to your photo. Without it, the browser has no idea what to show. | <img src="images/sunset.jpg"> |
alt |
Stands for "alternative text." This describes the image for screen readers (used by visually impaired visitors) and also pops up if the image fails to load. It's a huge deal for accessibility and SEO. | <img src="images/sunset.jpg" alt="A vibrant orange sunset over the ocean."> |
Once you get your head around these three things, you've got the power to place any image on any web page.
From this foundation, we'll explore the smarter tricks that will help your website:
- Load faster for visitors who won't wait around.
- Rank better in search engines like Google.
- Look fantastic on any device, from a huge desktop monitor to a small phone.
By the end of this guide, you won't just know how to add a photo… you'll know how to do it the right way. Let's get into it.
Getting to Grips With the Essential HTML Image Tag

Right, let's get our hands dirty with the absolute cornerstone of web images: the <img> tag. This is your workhorse. The tool you'll probably use 99% of the time for showing photos. We’re going to break it down so you can use it without even thinking.
First up, every <img> tag needs a src attribute. Think of it like a specific street address for your photo. It tells the browser exactly where to find the image file it needs to display. Without it, you’ve just got an empty frame.
This “address” can be written in a couple of different ways, and getting them mixed up is a classic beginner mistake. I've seen it cause more headaches than I can count.
The Tale of Two Paths: Absolute vs. Relative
Imagine giving someone directions. You could give them the full, complete address including the city and postcode… that’s an absolute path. Or, if they're already in the same neighbourhood, you could just say, "it's two doors down on the left"… that’s a relative path.
The src attribute works in exactly the same way:
- Absolute Path: This is the full web address of an image, always starting with
https. You'll use this for images hosted on other websites or a content delivery network (CDN). For example:<img src="https://some-other-website.com/images/photo.jpg"> - Relative Path: This points to an image file on your own website, relative to the location of your current HTML file. For example:
<img src="images/my-photo.jpg">
I once worked with a client whose entire gallery just vanished overnight. Total panic. It turned out they’d used relative paths, but then they reorganised their site and moved the HTML page into a new folder. Just like that, all the "directions" were wrong. It's such a simple mistake, but it's a powerful lesson in keeping your file structure tidy.
When you're working with the src attribute, the type of file you point to also matters a lot. Using a huge, unoptimised file will slow your site right down. For a deeper dive, learning about choosing the best image format for web performance is a great next step.
The Unsung Hero: The alt Attribute
Next, we need to talk about the alt attribute. So many people skip this or just stuff a lazy keyword in there. Please, don't be one of them. This is so much more than just some optional text; it’s a powerhouse for accessibility and SEO.
The alt text is what a screen reader will announce to a visually impaired user. It's also a key signal Google uses to understand what your image is about, helping your content rank. And if for some reason your image breaks, this text will appear in its place.
Good alt text describes the image concisely and accurately. It’s not about keyword stuffing; it’s about providing genuine context for people (and search engines) who can't see the visual.
Think about the difference here:
- Bad:
alt="dog" - Okay:
alt="golden retriever" - Great:
alt="A happy golden retriever catching a red frisbee in a sunny park."
See how the last one paints a picture? That's your goal. It’s a small effort that makes a massive difference to the user experience and aligns with important website accessibility standards.
Stopping the Jump: width and height
Finally, let's touch on the width and height attributes. You might be thinking that CSS handles all this now, and you're partly right. But these simple HTML attributes still have a vital job to do.
When you include width="800" and height="600", you're telling the browser the image's exact dimensions before it even starts to load. This lets the browser reserve the correct amount of space on the page right from the get-go.
Without them, the text loads first, and then… BAM! A giant image suddenly appears, pushing all the content down the page. This jarring effect is called "Cumulative Layout Shift," and it's incredibly frustrating for users. Including these attributes creates a much smoother, more professional loading experience. It’s one of those tiny details that signals a quality website.
Making Your Images Responsive for Any Device
Ever opened a website on your phone and had to pinch and zoom just to see a photo properly? It’s a terrible experience. We've all been there, and it’s usually enough to make you hit the back button and never come back. This is exactly why responsive images are non-negotiable.
Your website needs to look brilliant on a massive desktop monitor and just as sharp on a tiny phone screen. Let's walk through how to future-proof your site and give every single visitor a great experience, no matter what device they're using.
A Simple Safety Net for Your Layout
Before we get into the really clever stuff, let's talk about a simple but powerful CSS trick. I think of it as a safety net for your images. I’ve seen this one line of code fix so many broken layouts that it’s the first thing I check for when a client’s site looks wonky on mobile.
By adding this rule to your stylesheet, you’re telling the browser that an image can be its natural size, but it should never be wider than the container it’s in.
img {
max-width: 100%;
height: auto;
}
This tiny snippet stops huge images from "spilling out" of their columns and wrecking your whole page layout. The height: auto; part is just as important; it makes sure the image scales down proportionally, so it doesn't get stretched or squashed into a weird shape. It's a simple fix with a massive impact.
The Magic of srcset and sizes
Alright, now for the real magic. The srcset and sizes attributes sound a bit technical, but the idea behind them is beautifully simple. Instead of giving the browser just one image, you give it a whole menu of different-sized versions of that same photo.
The browser then cleverly looks at the user's screen size, its resolution, and even their network connection, and picks the perfect image from the menu. It's like a thoughtful waiter recommending the right-sized meal for your appetite.
This approach is a game-changer for site speed. A phone on a patchy mobile connection doesn’t need to download a massive desktop-sized image. By serving a smaller file, the page loads faster, uses less data, and keeps your visitors happy.
This is especially true here in Australia. With mobile connections soaring to 34.4 million, serving optimised images is vital for performance. As you can find out from the latest Australian digital reports on datareportal.com, focusing on quick initial load times is a key factor for success, particularly for e-commerce stores.
A Real-World Example
Let's imagine you're selling a beautiful handbag on your Shopify store. You've taken a gorgeous, high-resolution photo, but it's a huge file. Here’s how you’d use srcset to embed it responsively.
First up, you need to create a few different sizes of your image. Before you even think about embedding, optimising your image sizes is essential for fast loading times. I find it much easier to use a tool like a bulk image resizer to streamline this whole process.
You might end up with these versions:
handbag-large.jpg(1200 pixels wide)handbag-medium.jpg(800 pixels wide)handbag-small.jpg(400 pixels wide)
Now, you’d write your HTML like this:

Let's quickly break that down into plain English.
srcset: This is your menu of images. You list each file path followed by its actual width in pixels (e.g.,400wfor 400 pixels wide).sizes: This is a hint you give the browser. It says, "If the screen is less than 600px wide, the image will take up 100% of the viewport width (100vw). Otherwise, it will take up 50% of the viewport width (50vw)."
With this info, the browser does the maths and downloads the most efficient image. A phone will likely grab the small one, a tablet might get the medium, and a large desktop will get the big one. It's smart, efficient, and makes your website feel so much faster for everyone. It takes a little more effort upfront, but the payoff in user experience and performance is enormous.
Taking Your Image Embedding Skills to the Next Level
Once you've mastered the basic <img> tag, you can start exploring more sophisticated ways to handle images on your website. These techniques aren't just for show… they can seriously improve your site's performance and design flexibility.
Let’s move beyond the standard <img> tag and look at times when a different approach might be the smarter choice.
Using CSS for Background Images
Ever seen a big, beautiful banner image at the top of a homepage with text floating over it? That image isn't really content in the same way a product photo is. It's more like digital wallpaper. It's there for atmosphere and design.
This is the perfect job for a CSS background image.
The key question to ask yourself is: if this image were to disappear, would the page still make sense?
- If the image is essential to understanding the content… like a product shot, a diagram, or a photo in a news story… stick with the
<img>tag. This makes sure it gets proper alt text, which is crucial for both accessibility and SEO. - If the image is purely decorative… like a subtle texture, a hero banner behind a headline, or an icon next to text… use the CSS
background-imageproperty.
This approach keeps your HTML clean by separating your content (the HTML structure) from your presentation (the CSS styling). It's a fundamental principle of good web design.
A Quick Comparison: Choosing the Right Image Embedding Method
To make it even clearer, here’s a quick guide to help you choose the right technique for the job, from essential content images to decorative backgrounds.
| Method | Best Used For | Impact on SEO | When to Reconsider |
|---|---|---|---|
HTML <img> Tag |
Essential content images like product photos, diagrams, and author headshots. | High. alt text is a direct SEO signal. |
For purely decorative images or when you need text overlaid. |
CSS background-image |
Decorative images, hero banners, and background patterns. | None. Search engines don't "see" background images as content. | When the image is crucial for understanding the page's content. |
Responsive Images (srcset) |
Any <img> tag where performance across different screen sizes is important. |
Positive. Improves page speed, a key ranking factor. | For simple icons or images where one size is sufficient. |
Ultimately, choosing the right method comes down to the image's role on the page. Is it content or decoration? Answering that one question will point you in the right direction almost every single time.
Speed Up Your Site with Lazy Loading
Here’s a fantastic modern trick that can make your pages feel dramatically faster, especially on mobile. It's called lazy loading.
The idea is brilliantly simple. Instead of forcing a visitor's browser to download every single image on a long page the moment it loads, lazy loading tells it to wait. It only fetches an image right before it’s about to scroll into view.
This is now built directly into modern browsers, and it couldn't be easier to use. You just add one little attribute to your <img> tag:
<img src="my-photo.jpg" loading="lazy" alt="A detailed description of my photo">
Just by adding loading="lazy", you’ve optimised your page. For image-heavy pages like a photo gallery or a long blog post, this can shave seconds off the initial load time. It’s a huge win for user experience with almost zero effort.
Don't Forget to Choose the Right Image Format
Finally, let's talk about the file itself. The format you save your image in—whether it's a JPEG, PNG, SVG, or WebP—has a massive impact on file size and, therefore, your site's performance.
The flowchart above shows how a browser uses responsive image attributes to serve the most appropriate file, making sure someone on a small phone doesn't waste data downloading a huge desktop-sized image.
Here's a quick rundown of the main players:
- JPEG (or JPG): This is your workhorse for photographs and complex images with lots of colours. It offers great compression for rich, detailed pictures like landscapes or portraits.
- PNG: The perfect choice for graphics that need a transparent background, like your company logo or an icon. PNGs are "lossless," so they don't lose quality, but this often means larger files than JPEGs.
- SVG: A game-changer for logos, icons, and simple illustrations. Because they are vector-based (built from maths, not pixels), they are infinitely scalable without any quality loss and are usually tiny in file size.
- WebP: The modern champion of formats. WebP offers far better compression than both JPEG and PNG, giving you high-quality images at a fraction of the file size. Browser support is now excellent, making it a top choice for performance.
Choosing the right format isn't just a technical detail; it’s about respecting your visitor's time and data. A faster website is a better website, full stop.
If you’re keen to dive deeper into the practical differences, we've got a great article explaining the difference between JPG and PNG on our blog. Getting this right is one of the easiest ways to boost your site speed.
Putting It All Into Practice on Popular Platforms
All this talk about HTML and CSS is great for peeking behind the curtain, but let's be real… most of us aren't hand-coding websites from the ground up these days. You’re likely working with a content management system (CMS) like WordPress, Shopify, or Squarespace.
The good news is that these platforms do a lot of the grunt work for you. They’re smart enough to automatically create different image sizes and often handle things like lazy loading without you ever touching a line of code.
Still, knowing what’s happening 'under the hood' is your secret weapon. It helps you make better decisions from the get-go and gives you the confidence to dive in and troubleshoot when an image just isn't behaving. Let’s look at how this all plays out on the platforms you actually use every day.
WordPress: The Block Editor and Media Library
If you’re on WordPress, the block editor and Media Library are your bread and butter. When you pop an 'Image' block onto a page, you're essentially asking WordPress to write that <img> tag for you.
But that doesn’t mean you’re just a passenger. You still have a surprising amount of control. When you upload a new photo, don't just mindlessly click 'Insert'.
- Find the 'Alt Text' field: This is your moment to add that descriptive, meaningful text we've been talking about. It’s sitting right there in the sidebar, waiting for you. Fill it in. Every. Single. Time.
- Glance at the 'Image size' dropdown: WordPress automatically generates several versions of your image (thumbnail, medium, large, etc.). Choosing the right size here is a simple way to stop a massive, high-resolution photo from being squashed into a tiny space, which would kill your page speed.
Even though you’re clicking buttons instead of typing <img src="...">, you're directly influencing its most critical attributes. It’s the same job, just with a much friendlier interface.
Shopify and WooCommerce: The Lifeblood of Your Store
For anyone running an online shop with Shopify or WooCommerce, your product images are everything. This isn't just about making your site look pretty; these images are your number one sales tool. A blurry, slow, or missing product photo is a guaranteed sale-killer.
When you upload a product image, these e-commerce platforms do some serious heavy lifting. They’ll compress it, create multiple sizes, and build a srcset to make sure the right version gets delivered to the right device.
Your main focus here isn't on the code, but on the quality of your source material. Always start with the highest-quality photo you have and let the platform handle the optimisation. But never, ever skip the alt text.
For an e-commerce site, your alt text needs to be exceptionally descriptive. Put yourself in the shoes of a customer typing into a search engine.
- Bad:
alt="bag" - Good:
alt="Handcrafted brown leather tote bag with brass fittings and an adjustable shoulder strap."
This level of detail isn't just for accessibility… it’s a massive SEO boost that helps your products pop up in Google Image searches.
Squarespace: Drag, Drop, and Details
Squarespace has built its reputation on beautiful, image-heavy templates and an intuitive drag-and-drop editor. Adding photos is meant to be ridiculously easy. You just find an 'Image Block', drag it onto the page, and select your file.
But that beautiful simplicity shouldn't lead to complacency. Once your image is in place, you can… and should… tweak the important settings.
- Click on your image block and look for the Edit (pencil) icon.
- In the settings panel, find the 'Filename' field. By default, Squarespace sometimes pulls this as the alt text, but you should always write your own custom description. It gives you far more control over accessibility and SEO.
- You'll also spot options for linking the image and deciding if it opens in a new tab.
Even in a polished, user-friendly environment like Squarespace, understanding why alt text and image size matter helps you use the tools like a pro. You're not just dropping in a picture; you're strategically placing a well-optimised asset that makes your website better for everyone.
We’ve all been there. You write what you think is the perfect bit of code, hit refresh, and… nothing. Just that sad little broken image icon staring back at you. Or maybe the photo loads, but it’s stretched and looks awful. Perhaps it takes an eternity to appear, making your whole page feel sluggish.
It’s frustrating, but the good news is that most of these problems are incredibly common and usually simple to fix. Think of this section as your emergency first-aid kit for all things images. We'll get you sorted.
The Classic Broken Image Error
That little icon of a ripped piece of paper is probably the number one issue people run into. It feels like a massive failure, but 99% of the time, it’s just a simple typo in your file path. That's it.
Your browser is like a very literal delivery driver. If the address in your src attribute is off by a single letter, a misplaced slash, or points to the wrong folder, it just can't find the package.
Here's a quick checklist to run through:
- Check for typos: Is it
images/sunset.jpgoriamges/sunset.jpg? Double-check every single character. - Case sensitivity matters: On many web servers,
Photo.JPGis not the same file asphoto.jpg. Make sure the filename in your code exactly matches the actual file on the server. - Is the path correct? Are you positive the image is in an
imagesfolder? Did you actually upload it to the right place?
Why Your Site Is So Slow
The next big culprit is image size. I’ve seen clients upload a massive 5MB photo straight from a professional camera and then wonder why their homepage takes ten seconds to load. That’s a recipe for a slow, frustrating website that sends visitors running for the hills.
A huge image file is like trying to send a whole library of books through the mail when all you needed was a single postcard. It’s total overkill, and it clogs up the whole system. For web use, most photos should be well under 500KB, and ideally even smaller. To get a handle on this, you might be interested in our guide on how to minimise image size without sacrificing quality.
Don't Neglect Your File Names
Finally, let’s talk about what you call your files. Naming your photo IMG_8472.jpg is a massive missed opportunity for your SEO. Search engines read filenames to understand what an image is about, so give them something useful to work with.
A descriptive file name is another signal you send to Google about your content. It’s a tiny bit of effort that helps your images—and your page—get found.
Instead of just using the default camera name, get into the habit of renaming files before you upload them.
- Bad:
DSC_0123.jpg - Good:
brisbane-story-bridge-at-sunset.jpg
This simple habit helps with your own organisation and gives you a small but meaningful SEO advantage. It’s one of those easy wins that separates the pros from the amateurs.
Your Top HTML Image Questions, Answered
As you start putting images on your site, you’ll inevitably run into a few common questions. I’ve heard these countless times, so let’s clear them up right now.
Can I Just Link to an Image on Another Website?
While you can technically point your src attribute to an image URL on someone else's server, it's a practice called "hotlinking," and it's a really bad idea.
Think about it: you have zero control over that file. The other site could delete it, rename it, or even replace it with something inappropriate, leaving you with a broken or embarrassing image on your page. On top of that, you could be stepping into a copyright minefield.
My advice? Always upload images to your own server. It's the only way to guarantee you have full control over the file's availability and content.
What's the Best Image Format to Use?
This is one of those "it depends" answers, but it's a simple one. Each format has a specific job:
- JPEG: Your go-to for photos. It’s perfect for images with lots of colours and gradients, offering a great balance of quality and file size.
- PNG: Use this when you need a transparent background. Think logos, icons, or any graphic that needs to sit cleanly on top of a coloured background.
- WebP: This is the modern all-rounder. WebP often provides the same quality as a JPEG or PNG but at a significantly smaller file size, which is fantastic for site speed. It's the format we lean on most these days.
Why Isn't My Alt Text Showing Up?
That's a great sign – it means it's working as intended! Alt text isn't meant to be seen by the average visitor. Its purpose is to work behind the scenes.
It provides a description for screen readers, making your site accessible to visually impaired users, and it gives search engines crucial context about what your image contains. If you're looking for a visible caption, you’ll want to create that separately using standard HTML text and a bit of CSS styling.
How Do I Centre an Image on the Page?
Forget the old, clunky HTML attributes from back in the day. Centring an image is now purely a job for CSS, and it's much cleaner.
The most reliable method is to treat the image as a block element and let the margins do the work. Simply apply this CSS to your image: display: block; margin: auto;. This tells the browser to automatically calculate the left and right margins, perfectly centring it within its parent container.
At Wise Web, we know that building a high-performing website comes down to getting thousands of these small details right. If you want a site that’s not just visually appealing but also fast, accessible, and ready to climb the search rankings, let's talk. You can learn more about our web design services on our site.

