NEW BOOK! SwiftUI Fundamentals: The essential guide to SwiftUI core concepts and APIs. Learn more ...NEW BOOK! SwiftUI Fundamentals:Master SwiftUI core concepts and APIs. Learn more...

Font modifiers in SwiftUI

We are all familiar with view modifiers in SwiftUI, such as font(), background(), frame(), etc. We use them all the time to style and customize views in our apps. They are methods defined on the View type that return a different version of the original view. I previously wrote about text modifiers, which are methods applied directly to Text, returning a modified Text, that can be used inside text interpolation. In this post I'd like to explore font modifiers, which work similarly to view and text modifiers but are applied to the Font type, returning a modified font.

Here is an example of font modifiers in action. We apply bold(), monospaced() and smallCaps() to the largeTitle font to customize the way it looks.

Text("Hello, world!")
    .font(
        .largeTitle
            .bold()
            .monospaced()
            .smallCaps()
    )
iPhone screen displaying text in bold, monospaced and small caps iPhone screen displaying text in bold, monospaced and small caps

We can view the full list of font modifiers in SwiftUI Font documentation in the "Styling a font" section. We can see that they are not exactly the same as modifiers available on the Text type or methods for styling text on the View type.

For example, there is a font modifier for customizing leading, which lets us adjust the line spacing of a font and takes a Font.Leading enum as an argument. This modifier can't be applied to a Text or any other view, only to a Font.

VStack(spacing: 20) {
    Text(exampleText)
        .font(
            .largeTitle
                .leading(.tight)
        )
    Text(exampleText)
        .font(
            .largeTitle
                .leading(.loose)
        )
}
iPhone screen displaying text with tight leading and loose leading iPhone screen displaying text with tight leading and loose leading

Font modifiers are a great way to manage typography in SwiftUI, letting us style text directly at the font level. Using these modifiers thoughtfully can help us create a polished look that improves our app’s user experience.


If you want to build a strong foundation in SwiftUI, my new book SwiftUI Fundamentals takes a deep dive into the framework’s core principles and APIs to help you understand how it works under the hood and how to use it effectively in your projects.

For more resources on Swift and SwiftUI, check out my other books and book bundles.

SwiftUI Fundamentals by Natalia Panferova book coverSwiftUI Fundamentals by Natalia Panferova book cover

Deepen your understanding of SwiftUI!$35

The essential guide to SwiftUI core concepts and APIs

SwiftUI Fundamentalsby Natalia Panferova

  • Explore the key APIs and design patterns that form the foundation of SwiftUI
  • Develop a deep, practical understanding of how SwiftUI works under the hood
  • Learn from a former Apple engineer who worked on widely used SwiftUI APIs

Deepen your understanding of SwiftUI!

The essential guide to SwiftUI core concepts and APIs

SwiftUI Fundamentals by Natalia Panferova book coverSwiftUI Fundamentals by Natalia Panferova book cover

SwiftUI Fundamentals

by Natalia Panferova

$35