Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for fluid line-height #47

Closed
iljapanic opened this issue Oct 20, 2022 · 2 comments
Closed

Support for fluid line-height #47

iljapanic opened this issue Oct 20, 2022 · 2 comments
Labels
enhancement New feature or request

Comments

@iljapanic
Copy link

Foremost, thank you for creating such a graceful and simple tool 馃檹

I was looking around for a straight-forward solution to fluid typography and yours is by far the easiest with just the right amount of customization and modern Tailwind-like naming convention out of the box.

I was wondering if you have considered adding variables for fluid line-heights? One for body text and one for headings.

I suppose it may be an overkill to use clamp() for line-height since the variation between min/max is so small. On the other hand, it would make your tool a true plug & play typographic solution.

@iljapanic iljapanic added the enhancement New feature or request label Oct 20, 2022
@AleksandrHovhannisyan
Copy link
Owner

AleksandrHovhannisyan commented Oct 20, 2022

@iljapanic Thanks! Glad you found it useful.

Yup, I've thought about that before, but it might be tricky. You technically can clamp line height, but you can't clamp it in a unitless fashion (like clamp(1.3, x, 1.6)), so you'd need to use rems for the line height. That's actually what https://fluidtypography.com/ does (it's a similar tool), and it's perfectly fine, but in my experience, line height does not scale linearly with font size. So the curve looks more like this:

Line height on y axis and font size on x-axis, both in pixels. The y-axis is labeled from 1 to 1.2, 1.3, 1.4, 1.5, 1.6. A curve in blue starts at 1.6 with an initially sharp downward slope that decreases with time until it plateaus near 1.2.

Or, in pixels:

Line height on y axis and font size on x-axis, both in pixels. The y-axis is labeled from 60 down to 20. A curve in blue starts at a y-intercept of 20 with an initially sharp upward slope that decreases with time until it plateaus near 60.

So the tool would need to give you a way to define the function, maybe as a bezier curve (this might even be useful for font size if some users don't want their font size to scale in a perfectly linearly manner).

However, I still think the easiest approach is to just use unitless line heights and change the scale factor for each font size step. For example, on my personal website, what I do is have a set of line height variables, maybe like this:

--lh-3xs: 1.2;
--lh-2xs: 1.3;
--lh-xs: 1.4;
--lh-sm: 1.5;
--lh-base: 1.6;
--lh-md: 1.7;

And then I create font size utilities that pair the right line heights with the right font size steps. So maybe:

.fs-base {
  font-size: var(--fs-base);
  line-height: var(--lh-base);
}
.fs-3xl {
  font-size: var(--fs-3xl);
  line-height: var(--lh-3xs);

Alternatively, you could try out the technique in this article: Using calc to figure out optimal line-height. The trick in that article is actually what fluid-type-scale.com uses for its own CSS, although I will admit I still like to just create my own CSS variables. That way, I can more easily change line height based on other factors, like line length (e.g., for card components where the lines of text are very short).

I know that's a long response, but hopefully it clarifies things.

@iljapanic
Copy link
Author

@AleksandrHovhannisyan Thank you for a quick response. I appreciate you taking time to write such a thoughtful and in-depth explanation. I haven't considered that the unitless values might be a culprit. Your rationale makes total sense. I'll just go with a few variables with unitless values 馃殌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants