I’ve read article about “Line-height” in CSS and “Leading” in Photshop and I known how to convert leading to line-height. But in this article it just says about unit (px, em,…), for example:
If your font size in your PSD file is 10px and your leading is set to 20px. Then you should put 20px for line-height in your style guides.
I want to know how to convert to unitless to use in line-height. Thank in advance.
With CSS you can declare a unitless line height, for example:
p { line-height: 1.5; }
Will display paragraph text with a line height of 1.5 times the inherited font size. So if your font size is 16px (or equivilent) the the line height will calculate to 24px.
As bluedreamer said a unitless line-height is based on the font-size of the parent element concerned so that you maintain a relationship between the parent and the font-size. It is a scaling factor that is also passed down to children so a child with a smaller font-size gets a smaller line-height (unlike line-heights with units which pass down an actual computed px line-height to the children so a child with a small font-size will still get the larger line-height of the parent).
You would rarely set a line-height of 10px anyway as that would be smaller than the font-size in most cases and indeed on the web you really don’t want text smaller than 10px anyway (unless its a special effect that doesn’t need to be read).
Yes that means that children will get a line-height of 1.4287 times whatever their font-size is. (I would use 1.4 or 1.43 and avoid long decimal numbers as browsers round up or down to the nearest pixel anyway.)
Obviously if you want to change the default that you set then you can change it as required. Your design may call for small text with a large line-height so change it to suit the design but generally you would want the ratio of text to line-height to be consistent.
I generally also set the line-height of heading tags (h1- h6) to make sure UA defaults don’t get in the way.
There is never a “one size fits all” approach as situations differ.