Absolute Units in CSS


Absolute units in CSS are units of measurement that remain constant and are not affected by the environment or the content. They are used to specify fixed sizes and layouts, independent of the viewport or screen size. Absolute units are useful when you want consistent and predictable dimensions, regardless of the device or context, such as in print design, icons, or elements that should not scale or adjust with screen size changes.

absolute-units-in-css


Below are some of the most commonly used absolute units in CSS, including syntax and examples:

Pixels (px)

Definition: Pixels are the most commonly used absolute unit in CSS. They represent a single dot on the screen.

 

Use Case: Setting the size of fonts, images, and elements where you need precise control over dimensions.

 

Example:

div {
    width: 300px;
    height: 200px;
    font-size: 16px;
    margin: 10px;
} 

Points (pt)

Definition: Points are mainly used in print media. 1 point is equal to 1/72 of an inch.

 

Use Case: Frequently used in print layouts to define font size or element spacing when designing for print.

 

Example:

body {
    font-size: 12pt;
}

Inches (in)

Definition: Inches are a unit of length that corresponds to 2.54 centimeters.

 

Use Case: Often used in print media when you want to define dimensions based on physical measurements.

 

Example:

div {
    width: 5in;
    height: 3in;
}

Centimeters (cm)

Definition: Centimeters are another physical unit of measurement. 1 inch equals 2.54 cm.

 

Use Case: Useful for print or physical document layout where exact physical dimensions are required.

 

Example:

div {
    width: 10cm;
    height: 7cm;
}

Millimeters (mm)

Definition: Millimeters are a smaller unit of length, where 1 cm equals 10 mm.

 

Use Case: Used for precision in print media or physical layouts when you need very fine measurements.

 

Example:

div {
    width: 50mm;
    height: 30mm;
}

Unit Common Use Case Relative to Screen/Viewport? Conversion
px Web design, layouts, images No Fixed, pixel-based
pt Print design (fonts, documents) No 1pt = 1/72 inch
in Print design, layouts No 1in = 2.54cm
cm Print layouts, measurements No 1cm = 10mm
mm Precision layouts, print media No 1mm = 1/10 cm
pc Print design, typesetting No 1pc = 12pt



OnlineTpoint is a website that is meant to offer basic knowledge, practice and learning materials. Though all the examples have been tested and verified, we cannot ensure the correctness or completeness of all the information on our website. All contents published on this website are subject to copyright and are owned by OnlineTpoint. By using this website, you agree that you have read and understood our Terms of Use, Cookie Policy and Privacy Policy.