Skip to documentation content

9-Slice Boxes Guide

How GRUB 2 pixmap boxes work, the 9 required filenames, pixel alignment rules, shadows, and common slicing mistakes.

How GRUB 2 9-slice boxes work

GRUB 2 cannot draw rounded rectangles, borders, or drop shadows procedurally. Instead, boot_menu, progress_bar, terminal-box, and selected menu highlights use styled pixmap boxes built from up to 9 separate PNG files arranged in a 3×3 grid.

When a widget grows or shrinks, GRUB keeps the four corners at their exact pixel dimensions and stretches only the edges and center piece. Explore the scaling rules interactively below:

Visual reference preview only
276px
164px
menu_nw.png
Expected filename menu_nw.png
GRUB 2 scaling behaviorFixed corner (never stretched)

Keep all four corner PNGs crisp with matching corner radius and shadow margin.

Interactive 9-slice pixmap box anatomy in GNU GRUB 2 (preview for visual reference only).

Naming convention (*_*.png)

In theme.txt, you pass a wildcard pattern such as "menu_*.png". GRUB automatically resolves the 9 compass suffixes relative to the theme root:

Suffix Position Scaling Axis Optional?
_nw.png Top-left corner None (fixed) Optional (transparent if omitted)
_n.png Top edge Stretched horizontally (X) Optional
_ne.png Top-right corner None (fixed) Optional
_w.png Left edge Stretched vertically (Y) Optional
_c.png Center fill Stretched in X and Y Recommended
_e.png Right edge Stretched vertically (Y) Optional
_sw.png Bottom-left corner None (fixed) Optional
_s.png Bottom edge Stretched horizontally (X) Optional
_se.png Bottom-right corner None (fixed) Optional
theme.txt
        
          
            + boot_menu {
          
              left = 50%-260
          
              top = 50%-180
          
              width = 520
          
              height = 360
          
              menu_pixmap_style = "menu_*.png"
          
              selected_item_pixmap_style = "select_*.png"
          
            }
          
        
      

Step-by-step guide to creating clean 9-slices

  1. Design on an integer pixel grid: Start with a small card canvas (for example 64×64 px) containing your border, corner radius, fill, and any outer shadow or glow.
  2. Choose slice insets larger than your radius + shadow: If your corner radius is 10 px and your outer shadow spreads 8 px, slice at least 18–20 px from each edge so no curve or shadow gradient leaks into the stretched edge slices.
  3. Verify edge-to-corner alignment:
    • _n.png must have the exact same height as _nw.png and _ne.png.
    • _s.png must have the exact same height as _sw.png and _se.png.
    • _w.png must have the exact same width as _nw.png and _sw.png.
    • _e.png must have the exact same width as _ne.png and _se.png.
  4. Keep center and edges lightweight: If the fill is solid or semi-transparent without texture, _c.png only needs to be 4×4 px (or even 1×1 px).
  5. Export all 9 files as 8-bit RGBA PNG: See Image Formats & PNG Color Depth to avoid 16-bit load failures.

How 9-slice thickness affects inner padding

GRUB 2 draws a widget's inner content inside the central _c.png region. That means the widths of _w.png and _e.png and the heights of _n.png and _s.png act as built-in padding!

  • If your selected_item_pixmap_style uses 16 px tall _n.png and _s.png slices, make sure item_height in boot_menu is tall enough (>= 16 + 16 + font_height) so the text is never clipped.
  • For minimal underline or left-accent highlights, you can omit unused slices (for instance, ship only select_w.png and select_c.png for a crisp left bar highlight).