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

# monospaced(_:)

Returns a font adding or removing fixed-width design from the same family as the base font.

## Declaration

```swift
func monospaced(_ isActive: Bool) -> Font
```

## Return Value

Return Value A font with the fixed-width design added or removed, from the same family as the base font, if one is available, and a default font otherwise.

## Discussion

Discussion If there’s no suitable font face in the same family, SwiftUI returns a default 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(true)

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 appropriately-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.
