![]() |
VOOZH | about |
CSS units define the size of elements and help control layout and spacing in a webpage. They can be absolute or relative depending on how values are calculated.
CSS provides two main types of units:
Absolute units in CSS, such as px, cm, and mm, have fixed values and do not change based on the viewport or parent elements. They are used when precise, unchanging measurements are needed for elements.
A centimeter (cm) is a length unit in the SI system, derived from the meter (m), with 1 m = 100 cm. The SI system is maintained by the BIPM(International Bureau of Weights and Measures).
1 cm = 1 / 100 mThe millimeter (mm), introduced during the French Revolution's metric system, became part of the SI system. It is maintained by the International Bureau of Weights and Measures (BIPM).
1 cm=10mm
1mm=1/10 cmThe inch originated from ancient human measurements, based on the width of a thumb or the length of a dried grain of barley. It was standardized in 1959 by an international agreement, defining it as exactly 25.4 millimeters to align with the metric system.
1 inch = 2.54cm =2.54 * 1cm=2.54* 10mm= 25.4mmA pixel (px) is the smallest unit on a digital screen, representing a point of light. More pixels mean better image clarity and higher screen resolution.
1px = 0.26mmA point (pt) is a typography unit equal to 1/72 of an inch, used for font sizes and spacing in design.
1pt = 1/72 inch(1 inch=2.54cm)
1pt= 1.33pxA pica is a unit used in print and design, equal to 12 points or 1/6 of an inch (4.233 mm). It helps define layout dimensions like font and image sizes.
1pc=12pt=15.96pxRelative units are CSS units that scale based on another value such as parent size or viewport.
In CSS , the "em" unit refers to the font-size of its parent element, defaulting to the root element (<html>) if it's the only one in the DOM.
In CSS, rem is based on the font-size of the root element (<html>) and stays the same in all cases.
In CSS, vw depends on the viewport width, which changes with screen size, so an Android phone has a smaller vw than an HD TV.
In this code, the div's height is 50% of the viewport width and 10% of the viewport height.
The vh unit in CSS is 1% of the viewport height, useful for responsive design to scale elements with the window size.
The % unit in CSS is relative to the parent element's size, allowing elements to adjust dynamically for responsive design.
The vmin unit in CSS is based on the smaller of the viewport's width or height, helping elements scale proportionally for responsive designs.
vmax is a CSS unit that represents 1% of the larger viewport dimension (width or height), helping elements scale based on the screen's dominant size.
The ch unit in CSS represents the width of the "0" character of the current font. It's a relative unit commonly used for sizing text elements to maintain proportional widths and heights based on character dimensions.
Relative to the height of the letter "x" in the current font, primarily used for vertical spacing and font-related measurements.
This unit is relative and depends on the line-height of the current element.
Choosing the right CSS unit depends on the layout needs, responsiveness, and screen size, as absolute units offer fixed sizing while relative units adapt better to different devices.
Absolute units are used when a fixed and precise size is required, such as in print layouts, PDFs, borders, or elements that must remain the same size regardless of screen size or device.
Relative units are used to create responsive and flexible layouts, as their sizes adjust based on screen size, parent elements, or user settings, making them ideal for modern, device-friendly web designs.
Absolute units have fixed sizes that don’t change with screen or parent elements, while relative units scale based on the parent, root, or viewport, making layouts more flexible and responsive.
| Absolute Units | Relative Units |
|---|---|
| Not responsive; sizes remain fixed regardless of screen size or resolution. | Highly responsive; adjust dynamically based on context. |
| Independent of parent elements or viewport size. | Dependent on parent, root, or viewport dimensions. |
| Harder to scale across different devices. | Scales well for responsive design. |
| Ensures exact sizing, providing uniformity across devices. | Size may vary based on parent or viewport, allowing flexibility. |
| Can hinder accessibility by not adjusting to user-defined browser settings. | Adapts to user settings like font size, enhancing accessibility. |
| May be faster to render as values are fixed. | Requires calculation based on context, potentially increasing rendering time. |