Library

/

Official

Google Fonts

Every Google Font as a LAYR font value: font: GoogleFonts.Fraunces loads the family on first use.

layr add google_fonts

Version

3.1.0

LAYR

^3.0.0

Every Google Font as a LAYR font value. Name the family and font: takes it; the stylesheet is added to the page the first time a family is used.

LAYR
import { GoogleFonts } from '@dynshift/layr-google-fonts'

Text(.config(font: GoogleFonts.Fraunces, size: 40, weight: 600) .obj('Layout, authored.'))

Naming a family

Write the family name without spaces: GoogleFonts.SpaceGrotesk is "Space Grotesk", GoogleFonts.IBMPlexSans is "IBM Plex Sans". For a name that doesn't survive that (digits, odd capitals), or to choose weights, use GoogleFonts.font:

LAYR
import { GoogleFonts } from '@dynshift/layr-google-fonts'

Text(.config(font: GoogleFonts.font('M PLUS Rounded 1c', weights: [400, 800]), size: 28) .obj('Rounded'))
OptionMeaning
weightsWeights to load, e.g. [400, 700]. By default every weight the family has.
italicAlso load the italics.
fallbackThe generic stack shown until the font arrives. Guessed from the name (Mono → monospace, serif families → serif).

Faster first paint

Families load when a page first uses them. For the fonts on your first screen, put the stylesheet in index.html so a prerendered page starts downloading before any script runs:

TypeScript
import { href } from '@dynshift/layr-google-fonts'

href('Fraunces', 'Space Grotesk')
// https://fonts.googleapis.com/css2?family=Fraunces:wght@100..900&family=Space+Grotesk:wght@100..900&display=swap

Fonts are served by Google. If your privacy policy needs self-hosted files, download the family and use it by name with font: 'Family' and a @font-face rule instead.

examples/specimen.layrOpen in playground
import { GoogleFonts } from '@dynshift/layr-google-fonts'

// Colours are theme tokens (src/app.layr sets them for this gallery), so the page follows the
// reader's theme: light or dark here, and the site's theme on layr.dynshift.com.
Page(
  .name(Specimen)
  .route('/')

  Scaffold(
    .config(color: canvas)
    .body(
      Column(
        .config(
          w: fill
          gap: 28
          padding: all(32)
        )
        Column(
          .config(gap: 6)
          Text(
            .config(
              size: 13
              color: faint
              font: GoogleFonts.JetBrainsMono
            )
            .obj('Fraunces · 600')
          )
          Text(
            .config(
              size: 56
              color: ink
              font: GoogleFonts.Fraunces
              letterSpacing: -1.5
              lineHeight: 1
              weight: 600
            )
            .obj('Layout, authored.')
          )
        )
        Row(
          .config(
            w: fill
            gap: 24
            yAlign: stretch
          )
          Column(
            .config(
              w: fill
              color: sunken
              cornerRadius: 12
              gap: 8
              padding: all(20)
            )
            Text(
              .config(
                size: 13
                color: muted
                font: GoogleFonts.JetBrainsMono
              )
              .obj('Space Grotesk')
            )
            Text(
              .config(
                size: 26
                color: ink
                font: GoogleFonts.SpaceGrotesk
                weight: 500
              )
              .obj('Numbers flow, structure steps.')
            )
          )
          Column(
            .config(
              w: fill
              color: panel
              cornerRadius: 12
              gap: 8
              padding: all(20)
            )
            Text(
              .config(
                size: 13
                color: muted
                font: GoogleFonts.JetBrainsMono
              )
              .obj('Instrument Serif')
            )
            Text(
              .config(
                size: 30
                color: accent
                font: GoogleFonts.InstrumentSerif
              )
              .obj('One meaning per line.')
            )
          )
        )
      )
    )
  )
)

Privacy

Cookies

Terms

Contact & grievances