Images 1
ππ¨ Technique Card
HTML: Working with Images 1 (practical)
Learn how to add pictures to your web pages and make them look great!
π What youβll learn
- How to use the
<img>
tag - How to set the image source
- How to add image descriptions (for accessibility)
- How to change the size of an image
π Try this example
Save an image in the same folder as your HTML file. Call it cat.png
.
Now use this code in your HTML file:
<!DOCTYPE html>
<html>
<head>
<title>Images in HTML</title>
</head>
<body>
<h1>My Favourite Animal</h1>
<img src="cat.png" alt="A cute cat" width="300" />
<p>This is a picture of a cat. Isnβt it cute?</p>
</body>
</html>
Important
Lots of images found online are copyright protected - we can get free, good quality images which we are allowed to use from pexels and unsplash | when downloading images from pexels the medium quality is okay
π§© Whatβs going on?
Part | What it means |
---|---|
<img> |
Adds an image β it doesnβt need a closing tag! |
src |
The file name of the image (or a web address) |
alt |
Description for screen readers or when image breaks |
width |
How wide the image should be (in pixels) |
π§ͺ Try it yourself!
- Change the file name to another picture:
src="dog.png"
- Use an online image:
src="https://example.com/bird.jpg"
- Add a height:
height="200"
- Remove the
width
andheight
and see what happens!
π‘ Top Tips
- π Make sure your image file is saved in the same folder as your HTML file (unless using a web link).
- π You can control image size using width and height in pixels (
px
). - π¨ Want to center the image or add a border? Try the
CSS: Styling Basics
card!
π You might also like...
π Technique Cards