I'm puzzled by the behavior of the CSS code provided, which is also demonstrated in this fiddle.
<style type="text/css">
p {
font-size: 14px;
}
.percentage {
line-height: 150%;
}
.em-and-a-half {
line-height: 1.5em;
}
.decimal {
line-height: 1.5;
}
.smaller {
font-size:50%;
}
.caption {
font-weight: bolder;
font-size: 80%;
}
</style>
<p class="caption">default line spacing</p>
<p>This tutorial offers a concise introduction to programming <span class="">languages</span> using picture-drawing libraries.</p>
<p>This tutorial provides an overview of programming in utilizing a picture-drawing library and learning about different coding languages.</p>
<p class="caption">line-height: 150%</p>
<p class="percentage">This tutorial offers insights into programming <span class="">languages</span> through drawing libraries.</p>
<p class="percentage">The tutorial covers the basics of programming with picture-drawing libraries and introduces different coding languages.</p>
<p class="caption">line-height: 1.5em</p>
<p class="em-and-a-half">Learn the fundamentals of programming using picture-drawing libraries and explore various languages.</p>
<p class="em-and-a-half">Explore the core concepts of programming language and create illustrations using drawing libraries.</p>
<p class="caption">line-height: 1.5</p>
<p class="decimal">Discover the essentials of programming <span class="">languages</span> and illustration tools for creativity.</p>
<p class="decimal">Get introduced to programming and creating visual content with drawing libraries.</p>
The first two paragraphs have default line spacing. The second paragraph contains a smaller word but does not impact the line height in that paragraph.
The subsequent two paragraphs have a line-height set at 150%. Yet again, the second paragraph has a smaller word which creates additional space between the first two lines, particularly noticeable in multiple browsers.
Following that are paragraphs with a line-height of 1.5em, producing similar results in terms of extra spacing between the initial lines of the paragraphs.
However, when the following paragraphs have a line-height value of 1.5 without any specified unit, the extra-space issue disappears.
https://i.sstatic.net/6bJu2.png
To sum it up, there seems to be consistent line-spacing outcomes in CSS when parent-child line heights differ due to inheritance, yet inconsistencies emerge when parent-child line heights match.
Hence, my questions:
The CSS spec distinguishes between values like 1.5 and 150% or its equivalent, 1.5em. How does this difference explain the observed behavior here? Where does the added space originate from as a result of these rules?
If all examples should render the same way, which implementation deviates from the expected outcome?
In practical terms, what are the drawbacks of transitioning to unitless measurements such as 1.5 for line-height?(Answer: none)