<!--
{
  "availability" : [
    "iOS: 15.0.0 -",
    "iPadOS: 15.0.0 -",
    "macCatalyst: 15.0.0 -",
    "macOS: 12.0.0 -",
    "tvOS: 15.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 8.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/Font/monospaced()",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI4FontV10monospacedACyF"
  },
  "title" : "monospaced()"
}
-->

# monospaced()

Returns a fixed-width font from the same family as the base font.

```
func monospaced() -> Font
```

## Return Value

A fixed-width font from the same family as the base font,
if one is available, and a default fixed-width font otherwise.

## Discussion

If there’s no suitable font face in the same family, SwiftUI
returns a default fixed-width font.

The following example adds the `monospaced()` modifier to the default
system font, then applies this font to a [`Text`](/documentation/SwiftUI/Text) view:

```
struct ContentView: View {
    let myFont = Font
        .system(size: 24)
        .monospaced()

    var body: some View {
        Text("Hello, world!")
            .font(myFont)
            .padding()
            .navigationTitle("Monospaced")
    }
}
```

![A macOS window showing the text Hello, world in a 24-point](images/com.apple.SwiftUI/Environment-Font-monospaced-1@2x.png)

SwiftUI may provide different fixed-width replacements for standard
user interface fonts (such as [`title`](/documentation/SwiftUI/Font/title), or a system font created
with [`system(_:design:)`](/documentation/SwiftUI/Font/system(_:design:))) than for those same fonts when created
by name with [`custom(_:size:)`](/documentation/SwiftUI/Font/custom(_:size:)).

The [`font(_:)`](/documentation/SwiftUI/View/font(_:)) modifier applies the font to all text within
the view. To mix fixed-width text with other styles in the same
`Text` view, use the [`init(_:)`](/documentation/SwiftUI/Text/init(_:)-1a4oh) initializer to use an
appropropriately-styled
<doc://com.apple.documentation/documentation/Foundation/AttributedString>
for the text view’s content. You can use the
<doc://com.apple.documentation/documentation/Foundation/AttributedString/init(markdown:options:baseURL:)-52n3u>
initializer to provide a Markdown-formatted string containing the
backtick-syntax (`…`) to apply code voice to specific ranges
of the attributed string.

---

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)