kerning

Sets the spacing, or kerning, between characters.

Text ModifieriOS 13.0+macOS 10.15+tvOS 13.0+watchOS 6.0+kerning(_:) in SwiftUI

Declaration

React
compose().kerning(kerning: number)
Swift
nonisolated func kerning(_ kerning: CGFloat) -> Text

Parameters

  • kerning*number

    The spacing to use between individual characters in this text. Value of 0 sets the kerning to the system default value.

Return value

Text with the specified amount of kerning.

Discussion

Kerning defines the offset, in points, that a text view should shift characters from the default spacing. Use positive kerning to widen the spacing between characters. Use negative kerning to tighten the spacing between characters.

VStack(alignment: .leading) {
    Text("ABCDEF").kerning(-3)
    Text("ABCDEF")
    Text("ABCDEF").kerning(3)
}

The last character in the first case, which uses negative kerning, experiences cropping because the kerning affects the trailing edge of the text view as well.

Kerning attempts to maintain ligatures. For example, the Hoefler Text font uses a ligature for the letter combination ffl, as in the word raffle, shown here with a small negative and a small positive kerning:

The ffl letter combination keeps a constant shape as the other letters move together or apart. Beyond a certain point in either direction, however, kerning does disable nonessential ligatures.

See also

More in Text modifiers.