Next.js Discord

Discord Forum

Any way to set line-height when adding a localFont?

Unanswered
Havana posted this in #help-forum
Open in Discord
HavanaOP
I need to change it only for one font, but globally, since it seems to sit too high

5 Replies

@Havana I need to change it only for one font, but globally, since it seems to sit too high
you can override one or more [font-face descriptors](https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face#descriptors). which descriptor to override, i don't know, but you can look up the documentation of each of them and see which one suits your use case.

for example i have this in one of my app to change the font-size of the local font since the default font-size is too big:

const mono = localFont({
  src: [
    { path: "../../.fonts/ia-writer-mono/regular.woff2", weight: "normal", style: "normal" },
    { path: "../../.fonts/ia-writer-mono/bold.woff2", weight: "bold", style: "normal" },
    { path: "../../.fonts/ia-writer-mono/italic.woff2", weight: "normal", style: "italic" },
    { path: "../../.fonts/ia-writer-mono/bolditalic.woff2", weight: "bold", style: "italic" },
  ],
  display: "swap",
  declarations: [{ prop: "size-adjust", value: "90%" }],
  variable: "--mono",
  adjustFontFallback: false,
});
feel like [line-gap-override](https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/line-gap-override) is a good fit, play around with it
it's not supported in safari though which is a bit unfortunate
HavanaOP
i tried
  declarations: [
    {
      prop: 'ascent-override',
      value: '85%'
    },
    {
      prop: 'descent-override',
      value: '15%'
    },
    {
      prop: 'line-gap-override',
      value: '0%'
    }
  ]


on chrome, but nothing changes...
welp, seems like it's not possible then. you have to invent a new css class like
.font-myfont-resized {
  font-family: var("--font-myfont");
  line-height: .8;
}

and use it in your application instead of using var("--font-myfont") directly