CSS Lengths

A length in CSS is defined by concatenating the number of units and the unit identifier together. For example, 5cm means 5 cm (centimeters). 20pt means 20 pt (points).

CSS defines two kinds of length unit:

 
<!DOCTYPE HTML> 
<html> 
    <head> 
        <title>Example</title> 
        <style type="text/css"> 
        p { 
            background: grey; 
            color:white; 
            width: 5cm; 
            font-size: 20pt; 
        } 
        </style> 
    </head> 
    <body> 
        <a href="http://java2s.com">Visit the website</a> 
        <p>I like <span>HTML</span> and CSS.</p> 
        <a class="myclass1 myclass2" href="http://java2s.com">Visit the website</a> 
    </body> 
</html>
  
Click to view the demo
Home 
  HTML CSS Book 
    CSS  

CSS Value:
  1. CSS Colors
  2. CSS Lengths
  3. Absolute units of measurement
  4. Relative units of measurement
  5. Working with Pixels
  6. Working with Percentages
  7. CSS Unit Calculations
  8. Using CSS Angles
  9. Using CSS Times
Related: