How to style Text view in SwiftUI

You can style SwiftUI Text views with a bunch of dedicated ViewModifiers. Learn about them in this article.

Text styles covered in this article

How to apply italic text style?

You can switch the font to cursive using the italic modifier.


How to apply bold text style?

The bold view modifier will make the displayed text bolder.


Of course, you can stack these two modifiers to create an italic and bold typeface.

Text("bold & italic")

How to change font weight?

If you want to set your font to something different than bold, you can use the weight modifier.

Text("fontWeight heavy")

How to change the font?

The font modifier is applicable if you want to change more text parameters. There are predefined fonts that you can use for various elements of the app. In the example below title font is set.

Text("font .title")

You can create own Font struct to pick different font family, size or weight.

How to strikethrough a text?

There are two versions of the strikethrough modifier. One without argument that displays a line in the foreground color:


The second one has an active parameter and color option where you can control a strikethrough color.

Text("strikethrough color")
    .strikethrough(true, color: .red)

How to underline a text?

Instead of strikethrough, you may want to underline a text. API for this is very similar. More straightforward underline modifier takes foreground color value:


And more advanced has active and color parameters:

Text("underline color")
    .underline(true, color: .red)

How to change the text color?

Text view content color can be changed using the foregroundColor modifier.


Learn how to colorize text using a gradient.

How to change the Text view background color?

The background of any view can be applied using the background modifier. Since SwiftUI Color is also a view, you can use it to apply a color background to the text below.


How to change the baseline offset of text?

The baseline can be used to display your text above or below the normal text baseline. The baselineOffset view modifier accept positive and negative numbers. You will often use it with Text view concatenation with + sign.

Text("baseline ")
   + Text("Off")
   + Text("set")

How to adjust kerning?

You can adjust kerning (the distance between a pair of letters) with the kerning modifier.

Text("kerning kerning kerning")

How to adjust tracking?

Tracking delivers a similar effect to kerning, but it adds distance between each character, which means that ligatures will also be separated.

Text("tracking tracking tracking")
Text styles examples in Xcode Playground