isBatak/labs
Experiments
MasonryLay out items of different heights in columns, each one placed in the shortest column or in order.Wheel pickerPick from a vertical list with native scroll snapping, keyboard support and optional looping.Text flipCycle through words or phrases in place, flipping the next one in as the current one flips out.
All prototypes
SponsorClaim this seat
DS
InstallationAdd @isbatak/panda-ds to Panda CSS and copy in the components you need.ComponentsArk UI components styled with the design system recipes.StylesStyle props that extend the design system, like concentric radius.
SponsorClaim this seat
Tools
SourceryHold a hotkey, point at anything on the page and click to open the line of JSX that rendered it in your editor.Panda TurbopackPanda CSS v2 for Next.js on Turbopack, without the Panda CLI. Codegen, CSS and build-time class names from one config wrapper.IkonaTurn a folder of SVG icons into one sprite with typed icon names. The icons on this site are built with it.CaliperDraw specs over live UI: dimension lines, hatching and outlines that measure the real component. Headless Ark UI parts, with a Panda CSS recipe.
All tools
SponsorClaim this seat
Blog

isBatak/labs · MIT licensed, built in the open.

ExperimentsBlocksDesign systemIconsToolsBlogSponsorGitHub

Blog

Optical alignment for button icons

Pull the icon by a fixed amount, and to its ink only when nothing lines up with it.

November 20, 2026·4 min read

A button with an icon and a label usually gets the same padding on both sides. On paper that's symmetric. On screen the icon side looks wider, because the icon's box is wider than the icon you see.

16px
16px
4px
20px
16px
Icon boxEmpty space inside the icon
The md Button with a bookmark icon. Equal padding puts 16px before the icon's box, but the glyph starts about 4px inside it. The recipe pulls the icon out by a fixed 4px, close to that empty space.

Pull by a fixed amount#

Text has the same problem in a smaller dose. Letters have side bearings, but at button sizes they're under a pixel, so the label's box is close enough to its ink. The icon is the outlier, so the icon is what moves.

The fix is a negative margin on the icon, roughly the size of the empty space in its box. The padding stays the same on both sides, so the button still has one --button-padding-x, and the content inside it moves 4px toward the edge.

equalno pull
optical4px pull
The same two buttons at 2×. The top one looks heavier on the left; the bottom one looks centered.

The pull is a fixed value per size, the same for every icon. It gets each icon close to its ink, and keeps every label in a stack of buttons on one line. Perfect optical alignment shows why that matters.

How the Button recipe does it#

StartIcon and EndIcon mark the icon with data-icon-start and data-icon-end. The recipe targets those with the _iconStart and _iconEnd conditions and pulls the icon out with the iconPullStart and iconPullEnd utilities. Each takes a spacing token and turns it into a negative margin:

md: {
  h: "10",
  textStyle: "sm",
  "--button-padding-x": "spacing.4",
  gap: "2",
  _icon: { width: "5", height: "5" },
  _iconStart: { iconPullStart: "1" },
  _iconEnd: { iconPullEnd: "1" },
},

The margin also adds --icon-offset, which is zero unless you set it. More on that below, and the Icon pull page covers the utilities in full.

That's why icons are slots rather than plain children. The recipe can't tell a leading icon from a trailing one by looking at an svg, and a button with only an icon must not get the offset at all.

<Button variant="outline">
  <StartIcon asChild>
    <Icon name="bookmark" />
  </StartIcon>
  Save article
</Button>

End icons#

The trailing side is the same problem mirrored. The arrow's tip sits about 4px inside its box, so _iconEnd pulls the icon 4px toward the edge.

40px
16px
12px
16px
16px
EndIcon mirrors it: the arrow's tip sits about 4px inside its box, so the recipe pulls the box 4px toward the edge and the ink lands 16px from it.

Every size#

The pull scales with the icon: about a fifth of its size, rounded to the spacing scale. Small buttons use a 2px pull, the rest 4px.

SizePaddingIconPull
2xs8px14px2px
xs10px16px2px
sm14px16px2px
md16px20px4px
lg20px20px4px
xl20px20px4px
2xl28px24px4px

The rounded pull lands a pixel or so off any one glyph's ink. That's fine; what reads as wrong is the 4px to 5px an uncorrected icon adds.

Perfect optical alignment#

Sometimes an icon has nothing to line up with. Then it can go all the way to its ink, and that takes knowing exactly where the ink is.

Icons come with air#

Icons are drawn on a fixed grid, 24 units for ours, and the glyph rarely fills it. The bookmark's sides sit at 6 and 18 with a 1.5 unit stroke, so its ink starts at 5.25. That's 21.875% of the box left empty on each side. The arrow's tip stops 4.25 units short of the end.

5.25
4.25
The bookmark and the arrow on our 24-unit grid. The hatched band is the 2-unit trim area every glyph stays out of; the keylines inside it are the shapes glyphs are drawn to. The bookmark's ink starts 5.25 units in, the arrow's tip 4.25 units from the end.

In the md Button the icon is 20px, so the bookmark starts 4.375px inside its box. Without a pull the eye reads 20.375px on the left against 16px on the right. The fixed 4px pull brings that to 16.375px, 0.375px past the label side. The arrow's tip sits 3.542px inside its box, so the same pull leaves it at 15.542px, 0.458px short.

Why it isn't the default#

Each glyph has a different amount of air. The bookmark starts 5.25 units in, the share icon 2.25, the settings hexagon 1.25: 4.375px, 1.875px and 1.042px in a 20px box. Stack a few left-aligned buttons, as in a menu or an action sheet, and pulling each icon to its own ink moves each label by a different amount. The labels stop sharing an edge, and a ragged column of text is easier to see than icons up to 3.333px apart.

Three md Buttons stacked, left aligned. Pull each icon to its own ink and the icons line up, but the labels drift. With the fixed pull the labels share one edge and the icons' ink lands up to 3.333px apart.

So going to the ink is opt-in, for an icon with nothing to line up with.

Symbols in a Kbd#

A keyboard shortcut is a small box with a symbol or two and a letter, and it sits alone in a menu or a tooltip. Its padding is only a few pixels, so the air inside a glyph is a large share of it: at 16px, the command symbol starts 2.833px inside its box, next to 4px of padding.

Here a pull per icon is worth it. StartIcon and EndIcon take an offset, added to the recipe's own pull through --icon-offset. Kbd has no pull of its own, so the offset is the whole correction. Give it in em and it follows the icon at every Kbd size: the command glyph's 4.25 units of air are 0.177em.

<Kbd>
  <StartIcon asChild offset="0.177em">
    <Icon name="command" />
  </StartIcon>
  K
</Kbd>
K
6.833px
4px
P
6.443px
4px
6.833px
8.167px
Shortcut keys at 3×. Each symbol carries its own air: the command and option glyphs start 4.25 units into their box, the shift arrow 3.664, the up arrow ends 6.25 units short. An offset in em pulls each one to its ink at every Kbd size.

A single Button#

The same prop works in a Button that stands alone, such as a single call to action. The md Button pulls 4px and the bookmark has 4.375px of air, so offset="0.375px" lands it on its ink. A negative offset pulls less, for a glyph with less air than the pull assumes.

Rules#

  • Pad the button evenly. Correct the icon, not the padding.
  • Pull a start icon out with a negative start margin, and an end icon with a negative end margin.
  • Size the pull to the empty space in the icon grid: about a fifth of the icon size.
  • Keep the pull the same for every icon at a size, so stacked labels share an edge.
  • Pull a single icon to its ink with offset only when nothing lines up with it, like a symbol in a Kbd.
  • Don't pull an icon-only button. It's centered, so the empty space is even on both sides.
All posts