Skip navigation
Fixing a button with CSS and Math.
0:00 / 1:03

Fixing a button with CSS and Math.

Haz

@diegohaz14K followers

Visit on X
1,468 likesDownloadOriginal post

53,252 views

Fixing a button with CSS and Math.

30 Comments

Comments from the original post on X (Twitter)

  • Haz's profile picture

    @diegohaz

    Quick (and related) shameless plug: Ariakit Plus is 30% off for Black Friday for the next few days: It'll include styled component recipes for all these design posts, to copy-paste or use with agents via MCP. Planned to launch by the end of the year.

    8 likes

  • Ciprian Popescu's profile picture

    @cipriangb

    This will soon be a lost art, with AI hardcoding everything... And it's a shame.

    6 likes

  • Haz's profile picture

    @diegohaz

    This is still useful, but you have to teach your AI agents to do it. Otherwise they will default to `px-4 py-2`

    2 likes

  • Haz's profile picture

    @diegohaz

    In other words, I'm not posting code because I think people will write it themselves. I'm just giving them context so they can ask their agents to do it.

    2 likes

  • Sundry Mill's profile picture

    @SundryMill

    Years of nudging that arrow 1px left by eye and calling it optical alignment. Nice to finally have the formula

    2 likes

  • Haz's profile picture

    @diegohaz

    Yeah, I can totally relate. At some point I was like "there should be a formula for that" Luckily, CSS already had the lh and cap units by the time I thought about it. Otherwise, it wouldn't have been possible 😅

  • passerby0x16's profile picture

    @passerby0x16

    Great animation to visualize what those settings do! I wonder though if you consider A != B here an imbalance or not?

    2 likes

  • Haz's profile picture

    @diegohaz

    Text and 1lh icons should be treated differently. It's easier to see why this is more balanced with fully rounded buttons (the first one is using the original post's math):

    15 likes

  • passerby0x16's profile picture

    @passerby0x16

    Well explained, and indeed the first one just instantly clicks

  • Roboki's profile picture

    @ItsRoboki

    Great tutorial that would explain why buttons sometimes look great and sometimes they don't

    1 like

  • Georgii Bukharov's profile picture

    @souljorje

    U gotta have PhD in math to do some CSS nowadays

  • Watt dem een sin Uhl's profile picture

    @fancyPT

    Stop overthinking

  • Haz's profile picture

    @diegohaz

    I overthought so you can underthink. You’re welcome.

    2 likes

  • DDMSS's profile picture

    @DDMSS1

    That's beautiful, and exactly why I both love and hate CSS

  • Edu Calvo's profile picture

    @educalvolpz

    the margin-inline trick on the icon is the clever part, keeps text, icon and icon-only buttons all driven by the same --py

  • otter's profile picture

    @meaningmean_

    appreciate that!

  • 🦜's profile picture

    @popuguy_

    Это то, с чем у меня сейчас трудности, с формированием подхода создания компонентов независящих от окружения, т.е контейнеры, а компоненты без isDesktop, isMobile props, и size=xl,lg,md и так далее

  • vijay singh's profile picture

    @dprophecyguy

    man how did you arrive at this ?

  • Haz's profile picture

    @diegohaz

    I like CSS and I like math 😅

    2 likes

  • jayden メ𝟶's profile picture

    @NotCellium

    text-box properties can remove that leading on the text in your buttons if you’d rather just work with padding