2025-04-13 Web Development, Design
A Random Hero Title Font Selector Component in Next.js
By O. Wolfson
I want a hero title that uses a different font every time a website visitor loads the page. A simple way to add some variety and personality to a design. To achieve this, I created a react component that randomly picks a typeface from a list of custom fonts.
Big thanks to Cedilla Studio for letting me use their fonts for this. Their work brings character and unpredictability in the best way. Cedilla offers unique fonts, Lightroom presets, and custom design services. — Francis Bacon (the philosopher) wrote: “The job of the artist is always to deepen the mystery.” Cedilla Studio is deepening the mystery for us. Check out their work at cedilla.studio and follow the founder on Instagram at @type.otf.
How The Component Works
I am working in React / Next.js, so the explanation will be based on that.
- Fonts: We added several custom fonts in the
fonts/
folder and imported them using Next.js’slocalFont
utility. - Font Selection: The component uses
useMemo
to pick one font at random when the component is first rendered. - Rendering: That font is applied to the
<h1>
element to display the hero title in a bold, oversized style.
It’s lightweight, consistent, and makes each page load feel a little different.
File Tree
fonts.ts
random-font-hero.tsx