Absolute units let you set sizes that stay the same no matter the screen or device. They are useful when you want fixed sizes.
Absolute units in CSS
Start learning this pattern below
Jump into concepts and practice - no test required
property: value unit;Common absolute units include cm (centimeters), mm (millimeters), in (inches), px (pixels), pt (points), and pc (picas).
Absolute units do not scale with screen size or user settings.
width: 5cm;height: 2in;margin: 10px;
font-size: 12pt;This example creates a blue box with a fixed width of 5 centimeters and height of 3 centimeters. It has a 1 inch margin around it. The font size inside is set to 12 points for clear text. The box is centered with flexbox for neat alignment.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Absolute Units Example</title> <style> .box { width: 5cm; height: 3cm; background-color: lightblue; border: 2px solid navy; margin: 1in; font-size: 12pt; display: flex; align-items: center; justify-content: center; text-align: center; color: navy; font-family: Arial, sans-serif; } </style> </head> <body> <div class="box" role="region" aria-label="Blue box with fixed size"> This box is 5cm wide and 3cm tall with 1 inch margin. </div> </body> </html>
Absolute units are great for print or when exact size matters.
On screens, pixels (px) are the most common absolute unit.
Be careful: absolute units do not adjust for different screen sizes or zoom levels, so they can cause layout issues on small or large screens.
Absolute units set fixed sizes that do not change with screen or zoom.
Common units: cm, mm, in, px, pt, pc.
Use them when you need precise control over size, like for print or fixed layouts.
Practice
Solution
Step 1: Understand absolute vs relative units
Absolute units are fixed sizes that do not change with screen or zoom, like centimeters (cm), inches (in), pixels (px).Step 2: Identify the absolute unit in options
cmis an absolute unit, whileem,rem, and%are relative units.Final Answer:
cm -> Option DQuick Check:
Absolute unit = cm [OK]
- Confusing relative units like em or rem as absolute
- Thinking % is absolute unit
- Mixing up px as relative
Solution
Step 1: Check correct CSS property syntax
CSS properties use colon (:) after property name and end with semicolon (;). Spaces between number and unit are allowed but not recommended.Step 2: Identify correct spacing and punctuation
width: 5 cm;is correct. Equal sign is invalid.Final Answer:
width: 5 cm; -> Option AQuick Check:
Correct CSS syntax = width: 5 cm; [OK]
- Using equal sign instead of colon
- Omitting semicolon at end
div { width: 2in; }Solution
Step 1: Understand the
inunit meaninginstands for inches, an absolute unit representing physical inches on screen or print.Step 2: Interpret the CSS width value
The width is set to 2 inches, so the box will be exactly 2 inches wide on the screen or print.Final Answer:
2 inches on screen -> Option AQuick Check:
2in means 2 inches width [OK]
in means inches, so width is in inches [OK]- Confusing inches with pixels
- Thinking
inis relative unit - Assuming 2in equals 2cm
p { font-size: 12 pt; }Solution
Step 1: Check CSS unit syntax
In CSS, there should be no space between the number and the unit.12 ptis invalid.Step 2: Confirm the correct usage
The correct syntax isfont-size: 12pt;with no space.Final Answer:
Space between number and unit is invalid -> Option BQuick Check:
No space between number and unit [OK]
- Adding space between number and unit
- Thinking
ptis invalid unit - Forgetting semicolon
Solution
Step 1: Match width and height units to requirements
The width must be 3 centimeters and height 1 inch, so use3cmfor width and1infor height.Step 2: Verify the CSS syntax correctness
The syntaxbox { width: 3cm; height: 1in; }is correct and uses absolute units as required.Final Answer:
box { width: 3cm; height: 1in; } -> Option CQuick Check:
Use correct absolute units for each dimension [OK]
- Mixing units for width and height
- Using pixels instead of absolute units
- Using same unit for both dimensions incorrectly
