CSS Size
CSS Size
We’ve seen various units in CSS so far used for many different purposes; we did hit and trial to find the correct dimensions of that unit for our website.
But now let’s understand how units work in CSS.
Absolute Units.
- cm - centimetres (1 cm = 37.8 px)
- mm - millimetres
- in - inches (1 in = 96 px = 2.54cm)
- pt - points (1pt = 1/72th of 1 in)
- pc - picas (1pc = 1/6th of 1 in)
- px - pixel (1px = 1/96th of 1 in)
Generally we only use pixels to set dimensions of an element.
Relative Units
- em - Relative to the font size of the parent element. Eg: 5em means the size would be 5 times the current font size.
- ex - Relative to X height of the existing font
- ch - Relative to the width/ radius of the character “0”.
- rem - Relative to the font size of the root element.
- vw - Relative to 1% of the width of the viewport. (Viewport is the area of the website visible to the user.)
- vh - Relative to 1% of the height of the viewport
- % - Relative to the parent element’s size.
Apart from this some of the other metrics used in CSS are-
- Opacity: Ranges from 0 to 1
- RGB & RGBA values: 0 to 255
- HSL & HSLA values: 0 to 360