Pocket How
Design and HIG

Dynamic Type in SwiftUI: text styles, accessibility sizes and adaptive layouts

iOS 16+, iPadOS 16+. Intermediate. By Cihat Salik, .

Short answer

Set every font with a text style or Font.custom(_:size:relativeTo:), scale spacing and icon sizes with @ScaledMetric, and switch layouts at accessibility sizes with dynamicTypeSize.isAccessibilitySize, AnyLayout or ViewThatFits. Avoid fixed heights and single-line limits, and only cap sizes for text that is already large.

The problem

Dynamic Type lets people pick their text size in Settings, and many people do. At the default Large setting, iOS body text is 17 points. At the largest accessibility size, AX5, the same body style is 53 points, more than three times bigger, and a caption grows from 12 to 43. Layouts that were designed only at the default setting break in predictable ways at those sizes: text truncates to “Sett…”, buttons overlap, icons stay tiny next to huge labels, and rows with a fixed height clip their content.

Most of the fix is cheap if you build for it from the start. SwiftUI scales text styles for you. The work is in the pieces SwiftUI can’t guess: custom fonts, spacing, icon sizes, and layouts that need to change shape when text gets very big.

Step 1: use text styles everywhere

A text style is a named role, such as .body, .headline or .caption, that maps to a weight, size and leading at each Dynamic Type size. The HIG lists the full tables for iOS. A few anchors at the default size: Large Title 34 pt, Title 1 28, Headline 17 semibold, Body 17, Subheadline 15, Footnote 13, Caption 1 12, Caption 2 11.

VStack(alignment: .leading, spacing: 4) {
    Text("Morning run")
        .font(.headline)
    Text("5.2 km · 28 min")
        .font(.subheadline)
        .foregroundStyle(.secondary)
}

That snippet scales from xSmall to AX5 with no extra code. The HIG suggests using the built-in styles to express hierarchy and adjusting them with weight or leading when you need another level, rather than inventing point sizes. fontWeight(_:), bold() and Font.leading(_:) give you those adjustments.

A few rules from the HIG’s legibility section are worth keeping in your head:

  • The iOS default text size is 17 points and the minimum is 11.
  • Avoid Ultralight, Thin and Light weights for interface text. They disappear at small sizes.
  • Use as few typefaces as you can. Hierarchy comes from size, weight and colour.

Font.system(size:) is the one to avoid. A fixed point size doesn’t scale with Dynamic Type at all. If a design calls for “18 point”, ask which role that text plays and pick the style, or use the custom font approach below with relativeTo:.

Step 2: make custom fonts scale

Custom fonts scale too, as long as you tell SwiftUI which style to follow. Apple’s custom font article shows that Font.custom(_:size:) (iOS 14) scales relative to .body by default, and Font.custom(_:size:relativeTo:) (iOS 14) follows any style you choose.

extension Font {
    static let brandTitle = Font.custom("Fraunces-SemiBold", size: 30, relativeTo: .title)
    static let brandBody = Font.custom("Inter-Regular", size: 17, relativeTo: .body)
}

Three details from Apple’s documentation catch people out. The name must be the font’s PostScript name, which Font Book shows in its info panel. The file must be listed under UIAppFonts in the Info.plist. And if SwiftUI can’t load the font, it silently falls back to the system font, so check a screenshot rather than assuming it worked. SwiftUI also doesn’t synthesize bold or italic for custom fonts; ship the real weights.

The HIG adds that custom fonts must honour the same accessibility features as system fonts, including Bold Text. If your custom font has a bold weight, read legibilityWeight from the environment and switch to it when people turn Bold Text on.

Step 3: scale everything that sits next to text

Text styles only scale text. Padding, spacing, icon frames and corner radii stay fixed unless you scale them. @ScaledMetric (iOS 14) is the tool:

struct WorkoutRow: View {
    @ScaledMetric(relativeTo: .headline) private var iconSize: CGFloat = 28
    @ScaledMetric(relativeTo: .body) private var spacing: CGFloat = 12

    let title: String
    let detail: String

    var body: some View {
        HStack(spacing: spacing) {
            Image(systemName: "figure.run")
                .font(.system(size: iconSize * 0.6))
                .frame(width: iconSize, height: iconSize)
                .background(.tint.opacity(0.15), in: .circle)
            VStack(alignment: .leading) {
                Text(title).font(.headline)
                Text(detail).font(.subheadline).foregroundStyle(.secondary)
            }
        }
    }
}

Fatbobman’s property wrapper guide makes two points that save debugging time. Each text style follows its own growth curve, so scaling relative to .caption and relative to .largeTitle gives different results; match the metric to the text it sits beside. And @ScaledMetric changes sizes, never structure. A row that scales its icon perfectly can still be the wrong shape at AX5.

The HIG says meaningful icons should grow with the text. SF Symbols do that automatically when you size them with a font. Custom images need a scaled frame like the one above.

Step 4: change the layout at accessibility sizes

At the five accessibility sizes, horizontal layouts run out of room. The HIG’s guidance is to stack text above secondary items such as timestamps and icons, and to reduce the number of columns. SwiftUI gives you three ways to do it.

Read the size and branch. DynamicTypeSize (iOS 15) is ordered, so you can compare sizes, and isAccessibilitySize is true for the five large ones.

struct ReceiptLine: View {
    @Environment(\.dynamicTypeSize) private var typeSize
    let label: String
    let amount: String

    var body: some View {
        let layout = typeSize.isAccessibilitySize
            ? AnyLayout(VStackLayout(alignment: .leading, spacing: 4))
            : AnyLayout(HStackLayout())

        layout {
            Text(label)
            if !typeSize.isAccessibilitySize { Spacer() }
            Text(amount)
                .font(.body.monospacedDigit())
                .foregroundStyle(.secondary)
        }
    }
}

AnyLayout (iOS 16) swaps the container without destroying the subviews’ state, and the change animates if you wrap it in an animation. Prefer it over an if that switches between HStack and VStack, which creates new view identities and resets anything inside.

Let the space decide. ViewThatFits (iOS 16) tries its children in order and uses the first that fits. It is handy when the right layout depends on width as much as text size, for example a pair of buttons that sit side by side on iPad and stack on a small iPhone.

ViewThatFits(in: .horizontal) {
    HStack(spacing: 12) { actions }
    VStack(spacing: 12) { actions }
}

Paul Hudson warns that without an axis, ViewThatFits measures both directions and treats any wrapped text as not fitting. That makes it pick the fallback far more often than you expect. Pass in: .horizontal or in: .vertical to measure only the axis you care about.

Which one to use. Keith Harrison builds an adaptive stack on Use Your Loaf that combines size class, type size and width; Apple’s docs show the AnyLayout pattern; Paul Hudson leans on ViewThatFits. This article recommends isAccessibilitySize with AnyLayout for rows in lists, because the switch is predictable and matches what the HIG describes. Use ViewThatFits for button groups and toolbars where available width is the real constraint.

Step 5: let text wrap

Truncation is the most visible Dynamic Type failure. The HIG asks you to show as much useful text at AX5 as at the largest standard size, and to avoid truncating text in scrolling content unless people can open the full text somewhere.

  • Don’t put lineLimit(1) on anything a person needs to read. Use a range such as lineLimit(2...4) (iOS 16) when you need a bound.
  • lineLimit(_:reservesSpace:) (iOS 16) keeps cards in a grid the same height by reserving the lines even when the text is short.
  • Don’t give text containers fixed heights. Let them grow and put long screens in a ScrollView.
  • Use minimumScaleFactor(_:) only for short, single-line values like a big number in a dashboard tile. Shrinking body text defeats the user’s choice.
  • Text wraps and SF Symbols scale inside it, so build instructions like “Tap the plus button to add” with an interpolated Image for the symbol rather than placing an icon next to a label.

Step 6: cap sizes only where it is safe

dynamicTypeSize(_:) (iOS 15) accepts a range and limits the sizes a subtree will use. UIKit has minimumContentSizeCategory and maximumContentSizeCategory on views, also from iOS 15.

Text(score.formatted())
    .font(.largeTitle.bold())
    .dynamicTypeSize(...DynamicTypeSize.accessibility2)

Keith Harrison’s post on restricting sizes is clear about where this belongs. Text that is already large, like a large title or a hero number, can reasonably stop growing at some point. Using limits to hide a layout that breaks is the wrong use, and he relays Apple’s position that the API shouldn’t unduly limit text size because all functionality has to work at the largest setting. Multiple ranges in the hierarchy combine as an intersection, so a cap set high up the tree affects everything below it.

The HIG adds a related idea: not every piece of text needs to grow equally. People who raise the text size want the content to get bigger, not necessarily tab titles or transient labels. System bars already handle this for you. In your own views, prioritize the content.

Traps and edge cases

Testing only in previews. Previews help, but test on a device or simulator with Settings > Accessibility > Display & Text Size > Larger Text and the Larger Accessibility Sizes switch on. Xcode’s Environment Overrides panel changes the size live while the app runs. In code, .environment(\.dynamicTypeSize, .accessibility5) on a preview shows the worst case.

Mixed UIKit screens. UIKit labels need UIFont.preferredFont(forTextStyle:) and adjustsFontForContentSizeCategory = true, or UIFontMetrics for custom fonts, to update live. Hosted SwiftUI views scale on their own, so a mixed screen can end up half scaled.

Hierarchy at large sizes. The HIG asks you to keep primary elements near the top even at huge sizes. When a header grows to fill the screen, the content people came for can drop below the fold. Move secondary metadata below the main content at accessibility sizes.

Images with text. Text baked into an image never scales. Use real text over the image instead.

Tap targets. Bigger text usually means bigger targets, but icon-only buttons don’t grow unless you size them with a font or a scaled metric. Keep every target at least 44 by 44 points at every size.

Checklist

Check How
No fixed font sizes Search for .system(size: and replace with text styles
Custom fonts scale Font.custom(_:size:relativeTo:), PostScript name, UIAppFonts
Spacing and icons scale @ScaledMetric(relativeTo:) matched to nearby text
Rows reflow isAccessibilitySize with AnyLayout, or ViewThatFits(in:)
Text wraps No lineLimit(1) on content; ranges where needed
Caps are rare dynamicTypeSize(...) only on text that is already large
Bold Text works Custom fonts switch weight via legibilityWeight
Tested at AX5 Every screen, every state, in the longest language you ship

Run the last row with your longest localization. German or Finnish at AX5 is the combination that finds the layouts English at Large never will.

Sources and further reading

Read next