Do you have a favorite super hero? I have always been fascinated with Mighty Mouse. I love the idea of a tiny little mouse that has a really big impact.
There are a lot of different “Mighty Mouse” elements that exist when you’re growing a blog. These are seemingly small or unknown things that in actuality have a big impact on the success of your blog. One of these “Mighty Mouse” elements is the
img tag. In today’s post we’re going to dissect the
img tag and explain how it can super power your food blog.
You can click here to download the image we’ll use as an example in this post if you want to follow along!
What is the
img tag is the HTML code used to communicate information about an image to a user’s web browser. When looking at a website, we humans see images, but your computer sees HTML code.
I think the best way to understand is by doing, so let’s jump in and explore this together.
1. Login to your blog (we’ll use a WordPress blog in this example).
2. Hover over Pages and select Add New (don’t worry, we won’t be publishing this page).
3. Add a title of Chocolate Chip Muffins and then click the + button and then click Image to insert an Image Block.
4. Click Upload. Find and click the chocolate-chip-muffin.jpg image you downloaded to use as an example.
5. Under Image Settings, set the Alt Attribute and Image Size:
Alt Attribute: a chocolate chip muffin on a plate in front of bananas and a muffin tray
Image Size: Full Size
6. Your image is on your page! Now let’s take a look at the HTML code that WordPress is using behind the scenes. We can see the HTML code by clicking on the image, then by clicking the three vertical dots and finding Edit as HTML.
7. Cool! We’re now looking at the
img tag exactly as a web browser would see it when it comes to our blog.
The begin and end of the
The first part we need to look at is the
img tag itself. I put an orange line at the beginning and the end of the image tag. The first orange line shows where the tag starts, and the second orange line shows where the tag stops.
It’s important to know where the beginning and end of the tag is so we can examine everything that’s inside of it.
You’ll also see a
figure tag that surrounds the
That’s some code that WordPress automatically adds to all of the blocks (i.e. paragraphs, images, quotes, etc.) on your page. You can ignore it for now.
The parts that are inside of our
img tag are called attributes. Let’s take a look at the four attributes that are inside of the
img tag and talk about how they can super power your food blog.
1. The class attribute
You’ll see the class attribute both within the
figure tag and within the
We’re not going to spend much time with the class attribute, as you’ll only use it if you’re familiar with CSS (CSS is a type of code that helps you add style to websites).
You’ll see classes like “wp-block-image” and “size-full” at the
figure level. The “wp-block-image” class is just applying certain styles to every image you upload in one of those image blocks. Size “Full,” if you recall, is the image size we set earlier:
We can change the image dimensions using that side menu bar (here we just clicked 100%), and that will add width and height attributes to our image tags. It also added another class, “is-resized.”
Let’s go back to our original image. We also see a class within the
This isn’t anything we’ll need to adjust manually. You can really get into the weeds by adding new classes to your images and adjusting the styles for all of the images on your site, but we just wanted to give you a quick overview.Interested in learning more about CSS?
2. The alt attribute
It’s easiest to remember the alt attribute as the alternative attribute, as in what text should be displayed as an alternative if, for whatever reason, the image can’t be displayed.
There are two reasons why the alt attribute is really important:
- Usability: It communicates information about your image to visitors who are visually impaired or have slow internet connections.
- SEO: It communicates to search engines what your image is about.
Visitors that are visually impaired will use a screen reader to process the information on websites. A screen reader will go through the different parts of a website and attempt to read back information to the user. This works really well for text, but it doesn’t work as well for images. Providing descriptive text in your alt attribute supplies the screen reader with content that can be read back to the visitor, enabling them to better understand what the image is about. Imagine how you would describe your image to someone that is visually impaired. That’s a good starting point for what you should put in as your image’s alt attribute.
Not only that, your readers may be on slow internet connections and your big, beautiful food photos may not load. This alternative text will load instead.
When a search engine like Google comes to your site it will crawl through your page and attempt to understand the information on your blog post. Search engines are really good at understanding text, but not so great at understanding images. That’s why the alt attribute and the image’s file name (more on that later) are so important for your food blog’s SEO. If your file name is IMG_9205.jpg and the alt attribute area is empty, then you’re not giving Google any clues to help it figure out what your image is about. Providing an accurate and informational alt text helps Google understand your image.
Nerd Note: Never try and trick Google by adding a bunch of words into your alt attribute in an attempt to help your post show up higher in Google. This would be an example of keyword stuffing and could actually end up hurting your blog’s rank in Google. Just do your best to provide an accurate description of the image.
Another Nerd Note: Not every image actually needs an alt attribute. If it’s a decoration (like an icon on your menu bar), you can leave the alt attribute blank. Here’s a nifty decision tree you can use to help you determine whether your image needs an alt attribute or not.How do you write an alt description?
3. The src attribute.
The src attribute is telling the browser where the image is located on your server. It’s easiest to remember the src attribute as the source attribute, as in this URL is the source of the image.
This isn’t critical to know, but I think it’s interesting: Your blog’s images are organized the same way that they would be on a computer — where every image is stored in a folder. So, if you’re using WordPress, the URL for your src attribute will usually look like this:
In our example, the URL is:
That means that there is a folder on our server called wp-content:
…and in that folder there is another folder called uploads:
…and in that folder there is another folder called 2020:
…and in that folder there is another folder called 10:
…and in that folder we can find our image:
Nerd Note: You can actually copy the URL in the src attribute and paste it into your web browser like it is a website. When you do that it’ll bring you to a web page, but the only thing on the page will be the image.
The most important thing to consider with the src attribute is the file name that you give to the image before uploading it. The file name is important because search engines use it to try and figure out what your image is about. If your image is of a chocolate chip muffin, make sure that you don’t have a file name of IMG-1234.jpg, because that’s communicating to the search engine that your image is about “IMG-1234.jpg,” which doesn’t really make sense.
It would make much more sense if you call your image chocolate-chip-muffin.jpg, because that’s the actual content that is in image. This is an important concept, so I’ll bring in some emojis to help make my point.
There are lots of different ways you can change the file name of an image. Here’s how I usually do it:
- Click on the file
- Right click
- Click Rename
- Rename your image
You want to do this before you upload the image to your blog, as it’s really hard to change the file name after you uploaded the image.
4. The Pin Description.
Woah! What’s that?
You may not see the data-pin-description attribute on your images, and that’s okay. We see that here because we’re using a plugin (Tasty Pins — it’s actually one that we developed over on our sister site, WP Tasty!) to add that attribute for us.
Why is the data-pin-description attribute so important?
Pinterest is a huge driver of food blog traffic (we eat with our eyes, after all, and Pinterest is a highly-visual social platform), so we want to make sure we’re doing everything we can to optimize for traffic from Pinterest.
That’s where our data-pin-description attribute comes into play. It helps us add custom Pinterest Text to each of our images so that our images have descriptive and searchable descriptions.
Here’s what that looks like on Pinterest:
Linking an image to an image 😕
Occasionally I’ll notice a blog that is linking all of its images to a page that is just another picture of that image. I’ll provide an example below. If you hover over that image you’ll see that you can click on it. When you do click on it you’ll notice that it opens a new window that contains the same image.
This doesn’t hurt anything, but it’s considered poor form (unless you’re linking to a larger version of the same image to allow the visitor to see it better).
That said, there are instances when it makes sense to add a link to an image, like if you’re publishing a recipe round-up. It might make sense then to add a link back to the source of the original recipe when someone clicks that imgae. You’d do that by:
- Clicking on the image
- Clicking the link icon
- Pasting the link in the field
This is what that’ll look like in code form:
Editing and updating your img tag
We’ve dissected the
img tag and understand the attributes that are located inside, but how the heck do you put them in correctly in the first place (or edit them if you know you’ve done it wrong in the past)?
The easiest way is fill out the information in the Attachment Details when you’re first adding the image.
It’s super simple, but many people rush through this part. The screenshot below shows a basic example of an image with properly formatted Attachment Details. You’ll see that we’ve filled out the Pinterest Text and the Alt Text (and the Title has been auto-filled).
Nerd Note: Here’s a quick explanation on the other fields in this screen: (1) The Pinterest Title is auto-filled by Pinterest and comes from Tasty Pins. You can leave this blank. (2) The Pinterest Repin ID also comes from Tasty Pins and is used to help readers pin existing pins. You can read more about that here. (3) The Title attribute is no longer used in WordPress, so it’s not a critical area to fill out. It was auto-filled here. (4) It’s rare to see a caption used on a food blog (as the pictures are pretty self explanatory). (5) The description (which isn’t pictured, but it’s below the caption) is for your own internal use and won’t show up when you insert the image.
Editing the HTML Manually
At the begin of this post we switched our block from a Visual view to the HTML view:
Once you’re in the HTML view you can easily update the different attributes of the
Did you make it all the way through this post? If you did then you’re the kind of person that’s serious about growing your food blog. 😊
I just threw you a virtual high five for going above and beyond and taking the time to understand the
img tag. Remember: it’s all about small changes that can have a big effect on your blog. I’m off to watch some Mighty Mouse on YouTube!