{
  "id": "terminal-osc/11",
  "family": "terminal-osc",
  "slug": "11",
  "title": "OSC 11 — Set / query default background color",
  "summary": "OSC 11 ; spec ST sets the terminal's default background color; OSC 11 ; ? ST queries it, replied as OSC 11 ; rgb:RRRR/GGGG/BBBB ST. Programs query OSC 11 to detect a light-vs-dark background and adapt their colors. Mirrors OSC 10 for the foreground.",
  "kind": "control-sequence",
  "aliases": [
    "set background color",
    "query background",
    "OSC 11",
    "ESC ] 11",
    "default bg",
    "detect dark mode"
  ],
  "status": "de-facto",
  "verification": "verified",
  "tier": "B",
  "source_url": "https://invisible-island.net/xterm/ctlseqs/ctlseqs.html",
  "source_version": "xterm ctlseqs, patch #410, 2026/04/19",
  "retrieved_date": "2026-05-29",
  "attribution": [
    {
      "claim_ref": "#summary",
      "source_url": "https://invisible-island.net/xterm/ctlseqs/ctlseqs.html",
      "source_version": "xterm patch #410, 2026/04/19",
      "note": "xterm ctlseqs: Ps = 1 1 -> Change VT100 text background color to Pt; '?' queries and the terminal reports the color back."
    }
  ],
  "see_also": [
    "terminal-osc/10",
    "terminal-osc/12",
    "terminal-osc/4"
  ],
  "ext_type": "terminal-escape@1",
  "ext": {
    "csi_or_osc": "OSC",
    "command_number": 11,
    "frame": {
      "introducer_7bit": "\u001b]",
      "introducer_7bit_readable": "ESC ] (0x1B 0x5D)",
      "introducer_8bit": "",
      "introducer_8bit_readable": "0x9D (single-byte OSC, 8-bit C1)",
      "note": "OSC frame per ECMA-48 5th ed. 1991 / ISO 6429. Command number 11 is an xterm/vendor convention with no formal registry."
    },
    "terminator": "ST|BEL",
    "terminator_detail": {
      "canonical_ST_7bit": "\u001b\\",
      "canonical_ST_7bit_readable": "ESC \\ (0x1B 0x5C)",
      "canonical_ST_8bit": "",
      "canonical_ST_8bit_readable": "0x9C (single-byte ST, 8-bit C1)",
      "alt_BEL": "\u0007",
      "alt_BEL_readable": "BEL (0x07)",
      "note": "ECMA-48 mandates ST; xterm and most modern terminals also accept BEL. Emit ST, accept both."
    },
    "params": [
      {
        "id": "set",
        "anchor": "#set",
        "name": "Set default background",
        "meaning": "OSC 11 ; spec ST sets the default background color (X11 name or rgb:/# form).",
        "required": true,
        "byte_sequence_ST": "\u001b]11;#000000\u001b\\",
        "byte_sequence_ST_readable": "ESC ] 1 1 ; # 0 0 0 0 0 0 ESC \\   ==  \\x1b]11;#000000\\x1b\\\\   (black background)",
        "byte_sequence_BEL": "\u001b]11;#000000\u0007",
        "byte_sequence_BEL_readable": "ESC ] 1 1 ; # 0 0 0 0 0 0 BEL   ==  \\x1b]11;#000000\\x07",
        "subparams": []
      },
      {
        "id": "query",
        "anchor": "#query",
        "name": "Query default background",
        "meaning": "OSC 11 ; ? ST asks for the current background; reply OSC 11 ; rgb:RRRR/GGGG/BBBB ST. The de-facto way to detect light vs dark themes.",
        "required": false,
        "byte_sequence_ST": "\u001b]11;?\u001b\\",
        "byte_sequence_ST_readable": "ESC ] 1 1 ; ? ESC \\   ==  \\x1b]11;?\\x1b\\\\   (query; reply \\x1b]11;rgb:0000/0000/0000\\x1b\\\\)",
        "byte_sequence_BEL": "\u001b]11;?\u0007",
        "byte_sequence_BEL_readable": "ESC ] 1 1 ; ? BEL   ==  \\x1b]11;?\\x07",
        "subparams": []
      }
    ],
    "gotchas": [
      "Querying OSC 11 is the de-facto light/dark detection: parse the reply's RGB and compute luminance. Always read with a timeout — some terminals/multiplexers don't answer.",
      "Reply is 16-bit-per-channel rgb:RRRR/GGGG/BBBB.",
      "OSC 10/11/12 consume successive parameters; sending 'OSC 11 ; bg ST' sets only the background.",
      "tmux/screen may swallow or proxy OSC 11 queries; passthrough config can be required for the reply to reach your program.",
      "Reset with OSC 111 (reset background) and restore on exit."
    ],
    "v1_smoke_test": {
      "asserts": "OSC 11 set and query forms render as byte-exact OSC strings; query carries the literal '?' used for light/dark detection.",
      "behavioral_conformance": "deferred to v2."
    }
  },
  "updated": "2026-05-29T00:00:00Z"
}
