line-height to a unitless number like 1.5 in CSS?When line-height is set as a unitless number, it acts as a multiplier of the element's font size. For example, if the font size is 16px and line-height is 1.5, the line height becomes 24px.
line-height declarations are valid and will not cause a syntax error?CSS line-height accepts unitless numbers, percentages (%), and length units including em and pt. However, px is not recommended and may cause inconsistent rendering. The valid options here are 1.5em and 150%.
p {
font-size: 16px;
line-height: 2;
}With line-height: 2; and font size 16px, the line height becomes 32px, doubling the vertical space between lines.
<div> has line-height: 1.5; and a child <span> inside it has line-height: 2;, what line height will the child text have?<div style="line-height: 1.5;"> <span style="line-height: 2;">Text</span> </div>
Unitless line-height values multiply the element's own font size. The child with line-height: 2; uses 2 times its own font size, not the parent's.
line-height value is generally best for improving readability and accessibility of body text on a webpage?Line height around 1.5 is widely recommended for body text to improve readability and accessibility by providing enough vertical spacing without excessive gaps.