<!--
{
  "documentType" : "article",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/textkit",
  "metadataVersion" : "0.1.0",
  "role" : "collectionGroup",
  "title" : "TextKit"
}
-->

# TextKit

Manage text storage and perform custom layout of text-based content in your app’s views.

## Discussion

TextKit provides several classes to control the layout of text, such as [`NSTextContentStorage`](/documentation/AppKit/NSTextContentStorage), [`NSTextLayoutManager`](/documentation/AppKit/NSTextLayoutManager), and [`NSTextContainer`](/documentation/AppKit/NSTextContainer).

Additionally, TextKit uses <doc://com.apple.documentation/documentation/Foundation/NSAttributedString> objects extensively. The [`NSTextStorage`](/documentation/AppKit/NSTextStorage) class is a subclass of <doc://com.apple.documentation/documentation/Foundation/NSMutableAttributedString>, and many of the TextKit classes, for example, the classes listed in `Formatted content`, focus on creating complex <doc://com.apple.documentation/documentation/Foundation/NSAttributedString> instances. Use these classes to specify your text’s format.

Most of the time, you can use TextKit to fine tune the formatting and layout of a [`NSTextView`](/documentation/AppKit/NSTextView) by modifying various properties of your view’s layout manager, text container, or text storage objects in your app. If you need more control, you can also use TextKit to build your text controls.

## Topics

### Text management

[`NSTextContentStorage`](/documentation/AppKit/NSTextContentStorage)

A concrete object for managing your view’s text content and generating the text elements necessary for layout.

[`NSTextContentManager`](/documentation/AppKit/NSTextContentManager)

An abstract class that defines the interface and a default implementation for managing the text document contents.

  <doc://com.apple.documentation/documentation/Foundation/NSAttributedString>

  <doc://com.apple.documentation/documentation/Foundation/NSMutableAttributedString>

### Text management

[`NSTextContentStorage`](/documentation/AppKit/NSTextContentStorage)

A concrete object for managing your view’s text content and generating the text elements necessary for layout.

[`NSTextContentManager`](/documentation/AppKit/NSTextContentManager)

An abstract class that defines the interface and a default implementation for managing the text document contents.

  <doc://com.apple.documentation/documentation/Foundation/NSAttributedString>

  <doc://com.apple.documentation/documentation/Foundation/NSMutableAttributedString>

[TextKit string attributes](/documentation/AppKit/textkit-string-attributes)

AppKit-specific keys and values for displaying text and managing documents.

### Formatting and attributes

[`NSParagraphStyle`](/documentation/AppKit/NSParagraphStyle)

The paragraph or ruler attributes for an attributed string.

[`NSMutableParagraphStyle`](/documentation/AppKit/NSMutableParagraphStyle)

An object for changing the values of the subattributes in a paragraph style attribute.

[`NSTextTab`](/documentation/AppKit/NSTextTab)

A tab in a paragraph.

[`NSTextList`](/documentation/AppKit/NSTextList)

A section of text that forms a single list.

[`NSTextTable`](/documentation/AppKit/NSTextTable)

An object that represents a text table as a whole.

[`NSTextTableBlock`](/documentation/AppKit/NSTextTableBlock)

A text block that appears as a cell in a text table.

[`NSTextBlock`](/documentation/AppKit/NSTextBlock)

A block of text laid out in a subregion of the text container.

### Content elements

  <doc://com.apple.documentation/documentation/UIKit/enriching-your-text-in-text-views>

[`NSTextParagraph`](/documentation/AppKit/NSTextParagraph)

A class that represents a single paragraph backed by an attributed string as the contents.

[`NSTextListElement`](/documentation/AppKit/NSTextListElement)

A class that represents a text list node.

[`NSTextElement`](/documentation/AppKit/NSTextElement)

An abstract base class that represents the smallest units of text layout such as paragraphs or attachments.

[`NSTextElementProvider`](/documentation/AppKit/NSTextElementProvider)

A protocol the text content manager and its concrete subclasses conform to, which defines the interface for interacting with custom content types of a text document.

### Location and selection

[`NSTextRange`](/documentation/AppKit/NSTextRange)

A class that represents a contiguous range between two locations inside document contents.

[`NSTextSelection`](/documentation/AppKit/NSTextSelection)

A class that represents a single logical selection context that corresponds to an insertion point.

[`NSTextSelectionNavigation`](/documentation/AppKit/NSTextSelectionNavigation)

An interface you use to expose methods for obtaining results from actions performed on text selections.

[`NSTextLocation`](/documentation/AppKit/NSTextLocation)

An interface you implement that represents an abstract location inside your document’s content.

### Layout

  <doc://com.apple.documentation/documentation/UIKit/using-textkit-2-to-interact-with-text>

[`NSTextLayoutManager`](/documentation/AppKit/NSTextLayoutManager)

The primary class that you use to manage text layout and presentation for custom text displays.

[`NSTextContainer`](/documentation/AppKit/NSTextContainer)

A region where text layout occurs.

[`NSTextLayoutFragment`](/documentation/AppKit/NSTextLayoutFragment)

A class that represents the layout fragment typically corresponding to a rendering surface, such as a layer or view subclass.

[`NSTextLineFragment`](/documentation/AppKit/NSTextLineFragment)

A class that represents a line fragment as a single textual layout and rendering unit inside a text layout fragment.

[`NSTextViewportLayoutController`](/documentation/AppKit/NSTextViewportLayoutController)

Manages the layout process inside the viewport interacting with its delegate.

[`NSTextLayoutOrientationProvider`](/documentation/AppKit/NSTextLayoutOrientationProvider)

A set of methods that define the orientation of text for an object.

### Attachments

[`NSTextAttachment`](/documentation/AppKit/NSTextAttachment)

The values for the attachment characteristics of attributed strings and related objects.

[`NSTextAttachmentViewProvider`](/documentation/AppKit/NSTextAttachmentViewProvider)

A container object that associates a text attachment at a particular document location with a view object.

[`NSAdaptiveImageGlyph`](/documentation/AppKit/NSAdaptiveImageGlyph)

A data object for an emoji-like image that can appear in attributed text.

[`NSTextAttachmentContainer`](/documentation/AppKit/NSTextAttachmentContainer)

A set of methods that defines the interface to text attachment objects from a layout manager.

[`NSTextAttachmentLayout`](/documentation/AppKit/NSTextAttachmentLayout)

A set of methods that defines the interface to attachment objects from a text layout manager.

[`NSTextAttachmentCell`](/documentation/AppKit/NSTextAttachmentCell-swift.class)

An object that implements the functionality of the text attachment cell protocol.

[`NSTextAttachmentCellProtocol`](/documentation/AppKit/NSTextAttachmentCellProtocol)

A set of methods that declares the interface for objects that draw text attachment icons and handle mouse events on their icons.

### Glyphs

[`NSGlyph`](/documentation/AppKit/NSGlyph)

The type used to specify glyphs.

[`NSGlyphStorage`](/documentation/AppKit/NSGlyphStorage)

A set of methods that a glyph storage object must implement to interact properly with [`NSGlyphGenerator`](/documentation/AppKit/NSGlyphGenerator).

[`NSGlyphGenerator`](/documentation/AppKit/NSGlyphGenerator)

An object that performs the initial, nominal glyph generation phase in the layout process.

[`NSGlyphInfo`](/documentation/AppKit/NSGlyphInfo)

A glyph attribute in an attributed string.

[Reserved Glyph Codes](/documentation/AppKit/reserved-glyph-codes)

These constants define reserved glyph codes.

[`NSFontRenderingMode`](/documentation/AppKit/NSFontRenderingMode)

The font rendering mode.

### TextKit 1

[`NSTextStorage`](/documentation/AppKit/NSTextStorage)

The fundamental storage mechanism of TextKit that contains the text managed by the system.

[`NSLayoutManager`](/documentation/AppKit/NSLayoutManager)

An object that coordinates the layout and display of text characters.

[`NSATSTypesetter`](/documentation/AppKit/NSATSTypesetter)

A concrete typesetter object that places glyphs during the text layout process.

[`NSTypesetter`](/documentation/AppKit/NSTypesetter)

An abstract class that performs various type layout tasks.

[`NSLineSweepDirection`](/documentation/AppKit/NSLineSweepDirection)

Values that describe the progression of text on a page.

[`NSLineMovementDirection`](/documentation/AppKit/NSLineMovementDirection)

The direction in which a line moves.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)
