CSS Data Type - <dimension>



CSS <dimension> data type represents a measurement value along a single axis. It is used for properties that accept values in units such as length, width, height, margin, padding, and more. This data type allows you to specify measurements using various units such as distances (<length>), durations (<time>), frequencies (<frequency>), resolutions (<resolution>), and various other quantities.

Syntax

<value><unit>

Here, <value> is a numeric value, and <unit>; is the unit of measurement. Common units include:

  • px: Pixels

  • em: Relative to the font-size of the element

  • rem: Relative to the font-size of the root element

  • vw: Relative to 1% of the width of the viewport

  • vh: Relative to 1% of the height of the viewport

  • cm,mm,in,pt,pc: Absolute length units

Valid Dimensions

The following examples show the use of different units to specify length, time, and frequency −

20px     20 pixels
2rem     2 rem
1.5pt    1.5 points
1400ms   1400 milliseconds
10s       10 seconds
100hz    100 Hertz
100Hz    100 Hertz (values are case insensitive)

Invalid Dimensions

Following are some rules to be applied while using the <dimension> data type: −

12 px     The unit must immediately follow the number.
12"px"    Units are identifiers and should not be surrounded by quotations.
3sec      The seconds unit is denoted by "s" rather than "sec".

CSS <dimension> - height

The following example demonstrates that the use of <dimension> by specifying width and height to 100px −

<html>
<head>
<style>
   .box {
      width: 100px; 
      height: 100px; 
      background-color: pink; 
   }
</style>
</head>
<body>
   <div class="box">
      <dimension>
   </div>
</body>
</html>
Advertisements