Cairo (stylized as cairo) is an open-source graphics library that provides a vector graphics-based, device-independent API for two-dimensional drawing. Written in C, it supports output to multiple backends including X11, Quartz, Win32, SVG, PDF, and PostScript. Cairo uses hardware acceleration when available.
Cairo is used by GTK (versions 2.8 through 3.x), the Gecko layout engine in Mozilla Firefox, WebKit, Poppler, and Inkscape, among other projects. The library is dual-licensed under the GNU Lesser General Public License version 2.1 and the Mozilla Public License 1.1.
The name derives from the project's original name "Xr," interpreted as the Greek letters chi and rho, which together sound like "Cairo."
Keith Packard and Carl Worth created the project for use in the X Window System, originally naming it Xr (later Xr/Xc). The name was changed in July 2003 to emphasize that the library was cross-platform and not tied to X11.
Cairo 1.0 was released in 2005, providing a stable API. Version 1.2 (2006) added PDF and SVG backend support. Version 1.4 (2007) improved font handling and added the <code>cairo_push_group</code> API for offscreen rendering. Version 1.10 (2010) introduced the recording surface, which captures drawing operations for later replay, and the <code>cairo_region</code> API.
In 2022, several legacy backends were removed, including BeOS, OS/2, DirectFB, and the OpenGL backend (which had been inactive for a decade).
GTK adopted Cairo for rendering in version 2.8 (2005), and GTK 3.0 (2011) used Cairo for all rendering. GTK 4 (2020) shifted to Vulkan and OpenGL renderers via GSK, reducing Cairo's role.
Cairo uses a three-layer drawing model based on Porter-Duff compositing:
This approach differs from Scalable Vector Graphics (SVG), which attaches style attributes directly to shapes.
Cairo supports output to multiple backends ("surfaces"):
Legacy backends for BeOS, OS/2, DirectFB, and OpenGL (direct and via glitz) were removed in 2022-2023. Experimental backends have been developed for OpenVG, Qt, Skia, and Direct2D.
Bindings exist for C++, C# and other CLI languages, Delphi, Haskell, Julia, Lua, Perl, PHP, Python, Ruby, Rust, Scheme, and Smalltalk.
Cairo handles Latin and CJK fonts but does not directly support complex text layout scripts that require glyph shaping. The developers recommend using Pango for complex text, which integrates with Cairo for rendering.
A simple program that generates an SVG file using Cairo: