Comments (4)
Be curious to hear more what you mean? This is the script for generating
the styles
https://github.com/KyleAMathews/typography.js/blob/master/packages/typography/src/utils/createStyles.js
On Fri, Oct 7, 2016 at 10:42 PM Jonathan Haines [email protected]
wrote:
Just wondering what calculations are used for the scales?
I've compared typography.js to a couple of sites I've referenced in the
past and I've noticed that the output of typography.js isn't consistent
with the other sites.The sites I'm comparing are:
- http://kyleamathews.github.io/typography.js/
- http://www.gridlover.net/try
- http://www.modularscale.com/?1.25&em&1.333&web&text
and the values I'm using are
font size: 18px / 1.25em
line height: 1.5
scale ratio: ~1.333—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#89, or mute the
thread
https://github.com/notifications/unsubscribe-auth/AAEVh95ksOm8i8eFTKnZU4JnITbdv0uAks5qxy04gaJpZM4KRoWJ
.
from typography.js.
The calculations I've used previously to generate a modular scale are
p: base font size
h1: h2 * scale
h2: h3 * scale
h3: h4 * scale
h4: base font size
h5: h4 / scale
h6: h5 / scale
Using these inputs
font size: 18px / 1.25em
line height: 1.5
scale ratio: 4/3
The type scale generated looks something like this:
p: 18px / 1em
h1: 42px / 2.333em
h2: 32px / 1.77em
h3: 24px / 1.33em
h4: 18px / 1em
h5: 14px / 0.75em
h6: 10px / 0.666em
The two sites I mentioned above also give a similar result.
When using typography.js with the inputs I use above, the result looks like this:
p: 18px / 1rem
h1: 24px / 1.33rem
h2: 21.3592px / 1.18662rem
h3: 20.1749px / 1.33rem
h4: 18px / 1rem
h5: 17.0021px / 0.94456rem
h6: 16.524px / 0.918rem
I was wanting to know the method/reasoning typography.js uses to generate it's type scales.
from typography.js.
How I've setup Typography.js is that h1 equals the scaleRatio * baseFontSize
.
So the default scaleRatio
is 2 as the most common ratio between the body text size and header size is 2.
There's an internal scale
function which does this calculation
Math.pow(scaleRatio, scaleValue)
and then uses another internal function, adjustFontSizeTo
to return the font size + line height to maintain vertical rhythm.
A scale value of 0 equals the body size. A scale value of 1 equals the h1 size (by convention, it's pretty arbitrary where on the scale you pick off sizes — you could have different scales that end up returning the same font sizes — but 0 — 1 is pretty easy to remember and has worked well for me). You can see where header sizes are defined here:
I used to have each header size equidistant but in the real world, most sites want more differentiation between h1/h2 and so h2 is now 0.6 on the scale instead of 0.8.
So to recreate your example scale, just divide the h1 font size by the base to get the scale ratio for Typography.js or 42/18 == 2.333
from typography.js.
Also this release notes might help as it was when a lot of these ideas crystalized https://github.com/KyleAMathews/typography.js/releases/tag/v0.8.3
from typography.js.
Related Issues (20)
- Edge browser <p> margin-bottom overrides <p> margin: 0
- Why force text-align="left" on tables? HOT 2
- Add custom scoping
- How do I override linkColor? HOT 3
- Ocean Beach theme is missing a dependency
- either overriding styles is unintuitive and under-documented or I need help
- Adding my site in the list of projects using typography.js?
- Injecting CSS reset before typography.js styles in Gatsby? HOT 2
- Google Fonts are not loaded HOT 1
- Difference between demo website and usage themes HOT 3
- Which UI Kit plays nice with Typographyjs?
- Implementing pre-fetching for Google fonts
- Adding display=swap to GoogleFont in react-typography
- Fonts only seem to work if I have them installed locally HOT 1
- Heading line-heights not the same as paragraphs?
- Chromium doesn't load fonts
- Gatsby 3.0 Dependency Error HOT 2
- Update to support React 18 HOT 4
- Support CSS variables HOT 2
- Shoelace tokens based typography
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from typography.js.