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.
Want to practice doing some of this on your own? You can click on the button below to download the images and text that I’ll use in the examples.
What is the img tag?
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.
- Login to your blog (we’ll be using a WordPress blog in this example).
- Hover over Pages and select Add New (don’t worry, we won’t be publishing this page).
- Add a title of Chocolate Chip Muffins and then click Add Media.
- Drag the chocolate-chip-muffin.jpg image from the lesson material folder into the Insert Media window.
- Fill in the Attachment Details and Attachment Display Settings like the screenshot below. Click Insert into page.
- After clicking Insert into page, WordPress will drop the image into the 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 Text tab in the top right corner.
- 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 img tag
The first part we need to look at is the img tag itself. I put a red box around the beginning and the end of the image tag. The first red box shows where the tag starts, and the second red box 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. The parts that are inside of the 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
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). One thing that is important to point out in the class attribute area is the “align” class. In our example above, the align class is set to alignnone.
As the name implies, this is the way that your image is aligned in the post. There are four choices for alignment that you can pick from when putting an image into a post: Left, Center, Right and None.
Here’s how those alignments look:
Nerd note: If you want to switch your image’s alignment you can just change the text in the class attribute. For instance, we can change our example image to have a left alignment by changing alignnone to alignleft.
There are two other classes we see, size-full and wp-image-16139. These are not classes that we’ll need to change or adjust manually.
That’s all that we need to know with the class attribute for now. Let’s move on to the alt attribute.
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 three reasons why the alt attribute is really important:
- Usability: It communicates information about your image to visitors that are visually impaired.
- SEO: It communicates to search engines what your image is about.
- Pinterest: It’s the information that is auto populated into the description area when an image is pinned from your site.
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.
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 “stuffing” 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 “black hat” SEO and could actually end up hurting your blog’s rank in Google. Just do your best to provide an accurate description of the image.
Understatement: Pinterest has the potential to drive traffic to your food blog.
If you have a post that becomes popular on Pinterest it has the potential to send HUGE amounts of traffic to your blog. The most important part of a viral Pinterest post is how an image looks, but the alt attribute also plays a really important role when an image is pinned. This is because the default description for a Pinterest pin is the text in the image’s alt attribute.
That’s a really important point, so I’m going to repeat it: The default description for a Pinterest pin is the text in the image’s alt attribute.
Here’s an example:
A creative, eye-catching description can go a long way with Pinterest.
Want to take it a step further?
Here’s a Food Blogger Pro certified “super tip”: Include your blog’s URL at the end of the alt attribute. The URL will be clickable once the image gets pinned to Pinterest and will act as a direct link back to your site.
Here’s an example:
Here’s an example of some Pinch of Yum pins that include the URL in the description so you can see how this really looks on Pinterest: https://www.pinterest.com/search/pins/?q=pinchofyum
Can you see how it’s a major benefit to have your blog’s URL in the description of a Pinterest pin? Pretty darn cool.
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 2014:
- …and in that folder there is another folder called 01:
- …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_9205.jpg, because that’s communicating to the search engine that your image is about “IMG_9205.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
- Press return (enter) on your keyboard.
- Type in the new file name.
- Press return (enter) to finish editing.
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 height and width attributes
WordPress should automatically add these attributes to your img tag, but if they’re not included you need to add them. The height and width attributes are important because they save the web browser from having to measure the image’s file size on its own.
It’s kind of like handing someone a picture and asking them to go buy a frame for it. If you start by first telling them the exact dimensions of the picture then they’ll be able to quickly find the correct frame size. If you don’t tell them the dimensions then they’ll have to measure the picture before buying the frame, which takes a lot longer.
The same is true for images online. If you tell the web browser the size of the image then it doesn’t have to measure the image on its own, which means your page will load faster.
Linking an image to an image 🙁
Occasionally I’ll notice a blog that is linking all of it’s 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).
The issue comes from having “Media File” selected under “Link To” when you first add the image to your post.
You’ll usually want “Link To” set to “None.”
If you notice this issue on old posts and you’d like to fix it you can remove the anchor element (highlighted in red below) that is wrapped around the img tag.
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)?
Attachment Details and Attachment Display Settings
The easiest way is fill out the information in the Attachment Details and Attachment Display Settings when you’re first adding the image. It’s insanely simple, but many people rush through this part. The screenshot below shows a basic example of an image with properly formatted Attachment Details and Attachment Display Settings.
Nerd Note: Here’s a quick explanation on the other fields in this screen: (1) The title attribute is no longer used in WordPress, so it’s not a critical area to fill out. (2) It’s rare to see a caption used on a food blog (as the pictures are pretty self explanatory. (3) The description is for your own internal use and won’t show up when you insert the image.
Editing the HTML in the text tab
At the begin of this post we switched our editing screen from the Visual tab to the Text tab. Once you’re in the Text tab you can easily update the different attributes of the img tag. Although you can technically change all of them, the only one you’ll really want to change is the alt attribute (and possibly the alignment class).
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!