How to make pills with dynamic width, that could go across many rows?

How would I do this so that it also looks good on outlook, respecting padding and margins:

the equivalent of
<span style="display:inline-block; padding:x; margin:x;> P1</span> <span style="display:inline-block; padding:x; margin:x;> P2</span> <span style="display:inline-block; padding:x; margin:x;> P3 that is very long</span> <span style="display:inline-block; padding:x; margin:x;> P4 in a long list of Ps</span>