This article was co-authored by Tyrone Showers and by wikiHow staff writer, Hannah Dillon. Tyrone Showers is a Technologist and the Co-owner of Taliferro Group, an IT consulting company based in Seattle, Washington. With over 35 years of professional experience, he specializes in API Design, e-Commerce, Operational Efficiency, and website development. He has a B.S. in Computer Science from DeVry Institute of Technology.
There are 7 references cited in this article, which can be found at the bottom of the page.
This article has been fact-checked, ensuring the accuracy of any cited facts and confirming the authority of its sources.
This article has been viewed 2,082,827 times.
If you need to add an image using HTML but aren't sure where to start, this is the perfect article for you. Inserting images using HTML is very simple, and once you get it down, you'll be doing it like it's second nature. Keep reading to learn how!
How to Add an Image in HTML: Quick Steps
- Type <img src="".
- Paste your image link between the quotes: <img src="url_here".
- Add an alt attribute after the URL: <img src="url_here" alt="alt_text_here".
- Close the tag with a bracket: <img src="url_here" alt="alt_text_here">.
Steps
Sample HTML for Inserting Images
Inserting the Image
-
Upload your image. There are many free image hosting services. Some of the most popular free online image hosts are Imgur, ImgBB, Postimages, and Imgbox.
- Some image hosts require you to sign up for an account, while others let you upload images without an account. However, it's always best to sign up for an account so you can easily find the direct link to the image later.
- Some blog-hosting services let you upload images using built-in tools.
- If you have a paid web host, upload the image to your own site using an FTP service. Creating an "images" directory is recommended to keep your files organized.
-
Open your HTML file. Open the HTML document for the web page where the image will be displayed.
- If you are trying to insert an image on a forum, you can type this code directly into your post. However, be aware that some forums don't use HTML; instead, they use a different coding language called BBCode. If you're not sure how to insert an image on a forum, ask the forum admin for assistance.
Advertisement -
Begin with the img tag. Find the point in your HTML body where you'd like to insert an image. Type <img here.[1] Leave off the closing bracket, for now. We'll close it later.
- The <img> tag is considered an "empty" tag, as it doesn't require a closing tag. Unlike other tags (like <b></b>, there is no "</img>" tag.
-
Add the src attribute with quotes. As you may already know, HTML attributes go inside a tag to modify it. The src attribute tells the browser to display whatever URL you add after the src tag as an image. The code will work without the quotes, but using them is best practice.
- So far, your code should look like this: <img src=""
-
Copy the direct URL to your image. Most image hosts will provide this for you. Look specifically for the direct URL; any other URL won't work. A direct URL ends with the image's file type (e.g., .png, .jpg).
- If you uploaded the image to an images directory on your website, link to it as /images/yourfilenamehere. If this doesn't work, the images directory is probably inside another folder. Move it up to the root directory.
- To copy the URL, highlight it and press Ctrl+C on Windows or ⌘ Cmd+C on Mac.
-
Paste the URL into your img tag between the quotes. To paste the image URL into your tag, click between the quotes and press Ctrl+V on Windows or ⌘ Cmd+V on Mac.
- If you're using an image you uploaded to an image host like Imgur or Postimages, your code should look like <img src="http://www.examplehost.com/my-cute-dog.jpg".
- If you're using an image you uploaded to your blog or website host, you can use a shortened version of the URL. Your code might look something like <img src="images/my-cute-dog.jpg".
-
Add an alt attribute. While the alt attribute isn't necessary to display the image, it's best practice to include it. The alt attribute is what's read when someone using a screen reader looks at your webpage. It's also displayed if the image fails to load.[2] Follow this example, changing the text inside the quotation marks:
- Add the alt attribute just like the src attribute. Then, write a short description of the image. Here's an example: <img src="http://www.examplehost.com/my-cute-dog.jpg" alt="A golden retriever lying on a sofa"
- The best practice for writing alt text is to keep it short, accurately describe what's happening, and don't include the words "image" or "picture."[3]
- If the image you're adding is decorative (like a divider or border), you don't have to include alt text. However, according to the Web Accessibility Initiative, you should still include an empty alt attribute (alt="").[4]
- Add the alt attribute just like the src attribute. Then, write a short description of the image. Here's an example: <img src="http://www.examplehost.com/my-cute-dog.jpg" alt="A golden retriever lying on a sofa"
-
Close your image tag. Add a closing bracket to the end of the tag. You've now created an HTML image tag that will insert an image in your document.
- In our example, the finished HTML code looks like this: <img src="http://www.examplehost.com/my-cute-dog.jpg" alt="A golden retriever lying on a sofa">
-
Save your changes. Save the HTML file to your website. Visit the page you just edited, or refresh the page if you already had it open. You should now see your image. If it's the wrong size or you're unhappy for any other reason, continue to the next section.
Community Q&A
-
QuestionI have an image on my computer. Can I insert it in HTML without uploading it to a website?
Community AnswerYou can, but the image will still only be on your computer, and not visible by anyone else who visits your website. To do this, use the image's file path instead of a URL. To find the file path, use a browser's "Open File" function to open the image, then look at the address bar. It will say something like "C:\Users\wikihow\image.jpg" -
QuestionDoes it have to be a jpg file when inserting images with HTML?
Community AnswerNo. You can use any image file type unless the hosting website only allows certain file types. -
QuestionShould I resize the image before uploading, or can I just use the width and height attributes?
Community AnswerIf you're downsizing a particularly large image, it's best to do that in image editing software before uploading. Your website visitor has to download the exact image you uploaded, even if it only ends up as a tiny thumbnail on his or her screen.
Video
Tips
-
If you see a slash at the end of an img tag (like <img src="urlhere" alt="althere" />), this is a carryover from XHTML, which has been mostly superseded by HTML5. You don't need to add this trailing slash, but some IDEs or web editors may add it for you.[7] It's added because <img> is an empty tag that has no closing tag.Thanks
-
In most cases, you'll want to stick to images in the .gif, .jpeg, .jpg, or .png format. Other formats are unlikely to display correctly on all browsers.Thanks
Warnings
- Do not "hotlink" by using a direct link to someone else's image. This uses up bandwidth on that person's site (and costs them more money) without bringing any visitors to their page. Besides the bad etiquette, a hotlinked image will disappear if the site hosting it goes down.Thanks
Expert Interview
Thanks for reading our article! If you’d like to learn more about HTML basics, check out our in-depth interview with Tyrone Showers.
References
- ↑ https://www.geeksforgeeks.org/html-img-tag/
- ↑ https://developer.mozilla.org/en-US/docs/Learn_web_development/Core/Structuring_content/HTML_images
- ↑ https://www.freecodecamp.org/news/what-is-alt-text-image-alt-text-html-example/
- ↑ https://www.w3.org/WAI/tutorials/images/decorative/
- ↑ https://www.geeksforgeeks.org/html-images/#set-image-size-width-and-height-attribute
- ↑ https://www.geeksforgeeks.org/html-images/#adding-titles-to-an-image
- ↑ https://stackoverflow.com/questions/1778903/why-do-some-html-tags-end-with-a-forward-slash
About This Article
1. Upload the image.
2. Open your HTML file.
3. Type <img src="">
4. Insert the image URL between the quote marks.
Reader Success Stories
-
"This, I think, is the most successful and impressive page, because we know that wikiHow is forever true, it never lies. The images help us more and the way you write is food for thought. I'm fully satisfied with wikiHow."..." more













