Is it possible to make input element fit-content with css?

Hi guys, I wonder if it is possible to make input element fit-content with CSS (I'm using tailwind css)? I tried, but it does not work
<div>
<input className="w-fit"/>
</div>
<div>
<input className="w-fit"/>
</div>
2 Replies
Chris Bolson
Chris Bolson•4mo ago
You could try the new field-sizing property (field-sizing-content in Tailwind 4) but this is not supported by all browsers yet.
MDN Web Docs
field-sizing - CSS: Cascading Style Sheets | MDN
The field-sizing CSS property enables you to control the sizing behavior of elements that are given a default preferred size, such as form control elements. This property enables you to override the default sizing behavior, allowing form controls to adjust in size to fit their contents.
noob
noobOP•4mo ago
It seems to work fine in my casebut this is not supported by all browsers yet 😭

Did you find this page helpful?