Pixel art 9-slice UI panels in Godot 4 (without blurry or fat borders)
2 Nov 2026, 8:39 pm
Every game UI needs boxes: dialogue windows, inventory slots, buttons, tooltips. Drawing a new box for every size is a waste of time, and scaling one box up ruins it. The fix is 9-slice (Godot calls it nine-patch): draw one small panel, tell the engine where the borders are, and let it stretch only the parts that can stretch. The problem with plain scaling
Take a 24x24 panel with a 6 px border and scale it to a wide dialogue box. The border scales with it, so it gets fat on one axis and thin on the other, and the bevel looks wrong. How 9-slice works
Two vertical and two horizontal cut lines split the source into nine pieces: • 4 corners: never stretched. • 4 edges: stretched along one axis only (top and bottom horizontally, left and right vertically). • 1 center: stretched both ways (or tiled).
The cut lines are just four numbers, the margins from each side. For the panel above they are all 6. Drawing a panel that slices well
A few rules that save a round trip back to the editor: • Keep the border the same width all round unless you really want different margins. Equal margins mean one number in Godot. • Keep the edges uniform. Anything in the edge strip gets stretched, so a rivet or a notch in the middle of the top edge will smear. Put details in the corners. • Keep the center flat (or a pattern that tiles cleanly). A gradient in the center will stretch into a blur. • Draw at the size it will be used, not bigger. For a 320x180 game, a 24x24 or 32x32 panel is plenty.
I draw mine in a free browser pixel art editor and export a PNG; any editor works as long as it saves without anti-aliasing. Making it crisp in Godot 4
Before slicing, make sure Godot isn't filtering your pixels: Project Settings → Rendering → Textures → Canvas Textures → Default Texture Filter = Nearest. Without this every UI texture is blurred. Display → Window → Stretch → Mode = canvas_items (or viewport) with your base resolution, and Scale Mode = integer so the whole UI scales by whole numbers. If text or panels jitter when moving, enable Rendering → 2D → Snap 2D Transforms to Pixel. Option 1: NinePatchRect
NinePatchRect is a Control node that draws a texture as nine pieces. It's the quickest way to get a resizable box. Add a NinePatchRect to your UI scene and set Texture to your panel PNG. Under Patch Margin, set Left, Top, Right and Bottom to 6 (your border width). Resize the node. Corners stay put, edges and center stretch.
Axis Stretch controls how edges and center fill: Stretch (default), Tile, or Tile Fit. Use Tile when your edge has a repeating pattern (a rope, a chain, stitched leather); Tile Fit adjusts the tile slightly so it ends cleanly.
NinePatchRect doesn't hold children nicely by itself; put it behind a MarginContainer (margins equal to the patch margins) when you need content inside. Option 2: StyleBoxTexture (for buttons and themes)
For anything built from Godot's Control nodes (Button, PanelContainer, LineEdit, Tooltip), use a StyleBoxTexture instead.…
https://dev.to/hoanganhlam/pixel-art-9-slice-ui-panels-in-godot-4-without-blurry-or-fat-borders-ma