---
title: Adding Images | HTML & CSS Basics Made Easy
description: Today's dose of expert advice walks you through adding images to an HTML style sheet.
image: https://blog.flametreepublishing.com/hs-fs/file-3211239657-jpg/images/coding_11.jpg
---

- [Home](https://info.flametreepublishing.com/blog) |
- [ Contact & About Us](https://blog.flametreepublishing.com/contact-us)

T H E   F L A M E   T R E E   B L O G

![Hubspot_Winter_Europe1](https://blog.flametreepublishing.com/hs-fs/hubfs/Hubspot_Winter_Europe1.jpg?width=980&height=200&name=Hubspot_Winter_Europe1.jpg "Hubspot_Winter_Europe1")

# Cooking & Lifestyle Blog

# Adding Images | HTML & CSS Basics Made Easy

Posted by [Matt Knight](https://blog.flametreepublishing.com/simple-recipes/author/matt-knight)

- [Tweet](https://twitter.com/share)

**Most websites contain a lot more than just text.** Images, video and audio can greatly increase your visitor numbers and encourage them to stay longer. Advanced **HTML5** features such as geolocation can improve your site’s interactions with your visitors and, of course, adding a sprinkle of **visual polish** is always a good idea.

Alongside text, **images are the element** that almost every website has in common. Very rarely will you find a contemporary website with a total lack of imagery. Images are **extremely versatile** and have the potential to make a website much more visually appealing. 

### ![coding 11](https://blog.flametreepublishing.com/hs-fs/file-3211239657-jpg/images/coding_11.jpg)Image Formats

Images come in a variety of formats, but on the web there are effectively three formats used: **GIF**, **PNG** and **JPG**. The GIF format is a hangover from the early days of the web and is becoming increasingly uncommon. PNG and JPG, on the other hand, are **widely used**. Both have specific advantages and disadvantages, but together they can satisfy all situations.

**The PNG Format**

PNG (Portable Network Graphics, pronounced ‘ping’) is the best option for graphics (as opposed to **photo-based** imagery) because typically they use lossless compression and so offer better **sharpness** and **accuracy** than JPG. Their other benefit is that they support transparency. This means that a PNG image needn’t have a **solid-coloured background**, and that anything behind them can show through the transparent areas of the PNG.

**The JPG Format**

The JPG format (also known as JPEG, pronounced ‘jay-peg’) uses a complex **image compression** technique to reduce the file size of an image without visibly degrading it. This means that the images can be saved at different quality levels to reduce the file size of an image. The higher the level, the **better the quality**, but the larger the file size; the developer can choose where to strike the balance. JPGs** don’t support transparency** and so are not as suitable for graphics.

- **Hot Tip:** When creating images and graphics, work from a full quality editable version in a lossless format such as PSD (Photoshop’s native format), then export the graphics you need as PNG or JPG files.

### Adding Images

The addition of images to a web page is a **relatively simple** process. However, before adding an image, it is a good idea to store your images in a sub-folder of your site root. 

**The <img> Element**

When adding images to a page we use the **<img> element**. This is a self-closing element, meaning that, you will recall, they only have an opening tag and no closing tag, and can’t have any content nested within them.

![codingwide.jpg](https://blog.flametreepublishing.com/hs-fs/hubfs/codingwide.jpg?width=706&height=205&name=codingwide.jpg "codingwide.jpg")

*When defining more than a couple of attributes, it’s not unusual to split them into separate indented lines, making them easier to read. *

**How to Add an Image**

1. Locate your site folder and create a subfolder within it; name the subfolder ‘**images**’.

2. Find a suitable image. Use your image editor to resize it to **700 pixels wide** and whatever height is proportional to that width for your chosen image. Save a copy of the image into the folder we have just created, using the **JPG format**. Name the file homepageImage.jpg. 

![coding 5](https://blog.flametreepublishing.com/hs-fs/file-3211239677-jpg/images/coding_5.jpg?width=150&height=190&name=coding_5.jpg)

3. Open your site’s homepage (**index. html**) in your text or HTML editor, and locate the **<h2> element** that’s at the top of the <section> element. Create an **empty line** in the HTML, above the <h2> element.

4. Now add the **<img> element** as shown in the illustration (right). The **name attribute value** will be displayed in place of the image if the browser is unable to load it, whilst the alt attribute value is the text that is shown if the user **hovers** the mouse pointer above the image. The **src attribute value** is the URL of the image to use (note we’re using a relative URL).

5. We’re going to create a **style rule** for the image, so find the **<style> element** in the <head> of your page. Add the code shown in the illustration. Note that we’re using an ID selector so that we target only our newly added <img> element. **Save your work** and be sure to view the results in your web browser.

[![codingcover.jpg](https://blog.flametreepublishing.com/hs-fs/hubfs/codingcover.jpg?width=706&height=298&name=codingcover.jpg "codingcover.jpg")](http://www.flametreepublishing.com/Coding-HTML-and-CSS.html)

**This is just one example of a simple piece of expert advice that you can expect from our title *Coding HTML & CSS Basics*. As well as providing help for newcomers to coding, we've packed our book with information for people that have taken their skills up to an intermediate level. So, if you're looking for a great resource to help you learn, then master the art of coding, looking no further than our title. [Click here to take a closer look at the book.](http://www.flametreepublishing.com/Coding-HTML-and-CSS.html) To see it on Amazon, [click here](http://www.amazon.co.uk/Coding-HTML-CSS-Expert-Everyday/dp/1783613920/ref=sr_1_1?ie=UTF8&qid=1437580745&sr=8-1&keywords=9781783613922). **

- If you're looking to get a handle on the confusing coding terminology, just [click here for a helpful article](https://blog.flametreepublishing.com/simple-recipes/bid/77493/Coding-Terminology-Expert-Advice-Made-Easy). 

 Topics: [technology](https://blog.flametreepublishing.com/simple-recipes/topic/technology), [expert advice made easy](https://blog.flametreepublishing.com/simple-recipes/topic/expert-advice-made-easy), [computing and apps](https://blog.flametreepublishing.com/simple-recipes/topic/computing-and-apps), [Everyday Guides](https://blog.flametreepublishing.com/simple-recipes/topic/everyday-guides)

### Subscribe for email updates

### Free Download

[![FREE Recipe book here](https://no-cache.hubspot.com/cta/default/293166/e3e14ba9-7e61-4ba8-a1ef-78b8e2fc9c10.png)](http://cta-redirect.hubspot.com/cta/redirect/293166/e3e14ba9-7e61-4ba8-a1ef-78b8e2fc9c10)

Download a digital Recipe book, a special edition **Party Cakes****.**

![Party Cakes, Simple recipes](https://blog.flametreepublishing.com/hs-fs/file-271894719-jpg/images/24pp-partycakes_special_edition_cover-resized-171.jpg)

### About Us

With over 20 years of quick and easy recipes **FLAME TREE** has thousands of dishes for the beginner and the enthusiastic!

![FLAME-TREE-Hubspot-Head.gif](https://blog.flametreepublishing.com/hs-fs/hub/293166/file-398222920.gif?width=251&height=354&name=file-398222920.gif "FLAME-TREE-Hubspot-Head.gif")

### Stay up to date:

<http://pinterest.com/flametreearts/><https://www.facebook.com/124068147666850><https://www.instagram.com/flametreepublishing><https://twitter.com/flametreetweet>

### Subscribe to Email Updates

### Posts by category

- [Apple IOS (4)](https://blog.flametreepublishing.com/simple-recipes/topic/apple-ios)
- [baking (12)](https://blog.flametreepublishing.com/simple-recipes/topic/baking)
- [baking soda (1)](https://blog.flametreepublishing.com/simple-recipes/topic/baking-soda)
- [barbecue (1)](https://blog.flametreepublishing.com/simple-recipes/topic/barbecue)
- [bee keeping (1)](https://blog.flametreepublishing.com/simple-recipes/topic/bee-keeping)
- [beer (1)](https://blog.flametreepublishing.com/simple-recipes/topic/beer)
- [best kept secrets (3)](https://blog.flametreepublishing.com/simple-recipes/topic/best-kept-secrets)
- [bicarbonate of soda (2)](https://blog.flametreepublishing.com/simple-recipes/topic/bicarbonate-of-soda)
- [blog (7)](https://blog.flametreepublishing.com/simple-recipes/topic/blog)
- [blogging (3)](https://blog.flametreepublishing.com/simple-recipes/topic/blogging)
- [Christmas (3)](https://blog.flametreepublishing.com/simple-recipes/topic/christmas)
- [cleaning (1)](https://blog.flametreepublishing.com/simple-recipes/topic/cleaning)
- [computing and apps (26)](https://blog.flametreepublishing.com/simple-recipes/topic/computing-and-apps)
- [cookery (43)](https://blog.flametreepublishing.com/simple-recipes/topic/cookery)
- [cooking (1)](https://blog.flametreepublishing.com/simple-recipes/topic/cooking)
- [cooking on a budget (2)](https://blog.flametreepublishing.com/simple-recipes/topic/cooking-on-a-budget)
- [craft beer (1)](https://blog.flametreepublishing.com/simple-recipes/topic/craft-beer)
- [cycling (8)](https://blog.flametreepublishing.com/simple-recipes/topic/cycling)
- [deep clean (2)](https://blog.flametreepublishing.com/simple-recipes/topic/deep-clean)
- [Digging and Planting (6)](https://blog.flametreepublishing.com/simple-recipes/topic/digging-and-planting)
- [drawing (1)](https://blog.flametreepublishing.com/simple-recipes/topic/drawing)
- [Everyday Guides (11)](https://blog.flametreepublishing.com/simple-recipes/topic/everyday-guides)
- [expert advice made easy (57)](https://blog.flametreepublishing.com/simple-recipes/topic/expert-advice-made-easy)
- [food (2)](https://blog.flametreepublishing.com/simple-recipes/topic/food)
- [Gardening (10)](https://blog.flametreepublishing.com/simple-recipes/topic/gardening)
- [greek islands (1)](https://blog.flametreepublishing.com/simple-recipes/topic/greek-islands)
- [greek mythology (1)](https://blog.flametreepublishing.com/simple-recipes/topic/greek-mythology)
- [Handy Animal ID Guides (1)](https://blog.flametreepublishing.com/simple-recipes/topic/handy-animal-id-guides)
- [Handy Petcare Guides (1)](https://blog.flametreepublishing.com/simple-recipes/topic/handy-petcare-guides)
- [healthy eating (20)](https://blog.flametreepublishing.com/simple-recipes/topic/healthy-eating)
- [house cleaning (2)](https://blog.flametreepublishing.com/simple-recipes/topic/house-cleaning)
- [indoor activities (2)](https://blog.flametreepublishing.com/simple-recipes/topic/indoor-activities)
- [indoors (2)](https://blog.flametreepublishing.com/simple-recipes/topic/indoors)
- [iPhone (2)](https://blog.flametreepublishing.com/simple-recipes/topic/iphone)
- [kitchen and home (4)](https://blog.flametreepublishing.com/simple-recipes/topic/kitchen-and-home)
- [lifestyle (2)](https://blog.flametreepublishing.com/simple-recipes/topic/lifestyle)
- [Manga (2)](https://blog.flametreepublishing.com/simple-recipes/topic/manga)
- [Microsoft Excel (2)](https://blog.flametreepublishing.com/simple-recipes/topic/microsoft-excel)
- [Microsoft Windows (3)](https://blog.flametreepublishing.com/simple-recipes/topic/microsoft-windows)
- [nutrition and health (1)](https://blog.flametreepublishing.com/simple-recipes/topic/nutrition-and-health)
- [Photoshop (2)](https://blog.flametreepublishing.com/simple-recipes/topic/photoshop)
- [prague (1)](https://blog.flametreepublishing.com/simple-recipes/topic/prague)
- [Quick and Easy Recipes (40)](https://blog.flametreepublishing.com/simple-recipes/topic/quick-and-easy-recipes)
- [recipes and preparation (2)](https://blog.flametreepublishing.com/simple-recipes/topic/recipes-and-preparation)
- [running (8)](https://blog.flametreepublishing.com/simple-recipes/topic/running)
- [scotland (1)](https://blog.flametreepublishing.com/simple-recipes/topic/scotland)
- [smallholding (1)](https://blog.flametreepublishing.com/simple-recipes/topic/smallholding)
- [student recipes (14)](https://blog.flametreepublishing.com/simple-recipes/topic/student-recipes)
- [summer (2)](https://blog.flametreepublishing.com/simple-recipes/topic/summer)
- [superfood (1)](https://blog.flametreepublishing.com/simple-recipes/topic/superfood)
- [technology (28)](https://blog.flametreepublishing.com/simple-recipes/topic/technology)
- [Travel (6)](https://blog.flametreepublishing.com/simple-recipes/topic/travel)
- [Twitter (7)](https://blog.flametreepublishing.com/simple-recipes/topic/twitter)
- [vinegar (2)](https://blog.flametreepublishing.com/simple-recipes/topic/vinegar)

- [Home](http://classic-migration-sandbox-293166.hs-sites.com/) | [Flame Tree Fiction](https://blog.flametreepublishing.com/fantasy-gothic) | [Gift](https://blog.flametreepublishing.com/art-of-fine-gifts) | [Podcast](https://lnk.bio/flametreepodcast) | 
- [Music](https://blog.flametreepublishing.com/classic-rock-bands) |
-  [Lifestyle](https://blog.flametreepublishing.com/simple-recipes) |
-  [Links](https://blog.flametreepublishing.com/links/)

© 2025 FLAME TREE PUBLISHING LTD. [flametreepublishing.com](https://flametreepublishing.com)