Set width of <span> programmatically

Is it possible to set the width of an html tag like <span> programmatically?

Fixed values of the width of <span> I can set e.g. with

<span style="display: inline-block; width: 150px;">

I want to set the width instead of 150px to another value dependent of the needed space for content.

<span [style.width]=foo></span>
Change the value of ‘foo’ in your .ts file!#style-binding

It works! Thank you very much for your fast response.