---
title: monospaced()
framework: swiftui
role: symbol
role_heading: Instance Method
path: swiftui/font/monospaced()
---

# monospaced()

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

## Declaration

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

## Return Value

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

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 view: struct ContentView: View {     let myFont = Font         .system(size: 24)         .monospaced()

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

SwiftUI may provide different fixed-width replacements for standard user interface fonts (such as title, or a system font created with system(_:design:)) than for those same fonts when created by name with custom(_:size:). The 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(_:) initializer to use an appropropriately-styled AttributedString for the text view’s content. You can use the init(markdown:options:baseURL:) initializer to provide a Markdown-formatted string containing the backtick-syntax (`…`) to apply code voice to specific ranges of the attributed string.

## See Also

### Styling a font

- [bold()](swiftui/font/bold().md)
- [italic()](swiftui/font/italic().md)
- [monospacedDigit()](swiftui/font/monospaceddigit().md)
- [smallCaps()](swiftui/font/smallcaps().md)
- [lowercaseSmallCaps()](swiftui/font/lowercasesmallcaps().md)
- [uppercaseSmallCaps()](swiftui/font/uppercasesmallcaps().md)
- [weight(_:)](swiftui/font/weight(_:).md)
- [width(_:)](swiftui/font/width(_:).md)
- [Font.Width](swiftui/font/width.md)
- [leading(_:)](swiftui/font/leading(_:).md)
- [Font.Leading](swiftui/font/leading.md)
