All subjects · Information Technology · WIT12 3 hour practical exam on web development with HTML, CSS and JavaScript
CSS colours, opacity, gradients and length units
Edexcel IAL Information Technology · WIT12 3 hour practical exam on web development with HTML, CSS and JavaScript
Colours can be written as names, hexadecimal, RGB or HSL, made see-through with opacity and blended with gradients; sizes use absolute or relative length units (spec 8.2.1 to 8.2.3).
Specifying colours (8.2.1)
| Notation | Example (all are the same orange) | How it works |
|---|---|---|
| Colour name | `orange` | One of about 140 named colours |
| Hexadecimal | `#ffa500` | #RRGGBB: two hex digits (00 to ff, which is 0 to 255) for each of red, green and blue |
| Short hex | `#f80` | #RGB is short for #RRGGBB when each pair repeats: #f80 is #ff8800 (a slightly different orange) |
| RGB | `rgb(255, 165, 0)` | Red, green and blue from 0 to 255 |
| HSL | `hsl(39, 100%, 50%)` | Hue (0 to 360 degrees round the colour wheel: 0 red, 120 green, 240 blue), saturation (0% grey to 100% full colour), lightness (0% black, 50% normal, 100% white) |
Opacity and gradients (8.2.2)
opacity: 0.5;makes the whole element, including its text and children, 50% transparent (0 invisible, 1 solid).rgba(0, 0, 0, 0.5)orhsla(0, 0%, 0%, 0.5)makes only that colour transparent, so text on a see-through background stays solid.- Gradients are background images made by the browser:
header {
background-image: linear-gradient(to right, #003366, #3399cc);
}
.badge {
background-image: radial-gradient(circle, yellow, orange);
}HSL makes colour schemes easy: keep the hue and change lightness for lighter and darker shades of one colour.
Length units (8.2.3)
| Unit | Type | Meaning |
|---|---|---|
| px | Absolute | A CSS pixel |
| pt, cm, mm, in | Absolute | Physical units, mainly for print (1in = 96px) |
| % | Relative | A percentage of the parent's size (for width, of the parent's width) |
| em | Relative | Relative to the font size of the element (for font-size, of the parent's font size) |
| rem | Relative | Relative to the font size of the root html element (16px by default) |
| vw, vh | Relative | 1% of the viewport (browser window) width or height |
Relative units scale with the screen or the user's text size, which suits responsive and accessible design
Calculating relative sizes
With the browser default root font size of 16px:
- 1.5rem = 1.5 x 16 = 24px
- a p inside a div with font-size: 20px, given font-size: 0.75em, is 0.75 x 20 = 15px
- width: 50% inside a 960px container is 480px
- 10vw in a 1200px-wide window is 120px
Using rem or em for text lets users who increase their browser's text size get bigger text everywhere.
Worked example
Convert rgb(0, 128, 255) to hexadecimal.
- 0 in hex is 00.
- 128 = 8 x 16 + 0, which is 80 in hex.
- 255 = 15 x 16 + 15, which is ff.
Answer: #0080ff
Check yourself
- What is rgb(255, 0, 255) written as a six-digit hexadecimal colour? Type it with the #.
Show answer
#ff00ff. 255 is ff and 0 is 00, so #ff00ff.
- The root font size is 16px. How many pixels is 2.5rem?
Show answer
40 px. 2.5 x 16 = 40.
- A div has font-size: 18px. A span inside it has font-size: 1.5em. What is the span's font size in pixels?
Show answer
27 px. em for font-size is relative to the parent: 1.5 x 18 = 27.
- A banner needs a semi-transparent black background but solid white text. Which declaration should be used on the banner?
- background-color: rgba(0, 0, 0, 0.6);
- opacity: 0.6;
- background-color: black; opacity: 0.6;
- color: rgba(255, 255, 255, 0.6);
Show answer
background-color: rgba(0, 0, 0, 0.6);. rgba makes only the background colour transparent. opacity would fade the text as well.
- In hsl(120, 100%, 50%), what does 120 set?
- The amount of red from 0 to 255
- The lightness as a percentage
- The hue, as an angle on the colour wheel (green)
- The opacity
Show answer
The hue, as an angle on the colour wheel (green). Hue is an angle from 0 to 360: 0 red, 120 green, 240 blue.
- Which unit is relative to the width of the browser window?
- vw
- px
- pt
- cm
Show answer
vw. 1vw is 1% of the viewport width.
- The browser window is 1440px wide. How many pixels wide is an element with width: 25vw?
Show answer
360 px. 25% of 1440 = 360.
- Which value creates a background that fades from white at the top to grey at the bottom?
- radial-gradient(to bottom, white, grey)
- gradient(white, grey)
- linear-gradient(grey, white, to top-left)
- linear-gradient(to bottom, white, grey)
Show answer
linear-gradient(to bottom, white, grey). linear-gradient takes a direction and then the colours in order.
Sources
- Pearson Edexcel International Advanced Subsidiary/Advanced Level in Information Technology specification (first teaching 2018), Unit 2 Topics 7 to 11
- Pearson qualifications: Edexcel International Advanced Level Information Technology (2018)
Last updated 8 November 2026. Spotted a mistake? Tell us.