<!--
{
  "documentType" : "article",
  "framework" : "UIKit",
  "identifier" : "/documentation/UIKit/scaling-fonts-automatically",
  "metadataVersion" : "0.1.0",
  "role" : "article",
  "title" : "Scaling fonts automatically"
}
-->

# Scaling fonts automatically

Scale text in your interface automatically using Dynamic Type.

## Discussion

The Dynamic Type feature allows users to choose the size of textual content displayed on the screen. It helps users who need larger text for better readability. It also accomodates those who can read smaller text, allowing more information to appear on the screen. Apps that support Dynamic Type also provide a more consistent reading experience.

To add support for Dynamic Type in your app, you use *text styles*. A text style describes the use of the text, such as [`headline`](/documentation/UIKit/UIFont/TextStyle/headline) or [`body`](/documentation/UIKit/UIFont/TextStyle/body) or [`title1`](/documentation/UIKit/UIFont/TextStyle/title1), and lets the system know how best to adjust its size. You can configure text styles in either Interface Builder or your source code.

Although custom fonts are supported in Dynamic Type, the preferred font is designed to look good at any size. Also, using the preferred font ensures consistency within the system and with other apps. For more information, see Human Interface Guidelines > <doc://com.apple.documentation/design/Human-Interface-Guidelines/typography>.

### Configuring text styles using Interface Builder

In Interface Builder, select the text style from the Font menu, then select the Automatically Adjust Font checkbox to the right of Dynamic Type.

![A partial screenshot of Interface Builder with an arrow pointing at the text style 'Body' as the selected font in the Attributes Inspector for the selected label. Below the font selection is the label Dynamic Type, with the Automatically Adjust Font checkbox selected.](images/com.apple.uikit/scaling-fonts-automatically-1~dark@2x.png)

### Configuring text styles in source code

In your source code, call the [`preferredFont(forTextStyle:)`](/documentation/UIKit/UIFont/preferredFont(forTextStyle:)) method. This method returns a [`UIFont`](/documentation/UIKit/UIFont) that you can assign to a label, text field, or text view. Next, set the [`adjustsFontForContentSizeCategory`](/documentation/UIKit/UIContentSizeCategoryAdjusting/adjustsFontForContentSizeCategory) property on the text control to <doc://com.apple.documentation/documentation/Swift/true>. This setting tells the text control to adjust the text size based on the Dynamic Type setting provided by the user.

```swift
label.font = UIFont.preferredFont(forTextStyle: .body)
label.adjustsFontForContentSizeCategory = true
```

If the [`adjustsFontForContentSizeCategory`](/documentation/UIKit/UIContentSizeCategoryAdjusting/adjustsFontForContentSizeCategory) property is set to <doc://com.apple.documentation/documentation/Swift/false>, the font will initially be the right size, but it won’t respond to text-size changes the user makes in Settings or Control Center. To detect such changes, override the [`traitCollectionDidChange(_:)`](/documentation/UIKit/UITraitEnvironment/traitCollectionDidChange(_:)) method in your view or view controller, and check for changes to the content size category trait. You can also observe [`didChangeNotification`](/documentation/UIKit/UIContentSizeCategory/didChangeNotification) and update the font when the notification arrives.

If you use a custom font in your app and want to let the user control the text size, you must create a scaled instance of the font in your source code. Call [`scaledFont(for:)`](/documentation/UIKit/UIFontMetrics/scaledFont(for:)), passing in a reference to the custom font that’s at a point size suitable for use with [`large`](/documentation/UIKit/UIContentSizeCategory/large). This is the default value for the Dynamic Type setting. You can use this call on the default font metrics, or you can specify a text style, such as [`headline`](/documentation/UIKit/UIFont/TextStyle/headline).

```swift
guard let customFont = UIFont(name: "CustomFont-Light", size: UIFont.labelFontSize) else {
    fatalError("""
        Failed to load the "CustomFont-Light" font.
        Make sure the font file is included in the project and the font name is spelled correctly.
        """
    )
}
label.font = UIFontMetrics(forTextStyle: .headline).scaledFont(for: customFont)
label.adjustsFontForContentSizeCategory = true
```

> Note:
> In Interface Builder, the Dynamic Type option to automatically adjust fonts applies only to text styles or scaled fonts returned by ``doc://com.apple.uikit/documentation/UIKit/UIFontMetrics``. It has no effect on custom fonts set in Interface Builder.

Fonts created through [`UIFontMetrics`](/documentation/UIKit/UIFontMetrics) behave the same as the preferred fonts the system provides. The system scales to match the user’s selected text size in a manner that’s similar to the way the text style you supply is scaled.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)
