Pankaj Shah web agency director in London with over 20 years of experience in web design and project management

I hope you enjoy reading our blog posts.

If you want DCP to build you an awesome website, click here.

HTML5 & CSS3 – Beginners Tutorial – Part 7 – [ HTML Image Tags Tutorial ]

In this tutorial, we explore how to add images to a web page using HTML5 and CSS3. We cover creating an images folder, downloading images from Unsplash, renaming files, and using the IMG tag with attributes like source, width, height, and alt text.

Additionally, we discuss the importance of accessibility and image alignment. This comprehensive guide is perfect for beginners looking to enhance their web development skills.

Welcome to the seventh part of our HTML and CSS beginners tutorial series. In this tutorial, we will learn how to add images to our web pages. This is an essential skill for any web developer, as images play a crucial role in enhancing the visual appeal and user experience of a website.

Setting Up Your Workspace

To begin, open your Notepad file where you have been writing your HTML code. Simultaneously, open Google Chrome to preview your web page. To make it easier to work, minimise the browser window so you can access your project folder.

Creating an Images Folder

Within your project folder, create a new folder named images. This folder will be used to store all the pictures you want to display on your web page.

Downloading Images

Next, we will download an image to use in our project. A great resource for free stock images is Unsplash. Navigate to Unsplash and find a suitable image for your web page. For this tutorial, we will select an image and download it. Remember to acknowledge the photographer, as it is good practice to give credit for the images you use.

Renaming the Image

Once the image is downloaded, it is important to rename it for easier reference. You can rename the file by right-clicking on it and selecting “Rename,” or by clicking on the file once and then clicking again (not too fast). Alternatively, you can select the file and press F2 on your keyboard. For this tutorial, we will rename the image to image1.jpg.

Adding the Image to Your HTML Code

Now that we have our image ready, we will add it to our HTML code. Locate the section in your code where you want to insert the image, typically below any existing content like lists or text.

Writing the IMG Tag

To display the image, we will use the <img> tag. The basic syntax for the image tag is as follows:

    
     <img decoding="async" src="path/to/image" alt="description" width="value" height="value">
    
   

In our case, the src attribute will point to the location of our image. Since we created an images folder and named our image image1.jpg, the path will be images/image1.jpg.

Example Code

Here’s how the code will look:

    
     <img fetchpriority="high" fetchpriority="high" decoding="async" src="images/image1.jpg" alt="A beautiful flower painting" width="300" height="200">
    
   

After adding this code, save your file and refresh your browser to see the image displayed on your web page.

Troubleshooting Common Issues

If the image does not appear, check the following:

  • Ensure the file path is correct. The folder name and file name must match exactly, including capitalisation.
  • Make sure you have included the width and height attributes to prevent the image from displaying too large or too small.

Resizing Images

If the image appears too large, you can adjust the width and height attributes. For example, setting the width to 300 and height to 200 will resize the image appropriately without distorting its aspect ratio.

Importance of the Alt Attribute

Another important aspect of the <img> tag is the alt attribute. This attribute provides a text description of the image, which is crucial for accessibility. Screen readers use this text to describe images to visually impaired users. Additionally, using descriptive alt text can improve your website’s SEO.

Example of Alt Text

In our example, we used:

    
     alt="A beautiful flower painting"
    
   

This description helps users understand what the image represents, even if they cannot see it.

Image Alignment

By default, images are left-aligned in HTML. However, you can change the alignment using the align attribute. For example:

    
     <img decoding="async" src="images/image1.jpg" alt="A beautiful flower painting" width="300" height="200" align="right">
    
   

This code will align the image to the right side of the page. You can also use CSS for more advanced alignment options, which we will cover in future tutorials.

Conclusion

In this tutorial, we covered how to add images to your web page using HTML5 and CSS3. We discussed creating an images folder, downloading images, renaming files, and using the <img> tag with various attributes.

Remember to always include alt text for accessibility and SEO purposes. In future tutorials, we will explore more advanced techniques for image manipulation and styling using CSS. Thank you for following along, and I look forward to seeing you in the next part of our series!

Author

Picture of Pankaj Shah

Pankaj Shah

Pankaj Shah is the founder of DCP Web Designers, an award-winning London-based web design and digital marketing agency. With over 20 years of experience, he specialises in WordPress web design, WooCommerce, SEO and helping businesses build effective online solutions.
Tell Us Your Thoughts

This website (dcpweb.co.uk) uses cookies to improve your browsing experience and help us understand how our site is used. By continuing to browse this website, you agree to our use of cookies.

To learn more about how we collect, use, and protect your data, please read our Privacy Policy.

Since 2004, we have designed and developed websites for companies across a wide range of industries, from local service businesses to ecommerce brands and professional organisations.

Our focus is on creating websites that not only look professional, but also perform well in search engines, attract the right audience and support long-term business growth.

If you are looking for experienced web designers who understand how to build websites that deliver real results, our team is here to help.

Privacy Policy

Last Updated: 01/07/2024

Different Colour Productions Ltd (“we,” “us,” or “our”) is committed to protecting your privacy. This Privacy Policy outlines our practices concerning the collection, use, and disclosure of personal information when you visit our website or engage with our services. By using our website and services, you consent to the terms outlined in this Privacy Policy.

1. Information We Collect

We collect various types of information to provide and improve our services. The types of information we may collect include:

1.1. Personal Information: This may include your name, email address, phone number, and any other information you provide when you contact us, request information, or subscribe to our newsletter.

1.2. Log Data: When you visit our website, we automatically collect information, such as your IP address, browser type, pages visited, and the time and date of your visit.

1.3. Cookies and Similar Technologies: We use cookies and other tracking technologies to improve your experience on our website. You can adjust your browser settings to reject cookies or be alerted when cookies are being used.

2. How We Use Your Information

We use the collected information for various purposes, including:

2.1. Providing Services: To provide web design and related services you have requested from us.

2.2. Communication: To respond to your inquiries, send updates, and provide customer support.

2.3. Analytics: To analyse and improve our website and services, as well as monitor usage patterns.

3. Information Sharing and Disclosure

We do not sell or rent your personal information to third parties. However, we may share your information with third parties under the following circumstances:

3.1. Service Providers: We may share your information with trusted service providers who help us deliver our services, such as hosting providers, analytics providers, and marketing services.

3.2. Legal Obligations: We may disclose your information when required by law, to comply with legal processes, or to protect our rights, privacy, safety, or property.

4. Your Choices

You have choices regarding your personal information:

4.1. Access and Update: You can access and update your personal information by contacting us.

4.2. Marketing Communications: You can opt out of receiving marketing communications from us by following the unsubscribe instructions in our emails or emailing [email protected]

5. Security

We take appropriate measures to protect your personal information from unauthorised access, disclosure, alteration, or destruction.

6. Links to Other Websites

Our website may contain links to third-party websites. We are not responsible for the privacy practices of these websites. We recommend reviewing their respective privacy policies.

7. Changes to this Privacy Policy

We may update this Privacy Policy from time to time to reflect changes in our practices. Any changes will be posted on this page, and the date at the top will indicate the latest update.

8. Contact Us

If you have any questions or concerns about this Privacy Policy or our practices, please contact us at: [email protected]

By using our website and services, you acknowledge that you have read and agree to this Privacy Policy. Different Colour Productions Ltd is committed to safeguarding your personal information and respecting your privacy rights.

ThreeBestRated Top 3 Website Designers in London 2026 award for DCP Web Designers Certificate