Languages
[Edit]
EN

CSS - units

0 points
Created by:
nickkk0
647

In this article, we would like to explain CSS units.

Introduction

Edit

In CSS, there are two main types of units: relative units and absolute.

Relative units are units based on other length measurements. They allow you to specify lengths as a multiple of some other value, rather than as an absolute value.

Absolute units, on the other hand, correspond to physical lengths. They allow you to specify lengths in terms of actual physical distances, such as inches, centimeters, or millimeters.

Some units, like px and in, are based on the resolution of the screen or device, while others, like em and rem, are based on font sizes. Additionally, some units, like vh and vw, are based on the size of the viewport (the full size of the browser window).

CSS units

Edit

Relative units

Edit
UnitDescription
emrepresents the font size of the element
remrepresents the font size of the root element (typically the <html> element)
%represents a percentage of the parent element's size
vhrepresents a percentage of the viewport's height (the full size of the browser window)
vwrepresents a percentage of the viewport's width (the full size of the browser window)
vminrepresents a percentage of the viewport's smaller dimension (either the height or the width)
vmaxrepresents a percentage of the viewport's larger dimension (either the height or the width)
exrepresents a value relative to the x-height of the current font
chrepresents a value relative to the width of the 0 (zero)

Absolute units

Edit
UnitDescription
pxpixels, which correspond to actual physical pixels on the screen
ininches
cmcentimeters
mmmillimeters
ptpoints (1/72 of an inch)
pcpicas (1/6 of an inch)

Note:

Absolute units are not recommended to use in web design because they do not scale well across different devices with different screen sizes and resolutions.

 

References

Edit
  1. CSS values and units - Learn web development | MDN

Alternative titles

  1. CSS - relative/absolute unit lengths
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join