All subjects · Information Technology · WIT12 3 hour practical exam on web development with HTML, CSS and JavaScript

Images on web pages: formats, size, resolution and alt text

Edexcel IAL Information Technology · WIT12 3 hour practical exam on web development with HTML, CSS and JavaScript

Images must be the right format and size, keep their proportions, sit in the right place and have alt text (spec 7.3.1).

Practise this in the app: instant marking and a fix for every mistake. Free, no email needed to start.

Practise this lesson

The img element

<img src="images/pool.jpg" alt="Children having a swimming lesson in the main pool" width="300" height="200">

File formats

FormatBest forNotes
JPEG (.jpg)PhotographsLossy compression: small files, many colours, no transparency
PNG (.png)Logos, icons, screenshots, images needing transparencyLossless; supports transparency; larger files for photos
GIF (.gif)Simple animations, very simple graphicsOnly 256 colours; supports animation and simple transparency
SVG (.svg)Logos and icons that must scaleVector: stays sharp at any size
WebP (.webp)Photos and graphics on modern sitesSmaller files than JPEG or PNG at similar quality

Size, resolution and proportions

Screens display images in pixels, so prepare images at the size they will be shown: a 4000-pixel-wide photo shown 300 pixels wide wastes download time. Print resolution (dots per inch) does not matter on screen; the pixel dimensions do.

To retain proportions (the aspect ratio), change width and height by the same factor, or set only one of them and let the other be automatic. In CSS: width: 100%; height: auto;.

Example: a 1200 x 800 image shown 300 pixels wide must be 200 pixels high, because 800 / 1200 x 300 = 200.

Positioning an image (floating it beside text, centring it) is done with CSS, covered in the CSS lessons.

Worked example

A photo is 1200 pixels wide and 800 pixels high. It must be shown 300 pixels wide without distortion. What height should be set?

  1. Scale factor = 300 / 1200 = 0.25
  2. Height = 800 x 0.25 = 200

Answer: 200 pixels (or set height to auto)

Key idea: img needs src and alt; use JPEG for photos, PNG for transparency and sharp graphics, GIF for simple animation, SVG for scalable logos; size images in pixels for the screen and keep the aspect ratio.

Check yourself

  1. An image is 800 pixels wide and 600 pixels high. It is resized to 200 pixels wide with its proportions kept. What is the new height in pixels?
    Show answer

    150 pixels. Scale factor 200 / 800 = 0.25; 600 x 0.25 = 150.

  2. Which format is best for a full-colour company logo with sharp edges and a soft, semi-transparent shadow?
    • JPEG
    • GIF
    • PNG
    • BMP
    Show answer

    PNG. PNG is lossless, keeps millions of colours and supports partial transparency. JPEG has no transparency and blurs sharp edges; GIF has only 256 colours and on-or-off transparency.

  3. Give two reasons why every content image should have an alt attribute.
    Show answer

    A screen reader reads the alt text to blind users, and the text is displayed if the image fails to load.. Alt text makes the image accessible to screen reader users, appears when the image cannot be shown, and helps search engines understand the image.

  4. What should the alt attribute be for a purely decorative border image?
    • The file name of the image
    • The word image
    • It should be left out completely
    • An empty value: alt=""
    Show answer

    An empty value: alt="". An empty alt tells screen readers to skip the image. Leaving alt out makes some screen readers read the file name.

  5. A gallery of holiday photographs must load quickly. Which format suits the photos best?
    • GIF
    • JPEG
    • PNG-8 with 256 colours
    • SVG
    Show answer

    JPEG. JPEG's lossy compression gives small files for photographs with many colours.

  6. Why should an image be resized before it is put on a web page instead of being shown smaller using width and height?
    • Browsers cannot display large images
    • Resized images get alt text automatically
    • The width attribute only works on PNG files
    • A large file still downloads in full, wasting time and data
    Show answer

    A large file still downloads in full, wasting time and data. The browser downloads the whole file whatever size it is displayed at, so oversized images slow the page.

Practise with instant feedback

Sources

Last updated 8 November 2026. Spotted a mistake? Tell us.