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
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.