Skip to main content

Sixel graphics

AI-Generated Content
This page was generated with the assistance of AI and may contain inaccuracies. It is intended as a placeholder for future human verification. If you spot issues ahead of its initial review, please report them on GitHub!
Standard

Sixel graphics is a DCS-based bitmap graphics protocol originally introduced on the DEC VT240 and VT340 terminals. It encodes images as rows of six vertical pixels (a "sixel"), transmitted inline within the terminal data stream.

Syntax​

DCS P1 ; P2 ; P3 q sixel-data ST    Sixel graphics sequence
Formal syntax
SIXEL = 0x1b, "P", [ P1 ], ";", [ P2 ], ";", [ P3 ], "q",
      [ raster-attributes ], { sixel-statement }, 0x1b, "\\" ;

P1 = digit, { digit } ;             (* pixel aspect ratio, default: 0 *)
P2 = digit, { digit } ;             (* background select: 0 or 2 = device default, 1 = no change *)
P3 = digit, { digit } ;             (* horizontal grid size in pixels, default: 0 *)

raster-attributes = '"', Pan, ";", Pad, [ ";", Ph, ";", Pv ] ;
Pan = digit, { digit } ;            (* pixel aspect numerator *)
Pad = digit, { digit } ;            (* pixel aspect denominator *)
Ph  = digit, { digit } ;            (* horizontal extent in pixels *)
Pv  = digit, { digit } ;            (* vertical extent in pixels *)

sixel-statement = sixel-data
              | color-intro
              | repeat-intro
              | CR
              | LF ;

sixel-data = sixel-char, { sixel-char } ;
sixel-char = ? character in range 0x3F..0x7E ? ;    (* '?' to '~', value = char - 0x3F *)

color-intro   = "#", Pc, ";", Pu, ";", Px, ";", Py, ";", Pz ;
Pc = digit, { digit } ;             (* color register number *)
Pu = "1" | "2" ;                    (* 1 = HLS, 2 = RGB *)
Px = digit, { digit } ;             (* hue or red, 0-360 or 0-100 *)
Py = digit, { digit } ;             (* lightness or green, 0-100 *)
Pz = digit, { digit } ;             (* saturation or blue, 0-100 *)

repeat-intro  = "!", Pn, sixel-char ;
Pn = digit, { digit } ;             (* repeat count *)

CR = "$" ;                           (* carriage return — move to left edge *)
LF = "-" ;                           (* line feed — advance down one sixel row *)

digit = "0" | "1" | "2" | "3" | "4"
    | "5" | "6" | "7" | "8" | "9" ;

Parameters​

ParameterDescriptionDefault
P1Pixel aspect ratio selector (see table below)0
P2Background color select: 0 or 2 = use terminal default, 1 = do not erase background0
P3Horizontal grid size in pixels (ignored by most modern terminals)0

P1 aspect ratio values​

ValueAspect ratio (vertical:horizontal)
0, 12:1
25:1
3, 43:1
5, 62:1
7, 8, 91:1

Most modern terminal emulators ignore P1 and render with 1:1 pixel aspect ratio.

Description​

Sixel graphics encode images as a series of vertical six-pixel columns. Each sixel character (in the range ? to ~, ASCII 0x3F to 0x7E) represents a column of six pixels, where bit 0 is the top pixel and bit 5 is the bottom pixel. The character's value minus 0x3F gives the six-bit pattern.

For example, the character ~ (0x7E) has value 63 (0x3F subtracted), which is 111111 in binary -- all six pixels on. The character ? (0x3F) has value 0 -- all six pixels off.

Raster attributes​

The optional raster attributes string "Pan;Pad;Ph;Pv specifies the pixel aspect ratio (Pan:Pad) and image dimensions (Ph x Pv pixels). Modern terminals use this to allocate the image canvas before rendering begins.

Color introduction​

The # character introduces a color command:

  • Color selection: #Pc selects color register Pc for subsequent sixel data.
  • Color definition: #Pc;Pu;Px;Py;Pz defines a color register. Pu=1 specifies HLS (Hue/Lightness/Saturation) coordinates; Pu=2 specifies RGB percentages (0-100 for each component).

Repeat introducer​

The ! character introduces a repeat command: !Pn C repeats sixel character C a total of Pn times. This provides simple run-length compression, which significantly reduces data size for images with horizontal runs of identical pixel columns.

Carriage return and line feed​

  • $ (Graphics Carriage Return): Moves the drawing position back to the left edge of the current sixel row, allowing overprinting with additional colors.
  • - (Graphics Line Feed): Advances the drawing position down by one sixel row (six pixels) and returns to the left edge.

Background handling​

The P2 parameter controls whether the terminal erases the background behind the image. When P2=1, pixels with value 0 in the sixel data are left unchanged (transparent). When P2=0 or P2=2, background pixels are filled with the terminal's default background color.

Examples​

# Draw a simple 1x6 red pixel column
# Define color 1 as red (RGB: 100,0,0), then draw a full sixel column
printf '\ePq#1;2;100;0;0#1~\e\\'

# A 10-pixel-wide horizontal red bar, 6 pixels tall
printf '\ePq#1;2;100;0;0#1!10~\e\\'

# Two-color image with raster attributes (10x12 pixels)
# Red top half, blue bottom half
printf '\ePq"1;1;10;12#1;2;100;0;0#1!10~-#2;2;0;0;100#2!10~\e\\'

Specifications​

SpecificationSection
VT330/VT340 Reference—

Terminal support​

TerminalSupportVersionNotes
Terminal Emulators
Alacritty✗No
Bobcat✓0.9.0InlineImages() enables Sixel, iTerm2, and Jexer graphics protocols. Present since initial commit (b893b96). Implemented via TerminalCtrl library.
contour✓v0.1.0Sixel graphics (DCS DECSIXEL) fully implemented via SixelParser.h/cpp, Functions.h line 623, Screen.cpp line 4060, with color palette support
foot✓1.4.0Requires tweak.sixel config option enabled
Ghostty✗NoNot implemented
iTerm2✓YesSixel graphics via DCS_SIXEL token and VT100SixelParser, requires VT level >= 300
Kitty✗NoUses kitty graphics protocol instead
Konsole✓YesFull sixel graphics implementation with color management and scrolling control
mintty✓YesSixel graphics fully implemented at src/termout.c:4092-4214 with dedicated parser in src/sixel.c
mlterm✓3.3.5
PuTTY✗No
Rio✓v0.1.12Experimental support in v0.1.11, initial support in v0.1.12
rxvt-unicode✗No
st✗No
terminology✗NoGraphics attributes recognized but marked TODO
VT100✗No
VTE✓YesRequires compile flag WITH_SIXEL
WezTerm✓20200620-160318-e00b076cSixel graphics protocol
Windows Terminal✓Yes
xterm✓xterm-294Sixel graphics (DCS Pn ; Pn ; Pn q). Requires compile-time --enable-sixel-graphics
xterm.js✓5.3.0Requires @xterm/addon-image addon
Multiplexers
cy✗No
GNU Screen✗No
tmux✓3.4Requires ENABLE_SIXEL compile flag
tuios✓v0.6.0Full sixel parsing with passthrough support
Zellij✓v0.31.0Full sixel support added in feat(terminal): sixel support PR

See also​