Units of Length and Percentage : measurement « Style Basics « HTML / CSS






Units of Length and Percentage

  


Unit  Definition                                                           Example

em    relative to the height of the font used in the element               h1 {margin:0.5em}

ex    relative to the height of the character 'x' for                      h2 {margin: 1ex} 
      the font used by the element
  
px    size based on the number of screen pixels                            p {font-size:12px}

in    in for inches (1 in = 2.54 cm)                                       p {font-size: 0.5in}

cm    cm for centimetres                                                   p {font-size: 0.3cm}

mm    mm for millimetres                                                   p {font-size:3mm}

pt    pt for points (1pt = 1/72 inches)                                    p {font-size:12pt}

pc    pc for picas (1pc= 12 points)                                        p {font-size:1pc}

%     a percentage value relative to the value of the parent element,      p {line-height:120%} 
      depending on the properties used

   
  








Related examples in the same category

1.Absolute Units
2.Relative Units
3.Testing 96 DPI Equals an Inch
4.This paragraph has a 200 pixel width and 10 pixels of padding
5.Relative units giving rise to unequal side margins
6.Different measures
7.em is relative to the font size
8.Relative size font-size: .75em
9.width: size an element by assigning pixels, ems, a percentage, or another fixed measurement to width.
10.Percentages are more flexible because they can scale to the viewport.
11.width:100% stretches an element to the width of its parent.
12.Absolute vs. Relative Measurements
13.one inch tall
14.inch measurement
15.font-size with various measurements
16.This font is 24 pixels tall and this div is 3 ems tall
17.The body's border is 1em thick
18.font-size: 1in
19.inch vs pixel
20.percentage measurement width
21.A negative margin
22.This paragraph has a 1 pixel thick, solid black border around it.
23.Comparing em to Pixels
24.This font is 1.2 smaller than the default size, or pixels.
25.em measurement
26.ex measurement
27.inch measurement 2
28.inch vs pixels
29.Em Measurement Comparison to Pixels
30.percentage measurement
31.12 pixel base