Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JayPanoz/9a20ac4be6f775730b5aa875e3f05c88 to your computer and use it in GitHub Desktop.
Save JayPanoz/9a20ac4be6f775730b5aa875e3f05c88 to your computer and use it in GitHub Desktop.
Which line-height do you get when sizing based on font-size, x-height and character width

Line Height based on the typeface x-height and character width | Golden Ratio edition

CSS snippet

p {
  font-size: 1em;
  line-height: calc(1.618em + (1ex - 1ch));
}

Line height is based on the font-size (1.618em), the typeface’s x-height (1ex) and character width (1ch) so we’re taking the typeface metrics and proportions into account to typeset.

Note: Not implying those are the ideal line-heights for those typefaces. Just trying to experiment with vertical rhythm based on the typeface in use. There obviously could be a better calc formula (golden ratio and shit).

All values computed for font-size: 16px;.


font-family: 'Abril Text';

line-height: 24.38399887084961px;

ratio: 1.5239999294281006;


font-family: Adelle;

line-height: 24.92799949645996px;

ratio: 1.5579999685287476;


font-family: 'Adelle Sans';

line-height: 25.1200008392334px;

ratio: 1.5700000524520874;


font-family: 'Adobe Text Pro';

line-height: 25.280000686645508px;

ratio: 1.5800000429153442;


font-family: 'Adriane Text';

line-height: 24.128000259399414px;

ratio: 1.5080000162124634;


font-family: 'Arno Pro';

line-height: 24.639999389648438px;

ratio: 1.5399999618530273;


font-family: Calluna;

line-height: 24.11199951171875px;

ratio: 1.5069999694824219;


font-family: Edita;

line-height: 24.6560001373291px;

ratio: 1.5410000085830688;


font-family: Eskapade;

line-height: 25.1200008392334px;

ratio: 1.5700000524520874;


font-family: 'Essay Text';

line-height: 24.512001037597656px;

ratio: 1.5320000648498535;


font-family: 'Dagny Pro';

line-height: 24.591999053955078px;

ratio: 1.5369999408721924;


font-family: 'Tisa Pro';

line-height: 23.392000198364258px;

ratio: 1.4620000123977661;


font-family: 'Tisa Sans Pro';

line-height: 23.808000564575195px;

ratio: 1.4880000352859497;


font-family: 'Futura PT';

line-height: 23.440000534057617px;

ratio: 1.465000033378601;


font-family: Grad;

line-height: 24.895999908447266px;

ratio: 1.555999994277954;


font-family: 'Kepler Std';

line-height: 25.392000198364258px;

ratio: 1.5870000123977661;


font-family: Lexia;

line-height: 25.328001022338867px;

ratio: 1.5830000638961792;


font-family: 'Museo Sans';

line-height: 23.93600082397461px;

ratio: 1.496000051498413;


font-family: 'Museo Slab';

line-height: 24.064001083374023px;

ratio: 1.5040000677108765;


font-family: 'Proxima Nova';

line-height: 23.823999404907227px;

ratio: 1.4889999628067017;


font-family: 'Servus Slab';

line-height: 24.27199935913086px;

ratio: 1.5169999599456787;


font-family: 'Warnock Pro';

line-height: 24.895999908447266px;

ratio: 1.555999994277954;


font-family: -apple-system;

line-height: 24.54425048828125px;

ratio: 1.5340156555175781;


font-family: Athelas;

line-height: 24.144001007080078px;

ratio: 1.5090000629425049;


font-family: 'Iowan Old Style';

line-height: 24.65362548828125px;

ratio: 1.5408515930175781;


font-family: Charter;

line-height: 24.68487548828125px;

ratio: 1.5428047180175781;


font-family: Arial;

line-height: 25.28643798828125px;

ratio: 1.5804023742675781;


font-family: Helvetica;

line-height: 25.35675048828125px;

ratio: 1.5847969055175781;


font-family: Times;

line-height: 25.06768798828125px;

ratio: 1.5667304992675781;


font-family: Avenir;

line-height: 24.479999542236328px;

ratio: 1.5299999713897705;


font-family: Cambria;

line-height: 24.49737548828125px;

ratio: 1.5310859680175781;


font-family: 'American Typewriter';

line-height: 23.695999145507813px;

ratio: 1.4809999465942383;


font-family: 'Avenir Next';

line-height: 24.09600067138672px;

ratio: 1.50600004196167;


font-family: Baskerville;

line-height: 24.28643798828125px;

ratio: 1.5179023742675781;


font-family: 'Chaparral Pro';

line-height: 24.2239990234375px;

ratio: 1.5139999389648438;


font-family: Cochin;

line-height: 23.84000015258789px;

ratio: 1.4900000095367432;


font-family: Didot;

line-height: 23.855998992919922px;

ratio: 1.4909999370574951;


font-family: Georgia;

line-height: 23.77081298828125px;

ratio: 1.4856758117675781;


font-family: 'Gill Sans';

line-height: 25.07550048828125px;

ratio: 1.5672187805175781;


font-family: 'Hoefler Text';

line-height: 23.119998931884766px;

ratio: 1.4449999332427979;


font-family: 'Minion Pro';

line-height: 25.200000762939453px;

ratio: 1.5750000476837158;


font-family: 'Myriad Pro';

line-height: 25.423999786376953px;

ratio: 1.5889999866485596;


font-family: 'Open Sans';

line-height: 25.30206298828125px;

ratio: 1.5813789367675781;


font-family: Palatino;

line-height: 25.42706298828125px;

ratio: 1.5891914367675781;


font-family: Optima;

line-height: 24.559999465942383px;

ratio: 1.534999966621399;


font-family: Roboto;

line-height: 25.33331298828125px;

ratio: 1.5833320617675781;


font-family: 'Roboto Condensed';

line-height: 26.51300048828125px;

ratio: 1.6570625305175781;


font-family: 'Source Sans Pro';

line-height: 25.711999893188477px;

ratio: 1.6069999933242798;


font-family: 'Source Serif Pro';

line-height: 25.472000122070313px;

ratio: 1.5920000076293945;


font-family: Verdana;

line-height: 24.44268798828125px;

ratio: 1.5276679992675781;


font-family: Vollkorn;

line-height: 23.631999969482422px;

ratio: 1.4769999980926514;


font-family: 'Adobe Garamond Pro';

line-height: 24.239999771118164px;

ratio: 1.5149999856948853;


font-family: 'Adobe Caslon Pro';

line-height: 24.624000549316406px;

ratio: 1.5390000343322754;

<!-- Quick and dirty “web app” -->
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
<style type="text/css" id="styles">
html, body {margin: 0; padding: 0;}
.main {
box-sizing: border-box;
display: flex;
align-items: center;
min-height: 100vh;
padding: 0 20px;
}
.main > * {
flex: 1 1 auto;
}
.text {
font-family: "Iowan Old Style";
max-width: 60ch;
margin: 0 auto;
}
p {
font-size: 1em;
line-height: calc(1em + (2ex - 1ch));
margin: calc(1em + (2ex - 1ch)) 2%;
}
#console {
box-sizing: border-box;
border: 1px solid gray;
font-family: monospace, monospace;
font-size: 1em;
align-self: stretch;
overflow-y: auto;
max-height: 100vh;
}
#console span {
display: block;
margin: 1em 0;
}
#settings {
position: fixed;
top: 20px;
right: 20px;
text-align: right;
}
button {
padding: 0.5em 1em;
font-size: 16px;
font-weight: bold;
z-index: 10;
}
input {
display: block;
margin: 1em 0;
}
</style>
</head>
<body>
<div id="settings">
<input type="text" id="fontInput" placeholder="Font Family"></input>
<input type="text" id="fontSizer" placeholder="Font Size (em)"></input>
<button type="button">Write values</button>
</div>
<div class="main">
<div class="text">
<p>Do you see any Teletubbies in here? Do you see a slender plastic tag clipped to my shirt with my name printed on it? Do you see a little Asian child with a blank expression on his face sitting outside on a mechanical helicopter that shakes when you put quarters in it?</p>
<p>No? Well, that's what you see at a toy store. And you must think you're in a toy store, because you're here shopping for an infant named Jeb.</p>
<p>The path of the righteous man is beset on all sides by the iniquities of the selfish and the tyranny of evil men. Blessed is he who, in the name of charity and good will, shepherds the weak through the valley of darkness, for he is truly his brother's keeper and the finder of lost children. And I will strike down upon thee with great vengeance and furious anger those who would attempt to poison and destroy My brothers. And you will know My name is the Lord when I lay My vengeance upon thee.</p>
</div>
<div id="console"></div>
</div>
<script type="text/javascript">
var button = document.getElementsByTagName("button")[0],
textSample = document.getElementsByTagName("p")[0],
fontInput = document.getElementById("fontInput"),
fontSizer = document.getElementById("fontSizer"),
logger = document.getElementById("console"),
style = document.getElementById("styles");
button.addEventListener("click", function(e) {
e.preventDefault();
var ff = window.getComputedStyle(textSample, null).getPropertyValue("font-family"),
fs = window.getComputedStyle(textSample, null).getPropertyValue("font-size"),
lh = window.getComputedStyle(textSample, null).getPropertyValue("line-height"),
ratio = parseFloat(lh) / parseFloat(fs);
logger.innerHTML += "<span>font-family: " + ff + ";<br/>font-size: " + fs + ";<br/>line-height: " + lh + ";<br/>ratio: " + ratio + ";</span>";
}, false);
fontInput.addEventListener("keyup", function(e) {
if (e.keyCode == 13) { // Return key
newFont = fontInput.value;
fontToTest = document.createTextNode("p { font-family: " + newFont + "; }");
style.appendChild(fontToTest);
}
}, false);
fontSizer.addEventListener("keyup", function(e) {
if (e.keyCode == 13) { // Return key
newSize = fontSizer.value;
sizeToTest = document.createTextNode("p { font-size: " + newSize + "em; }");
style.appendChild(sizeToTest);
}
}, false);
</script>
</body>
</html>

Line Height based on the typeface x-height and character width

CSS snippet

p {
  font-size: 1em;
  line-height: calc(1em + (2ex - 1ch));
}

Line height is based on the font-size (1em), the typeface’s x-height (2ex) and character width (1ch) so we’re taking the typeface metrics and proportions into account to typeset.

Note: Not implying those are the ideal line-heights for those typefaces. Just trying to experiment with vertical rhythm based on the typeface in use. There obviously could be a better calc formula (golden ratio and shit).

All values computed for font-size: 16px;.


font-family: 'Abril Text';

line-height: 22.447999954223633px;

ratio: 1.402999997138977;


font-family: Adelle;

line-height: 23.263999938964844px;

ratio: 1.4539999961853027;


font-family: 'Adelle Sans';

line-height: 23.45600128173828px;

ratio: 1.4660000801086426;


font-family: 'Adobe Text Pro';

line-height: 22.496000289916992px;

ratio: 1.406000018119812;


font-family: 'Adriane Text';

line-height: 22.239999771118164px;

ratio: 1.3899999856948853;


font-family: 'Arno Pro';

line-height: 21.119998931884766px;

ratio: 1.3199999332427979;


font-family: Calluna;

line-height: 21.487998962402344px;

ratio: 1.3429999351501465;


font-family: Edita;

line-height: 21.855998992919922px;

ratio: 1.3659999370574951;


font-family: Eskapade;

line-height: 22.4320011138916px;

ratio: 1.402000069618225;


font-family: 'Essay Text';

line-height: 21.50400161743164px;

ratio: 1.3440001010894775;


font-family: 'Dagny Pro';

line-height: 22.576000213623047px;

ratio: 1.4110000133514404;


font-family: 'Tisa Pro';

line-height: 21.104000091552734px;

ratio: 1.319000005722046;


font-family: 'Tisa Sans Pro';

line-height: 21.695999145507813px;

ratio: 1.3559999465942383;


font-family: 'Futura PT';

line-height: 20.192001342773438px;

ratio: 1.2620000839233398;


font-family: Grad;

line-height: 22.336000442504883px;

ratio: 1.3960000276565552;


font-family: 'Kepler Std';

line-height: 22.27199935913086px;

ratio: 1.3919999599456787;


font-family: Lexia;

line-height: 23.552001953125px;

ratio: 1.4720001220703125;


font-family: 'Museo Sans';

line-height: 22.09600067138672px;

ratio: 1.38100004196167;


font-family: 'Museo Slab';

line-height: 22.224000930786133px;

ratio: 1.3890000581741333;


font-family: 'Proxima Nova';

line-height: 21.66400146484375px;

ratio: 1.3540000915527344;


font-family: 'Servus Slab';

line-height: 21.919998168945313px;

ratio: 1.369999885559082;


font-family: 'Warnock Pro';

line-height: 22.04800033569336px;

ratio: 1.378000020980835;


font-family: -apple-system;

line-height: 23.078125px;

ratio: 1.4423828125;


font-family: Athelas;

line-height: 21.055999755859375px;

ratio: 1.315999984741211;


font-family: 'Iowan Old Style';

line-height: 22.4296875px;

ratio: 1.40185546875;


font-family: Charter;

line-height: 22.4921875px;

ratio: 1.40576171875;


font-family: Arial;

line-height: 23.6953125px;

ratio: 1.48095703125;


font-family: Helvetica;

line-height: 23.8359375px;

ratio: 1.48974609375;


font-family: Times;

line-height: 22.359375px;

ratio: 1.3974609375;


font-family: Avenir;

line-height: 22.079999923706055px;

ratio: 1.3799999952316284;


font-family: Cambria;

line-height: 22.078125px;

ratio: 1.3798828125;


font-family: 'American Typewriter';

line-height: 21.807998657226563px;

ratio: 1.3629999160766602;


font-family: 'Avenir Next';

line-height: 21.695999145507813px;

ratio: 1.3559999465942383;


font-family: Baskerville;

line-height: 20.796875px;

ratio: 1.2998046875;


font-family: 'Chaparral Pro';

line-height: 21.055999755859375px;

ratio: 1.315999984741211;


font-family: Cochin;

line-height: 19.90399932861328px;

ratio: 1.24399995803833;


font-family: Didot;

line-height: 20.832000732421875px;

ratio: 1.3020000457763672;


font-family: Georgia;

line-height: 21.5859375px;

ratio: 1.34912109375;


font-family: 'Gill Sans';

line-height: 22.375px;

ratio: 1.3984375;


font-family: 'Hoefler Text';

line-height: 20.304000854492188px;

ratio: 1.2690000534057617;


font-family: 'Minion Pro';

line-height: 22.304000854492188px;

ratio: 1.3940000534057617;


font-family: 'Myriad Pro';

line-height: 23.280000686645508px;

ratio: 1.4550000429153442;


font-family: 'Open Sans';

line-height: 23.9765625px;

ratio: 1.49853515625;


font-family: Palatino;

line-height: 23.078125px;

ratio: 1.4423828125;


font-family: Optima;

line-height: 22.239999771118164px;

ratio: 1.3899999856948853;


font-family: Roboto;

line-height: 23.8984375px;

ratio: 1.49365234375;


font-family: 'Roboto Condensed';

line-height: 25.078125px;

ratio: 1.5673828125;


font-family: 'Source Sans Pro';

line-height: 23.600000381469727px;

ratio: 1.475000023841858;


font-family: 'Source Serif Pro';

line-height: 23.152000427246094px;

ratio: 1.4470000267028809;


font-family: Verdana;

line-height: 23.28125px;

ratio: 1.455078125;


font-family: Vollkorn;

line-height: 21.104000091552734px;

ratio: 1.319000005722046;


font-family: 'Adobe Garamond Pro';

line-height: 20.703998565673828px;

ratio: 1.2939999103546143;


font-family: 'Adobe Caslon Pro';

line-height: 21.472000122070313px;

ratio: 1.3420000076293945;

@JayPanoz
Copy link
Author

Actually, you can somehow get far more pleasing results with

line-height: calc(1.618em + (1ex - 1ch));

As far as I’m concerned, as long as the max-width is character based.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment