Before gap worked in flexbox, spacing buttons meant a margin that had to be removed from the last one, plus a negative margin trick for wrapped rows. Now one property handles both directions.
.toolbar {
display: flex;
flex-wrap: wrap;
gap: 0.5rem 1rem;
}
The first value is the gap between rows, the second the gap between columns. With one value both are the same. The space only goes between items, never on the outside edge, so the toolbar lines up with the rest of the page without any correction.
When items wrap to a second line, the row gap keeps them apart vertically. With margins you would get double spacing or a margin on the last row that pushed the next element down.
All current browsers support it; Safari was last, in version 14.1. The odd thing is detection: @supports (gap: 1rem) returns true in browsers that only knew grid gap, so it cannot tell you whether flex gap works. In practice the old Safari versions without it are rare now, so I’d just use it.
Further reading: MDN: gap