The .underline() view modifier in SwiftUI applies an underline style to text characters in a View.


Text("This text will be underlined")

The .underline() modifier is applied to all characters within the Text (which conforms to the View protocol).


The following example creates some underlined text:

var body: some View {
Text("Underlined text")

In the above example, the .underline() modifier is called on the Text view. This applies an underlined style to all characters within the Text.

This will display the following:

SwiftUI ViewModifier Underline


Interested in helping build Docs? Read the Contribution Guide or share your thoughts in this feedback form.

Learn SwiftUI on Codecademy