All formats

RTF (Rich Text Format)

Full nameRich Text Format
Extensions.rtf
MIME typeapplication/rtf (also text/rtf)
Typeformatted text document, 7-bit ASCII markup
Starts with7B 5C 72 74 66 31 ({\rtf1)
SpecificationRich Text Format (RTF) Specification 1.9.1 (Microsoft, 2008; archived download page)
Maintained byMicrosoft (no updates since 2008)
Licenseopen specification, free to implement

RTF describes a formatted document (fonts, colors, paragraphs, lists, tables, images, headers and footers) as plain ASCII text with control words like \b (bold) and \par (end of paragraph) grouped by braces. Almost every word processor reads and writes it, which made it the traditional exchange format between Microsoft Word, LibreOffice, Apple TextEdit and others. It’s still used for clipboard rich text on Windows and macOS, for Outlook rich-text email, for document templates generated by programs, and in legal and medical systems.

RTF is verbose and the spec is large; each program supports a different subset, so complex layouts don’t survive a round trip. For modern documents use DOCX or ODT; for simple formatted text Markdown or HTML are easier to generate and parse.

When to use RTF#

File structure#

An RTF file is one group {...} that starts with \rtf1. Inside are control words, control symbols, nested groups and plain text. The text is 7-bit ASCII; other characters are escaped.

{\rtf1\ansi\ansicpg1252\deff0
{\fonttbl{\f0\fswiss Arial;}{\f1\fmodern Courier New;}}
{\colortbl;\red0\green0\blue0;\red200\green0\blue0;}
{\info{\title Example}{\author Ann}}
\pard\fs24 Hello, {\b bold} and {\i italic} text.\par
\pard\cf2 Red text, caf\'e9 (code page) and 荤? (Unicode euro).\par
{\f1 Monospaced}\par
}

Syntax#

Element Example Meaning
Group { ... } scopes formatting: properties set inside end at }
Control word \b, \fs24, \b0 a lowercase word and an optional signed number; a space after it is part of the word
Control symbol \~, \-, \{, \\ backslash and one non-letter: non-breaking space, optional hyphen, literal brace or backslash
Destination {\fonttbl ...}, {\*\generator ...} a group whose content isn’t body text; \* marks destinations a reader may skip if unknown
Hex character \'e9 a byte in the document’s code page (\ansicpg1252 → é)
Unicode character 荤? UTF-16 code unit as a signed decimal, followed by a fallback character for old readers (\ucN sets how many)
Binary data \bin1024 the next 1024 bytes are raw binary, used rarely; usually pictures are hex

The header comes before the first text: \rtf1, the character set (\ansi, \mac, \pc), the default code page (\ansicpgN), the default font (\deffN) and these destination groups:

Group Contents
{\fonttbl ...} fonts: \f0 number, family (\froman, \fswiss, \fmodern), charset (\fcharset204 for Cyrillic), name
{\colortbl ...} colors as \redN\greenN\blueN;; index 0 (empty) is “auto”; \cfN and \highlightN refer to them
{\stylesheet ...} paragraph and character styles (\s1 Heading 1, …)
{\*\listtable ...} list definitions for numbered and bulleted lists
{\info ...} metadata: \title, \author, \creatim, \company, …
{\*\generator ...} the program that wrote the file

Document body#

Control words Meaning
\pard, \par reset paragraph properties; end a paragraph
\plain, \b, \i, \ul, \strike reset character formatting; bold, italic, underline, strikethrough (\b0 turns off)
\fN, \fsN, \cfN font, font size in half-points (\fs24 = 12 pt), text color
\ql, \qc, \qr, \qj left, center, right, justified alignment
\liN, \riN, \fiN, \sbN, \saN indents and spacing in twips (1/1440 inch)
\line, \tab, \page line break, tab, page break
\trowd, \cellxN, \cell, \row table row definition, cell right edge in twips, end of cell, end of row
{\pict \pngblip \picwN \pichN ... hex} picture: PNG (\pngblip), JPEG (\jpegblip), EMF (\emfblip), WMF (\wmetafile8), data as hex digits
{\field{\*\fldinst HYPERLINK "url"}{\fldrslt text}} fields: hyperlinks, page numbers, dates
{\header ...}, {\footer ...} page headers and footers
\sectd, \paperwN, \margl, … section and page setup

Reading RTF as text#

To extract plain text: track the group stack, skip destinations you don’t handle (font table, color table, stylesheet, info, pictures, any group starting with {\*), turn \par and \line into newlines, \tab into tabs, decode \'hh with the current code page (from \ansicpg or the font’s \fcharset), decode \uN and skip the next N fallback characters (from \uc, default 1). Libraries like striprtf do exactly this.

Variants#

Variant What it is
Encapsulated HTML Outlook stores HTML email as RTF with \fromhtml1; the original HTML is in {\*\htmltag ...} groups and can be recovered
RTFD macOS: a folder (package) with TXT.rtf and the attached images; TextEdit uses it when a document has images
Compressed RTF Outlook/MAPI PR_RTF_COMPRESSED property, LZ-compressed RTF (see MS-OXRTFCP)

Specifications and documentation#

Software that opens RTF files#

SoftwareWindowsmacOSLinuxWebCanNotes
SumatraPDF✓viewfree, open source; shows RTF as a reflowable document (no headers, footers or vector pictures)
Microsoft Word✓✓✓view, edit, create, convertcommercial; the reference RTF implementation. Also on Android and iOS
LibreOffice Writer✓✓✓view, edit, create, convertfree, open source; soffice --convert-to pdf file.rtf
TextEdit✓view, edit, createbuilt into macOS; RTF is its default format
Apple Pages✓view, edit, convertfree; imports and exports RTF. Also on iOS
WordPad✓view, edit, createbuilt into Windows 10 and Windows 11 before 24H2; removed since
Google Docs✓view, edit, convertfree; imports RTF and downloads as RTF
ONLYOFFICE Docs✓✓✓✓view, edit, create, convertfree, open source (AGPL) desktop editors
AbiWord✓view, edit, create, convertfree, open source
Pandoc✓✓✓convertfree, open source; reads and writes RTF (basic formatting)
unrtf✓✓convertGNU command line converter to HTML, text, LaTeX

Libraries#

RTF libraries mostly extract text or convert to HTML; few write RTF. See all RTF libraries.

C#RtfPipe
JavaRTF Parser Kit, RTFEditorKit
Pythonstriprtf
Rubyruby-rtf
Rustrtf-parser
PHPPHPWord