You have an icon file and an HTML page, and you want the icon on the page without it looking blurry, jumping the layout around, or slowing things down. This post shows how to add icons to an HTML website with plain image files, no icon font and no build step. The video that prompted it is How to add Icons in HTML Website | Font Awesome Icons | HTML CSS by Web Tech Knowledge. This post doesn't summarise it. It covers the image-file route.
Step 1: Pick the file format and size you need
Decide where the icon will sit before you download anything. A nav item at 32px needs a different file from a feature card at 128px.
I measured one Thridy icon, "Website", through the public API at api.thridy.com/api/icons and then fetched its files from the CDN. The API lists embed sizes of 32, 64, 96, 128, 256 and 512 px, and download formats of PNG and WebP.
| File | Pixels | Bytes |
|---|---|---|
| Small embed link (WebP) | 200 x 200 | 11,912 |
| Display link (WebP) | 512 x 512 | 53,358 |
That's roughly a 4.5x difference in weight for the same picture. If the icon shows at 64px, don't ship the 512px file.
Step 2: Save the icon into your project
Make an icons folder next to your index.html and put the file in it. Use a short, lowercase name with no spaces, like website.webp.
my-site/
index.html
icons/
website.webp
website-2x.webp
Thridy icons are free for personal and commercial use. On the free plan a credit to Thridy is needed. On a paid plan (Designer or Studio) no credit is needed.
Step 3: Add the icon with an img tag
This is the whole core of it. One line of HTML:
<img src="icons/website.webp" alt="Website" width="64" height="64">
The path in src is relative to the HTML file. If the page doesn't show the icon, a wrong path is the first thing I'd check, then a typo in the file name, then a capital letter that doesn't match on a case-sensitive server.
Step 4: Write the alt text properly
MDN's reference for the img element says browsers don't always display images: non-visual browsers, people who turn images off, or a file that is invalid or an unsupported type. In those cases the alt text is what shows or gets read out, so give a useful value whenever you can.
There are two cases:
- The icon carries meaning on its own, like a lone cart button. Describe what it does:
alt="Open cart". - The icon sits next to a text label and just decorates it. Use an empty value:
alt="". MDN notes that an empty alt tells non-visual browsers the image isn't a key part of the content, so it can be skipped.
Screen readers will announce a decorative icon with a long file name if there is no alt at all, which is noise nobody wants. Don't leave the attribute off. An empty alt and a missing alt are not the same thing.
Step 5: Set width and height
Put width and height in pixels, as plain integers with no units, on every icon. MDN explains why: with both set, the browser can work out the aspect ratio before the image has loaded and reserve the space. Without them the text below can jump when the file arrives.
Match the attributes to the size you actually want on screen. A 512px file shown at width="64" height="64" works, but you're paying for pixels nobody sees. That's what the next step fixes.
Step 6: Serve a sharper file to high-density screens
On a high-density display a 64px slot has 128 physical pixels to fill. Offer two files with srcset and pixel-density descriptors, which is the form MDN and web.dev both use:
<img
src="icons/website.webp"
srcset="icons/website.webp 1x, icons/website-2x.webp 2x"
alt="Website"
width="64" height="64">
Here website.webp is the 64px version and website-2x.webp is the 128px version. The browser picks one. Both sizes are in Thridy's list of embed sizes, so you don't have to resize anything yourself.
Step 7: Size icons with CSS when you reuse them
If you have many icons of the same size, a class keeps the HTML short:
.icon { width: 32px; height: 32px; vertical-align: middle; }
<img class="icon" src="icons/cart.webp" alt="" width="32" height="32">
<span>Cart</span>
Keep the HTML attributes as well. The attributes reserve the space and the CSS controls the final look.
Step 8: Lazy-load icons that start off screen
web.dev documents the loading attribute for deferring images that start below the fold:
<img src="icons/website.webp" loading="lazy" alt="Website" width="128" height="128">
Use it for icons far down the page, such as a footer row or a long feature list. Leave icons at the top of the page alone, since they should load right away. The default behaviour, eager, is fine for those.
Step 9: Keep one size scale across the page
Icons look careless when every one has a different size. Pick two or three sizes and stick to them. I'd use 32px for inline and nav icons, 64px for list items, and 128px for feature cards. Those three all appear in Thridy's embed sizes, and each has a double that's also on the list (64, 128, 256), so the 2x files from Step 6 are already there.
Keep the style consistent too. Mixing a flat outline icon with a glossy 3D one on the same row makes the page feel unfinished, even when each icon is fine alone. Choose one set and take every icon from it.
Name the files by what they show, not by where they sit: cart.webp beats header-icon-3.webp. When you redesign the header, the names still make sense.
Step 10: Check it in the browser
Open the page and look at three things:
- Every icon shows. If one is missing, open DevTools, go to the Network tab and look for a red 404 on that file.
- Nothing jumps as the page loads. Throttle the connection to a slow preset and reload.
- Icons look crisp. Zoom to 200 percent. A soft icon means the 2x file isn't being picked up.
Quick reference
Folder:
icons/besideindex.html.
Tag:<img src="icons/name.webp" alt="..." width="64" height="64">.
Alt: describe the action, oralt=""if a label sits beside it.
Sharp screens:srcset="a.webp 1x, a-2x.webp 2x".
Far down the page:loading="lazy".
Weight check: a 200px WebP measured 11,912 bytes, a 512px one 53,358.
Pick the smallest file that still looks sharp, and always set alt, width and height.
Free 3D icons for this
Every icon on Thridy is free to download and use. A few that fit this piece:
