<dl class="_leading">
<div>
<dt>Lead ratio</dt>
<dd>
<select name="lead-ratio">
<option value="1" selected>1</option>
<option value="3/4">3/4</option>
<option value="2/3">2/3</option>
<option value="1/2">1/2</option>
<option value="1/3">1/3</option>
<option value="1/4">3/4</option>
<option value="0">0</option>
</select>
</dd>
</div>
<div>
<dt>Heading lead scale</dt>
<dd>
<select name="heading-lead-scale">
<option value="1" selected>1</option>
<option value="3/4">3/4</option>
<option value="2/3">2/3</option>
<option value="1/2">1/2</option>
<option value="1/3">1/3</option>
<option value="1/4">3/4</option>
<option value="0">0</option>
</select>
</dd>
</div>
<div>
<dt>Main font size</dt>
<dd>
<select name="main-font-size">
<option value="12">12px</option>
<option value="14">14px</option>
<option value="16" selected>16px</option>
<option value="18">18px</option>
<option value="20">20px</option>
</select>
</dd>
</div>
<div>
<dt>Side font size</dt>
<dd>
<select name="side-font-size">
<option value="12">12px</option>
<option value="14">14px</option>
<option value="16" selected>16px</option>
<option value="18">18px</option>
<option value="20">20px</option>
</select>
</dd>
</div>
<div>
<dt>Visualization</dt>
<dd><label><input type="checkbox" name="show-leading" checked /> Show leading</label></dd>
</div>
</dl>
<div class="_container">
<header class="_header">
<h1>line-height using rem</h1>
</header>
<main class="_main">
<pre class="_code"><code><!--
-->html {
<!--
--> --lead-size: 1rem;
<!--
--> --lead-ratio: <mark class="lead-ratio"><span>1</span></mark>;
<!--
--> --lead-scale: 1;
<!--
-->}
<!--
-->* {
<!--
--> line-height: calc(1em + var(--leading, var(--lead-size) * var(--lead-ratio) * var(--lead-scale)));
<!--
-->}
<!--
-->:is(h1, h2, h3, h4, h5, h6) {
<!--
--> --lead-scale: <mark class="heading-lead-scale"><span>1</span></mark>;
<!--
-->}
<!--
-->._main {
<!--
--> --lead-size: <mark class="main-font-size"><span>1rem</span></mark>;
<!--
--> font-size: <mark class="main-font-size"><span>1rem</span></mark>;
<!--
-->}
<!--
-->._side {
<!--
--> --lead-size: <mark class="side-font-size"><span>1rem</span></mark>;
<!--
--> font-size: <mark class="side-font-size"><span>1rem</span></mark>;
<!--
-->}
<!--
--></code></pre>
<h2>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
<h2>Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
<h2>Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
<h2>Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</main>
<aside class="_side">
<h2>Lorem ipsum dolor sit amet</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
<h2>Ut enim ad minim veniam</h2>
<p>Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
<h2>Duis aute irure dolor in reprehenderit</h2>
<p>Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.</p>
<h2>Excepteur sint occaecat cupidatat non proident</h2>
<p>Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</aside>
<footer class="_footer">
<p>© 2025 nov.</p>
</footer>
</div>
html {
--black: #111;
--white: #fff;
--lead-size: 1rem;
--lead-ratio: 1;
--lead-scale: 1;
background: var(--white);
color: var(--black);
font-family: ui-sans-serif, sans-serif;
}
* {
line-height: calc(
1em +
var(--leading, var(--lead-size) * var(--lead-ratio) * var(--lead-scale))
);
margin: 0;
}
:is(h1, h2, h3, h4, h5, h6):is(* + *) {
margin-block-start: 4rem;
}
:is(p, pre):is(* + *) {
margin-block-start: 2rem;
}
h1 {
font-size: calc(1em * 12 / 6);
}
h2 {
font-size: calc(1em * 12 / 7);
}
h3 {
font-size: calc(1em * 12 / 8);
}
h4 {
font-size: calc(1em * 12 / 9);
}
h5 {
font-size: calc(1em * 12 / 10);
}
h6 {
font-size: calc(1em * 12 / 11);
}
pre,
code {
font-family: ui-monospace, monospace;
}
:is(h1, h2, h3, h4, h5, h6) {
html:has([name="heading-lead-scale"] > [value="1"]:checked) & {
--lead-scale: 1;
}
html:has([name="heading-lead-scale"] > [value="3/4"]:checked) & {
--lead-scale: calc(3 / 4);
}
html:has([name="heading-lead-scale"] > [value="2/3"]:checked) & {
--lead-scale: calc(2 / 3);
}
html:has([name="heading-lead-scale"] > [value="1/2"]:checked) & {
--lead-scale: calc(1 / 2);
}
html:has([name="heading-lead-scale"] > [value="1/3"]:checked) & {
--lead-scale: calc(1 / 3);
}
html:has([name="heading-lead-scale"] > [value="1/4"]:checked) & {
--lead-scale: calc(1 / 4);
}
html:has([name="heading-lead-scale"] > [value="0"]:checked) & {
--lead-scale: 0;
}
}
._container {
html:has([name="lead-ratio"] > [value="1"]:checked) & {
--lead-ratio: 1;
}
html:has([name="lead-ratio"] > [value="3/4"]:checked) & {
--lead-ratio: calc(3 / 4);
}
html:has([name="lead-ratio"] > [value="2/3"]:checked) & {
--lead-ratio: calc(2 / 3);
}
html:has([name="lead-ratio"] > [value="1/2"]:checked) & {
--lead-ratio: calc(1 / 2);
}
html:has([name="lead-ratio"] > [value="1/3"]:checked) & {
--lead-ratio: calc(1 / 3);
}
html:has([name="lead-ratio"] > [value="1/4"]:checked) & {
--lead-ratio: calc(1 / 4);
}
html:has([name="lead-ratio"] > [value="0"]:checked) & {
--lead-ratio: 0;
}
& {
display: flex;
flex-flow: wrap;
gap: 4rem 2rem;
padding: 2rem;
}
._header {
flex: 100%;
}
._main {
flex: 1e5 0 50%;
}
._side {
flex: 1 1 240px;
}
._footer {
flex: 100%;
}
:is(h1, h2, p, pre) {
html:has([name="show-leading"]:checked) & {
background: linear-gradient(
color-mix(in srgb, transparent, var(--black) 20%) calc(50% - 0.5em),
transparent calc(50% - 0.5em) calc(50% + 0.5em),
color-mix(in srgb, transparent, var(--black) 20%) calc(50% + 0.5em)
)
0 0 / 100% 1lh;
}
}
}
._main {
html:has([name="main-font-size"] > [value="12"]:checked) & {
--lead-size: 0.75rem;
font-size: 0.75rem;
}
html:has([name="main-font-size"] > [value="14"]:checked) & {
--lead-size: 0.875rem;
font-size: 0.875rem;
}
html:has([name="main-font-size"] > [value="16"]:checked) & {
--lead-size: 1rem;
font-size: 1rem;
}
html:has([name="main-font-size"] > [value="18"]:checked) & {
--lead-size: 1.125rem;
font-size: 1.125rem;
}
html:has([name="main-font-size"] > [value="20"]:checked) & {
--lead-size: 1.25rem;
font-size: 1.25rem;
}
}
._side {
html:has([name="side-font-size"] > [value="12"]:checked) & {
--lead-size: 0.75rem;
font-size: 0.75rem;
}
html:has([name="side-font-size"] > [value="14"]:checked) & {
--lead-size: 0.875rem;
font-size: 0.875rem;
}
html:has([name="side-font-size"] > [value="16"]:checked) & {
--lead-size: 1rem;
font-size: 1rem;
}
html:has([name="side-font-size"] > [value="18"]:checked) & {
--lead-size: 1.125rem;
font-size: 1.125rem;
}
html:has([name="side-font-size"] > [value="20"]:checked) & {
--lead-size: 1.25rem;
font-size: 1.25rem;
}
}
._leading {
& {
background: color-mix(in srgb, transparent, var(--black) 70%);
color: var(--white);
display: flex;
flex-flow: wrap;
column-gap: 2em;
overflow: auto;
padding-inline: 1em;
position: sticky;
inset-block-start: 0;
z-index: calc(infinity);
}
div {
display: flex;
flex-flow: wrap;
column-gap: 0.5em;
align-items: center;
}
dd {
margin: 0;
}
}
._code {
& {
--leading: 0.25rem;
white-space: pre-wrap;
}
.lead-ratio {
span {
clip-path: inset(50%);
position: absolute;
}
html:has([name="lead-ratio"] > [value="1"]:checked) &::before {
content: "1";
}
html:has([name="lead-ratio"] > [value="3/4"]:checked) &::before {
content: "calc(3 / 4)";
}
html:has([name="lead-ratio"] > [value="2/3"]:checked) &::before {
content: "calc(2 / 3)";
}
html:has([name="lead-ratio"] > [value="1/2"]:checked) &::before {
content: "calc(1 / 2)";
}
html:has([name="lead-ratio"] > [value="1/3"]:checked) &::before {
content: "calc(1 / 3)";
}
html:has([name="lead-ratio"] > [value="1/4"]:checked) &::before {
content: "calc(1 / 4)";
}
html:has([name="lead-ratio"] > [value="0"]:checked) &::before {
content: "0";
}
}
.heading-lead-scale {
span {
clip-path: inset(50%);
position: absolute;
}
html:has([name="heading-lead-scale"] > [value="1"]:checked) &::before {
content: "1";
}
html:has([name="heading-lead-scale"] > [value="3/4"]:checked) &::before {
content: "calc(3 / 4)";
}
html:has([name="heading-lead-scale"] > [value="2/3"]:checked) &::before {
content: "calc(2 / 3)";
}
html:has([name="heading-lead-scale"] > [value="1/2"]:checked) &::before {
content: "calc(1 / 2)";
}
html:has([name="heading-lead-scale"] > [value="1/3"]:checked) &::before {
content: "calc(1 / 3)";
}
html:has([name="heading-lead-scale"] > [value="1/4"]:checked) &::before {
content: "calc(1 / 4)";
}
html:has([name="heading-lead-scale"] > [value="0"]:checked) &::before {
content: "0";
}
}
.main-font-size {
span {
clip-path: inset(50%);
position: absolute;
}
html:has([name="main-font-size"] > [value="12"]:checked) &::before {
content: "0.75rem";
}
html:has([name="main-font-size"] > [value="14"]:checked) &::before {
content: "0.875rem";
}
html:has([name="main-font-size"] > [value="16"]:checked) &::before {
content: "1rem";
}
html:has([name="main-font-size"] > [value="18"]:checked) &::before {
content: "1.125rem";
}
html:has([name="main-font-size"] > [value="20"]:checked) &::before {
content: "1.25rem";
}
}
.side-font-size {
span {
clip-path: inset(50%);
position: absolute;
}
html:has([name="side-font-size"] > [value="12"]:checked) &::before {
content: "0.75rem";
}
html:has([name="side-font-size"] > [value="14"]:checked) &::before {
content: "0.875rem";
}
html:has([name="side-font-size"] > [value="16"]:checked) &::before {
content: "1rem";
}
html:has([name="side-font-size"] > [value="18"]:checked) &::before {
content: "1.125rem";
}
html:has([name="side-font-size"] > [value="20"]:checked) &::before {
content: "1.25rem";
}
}
}
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.