Open this example in the interactive library
Source code
<style>
.demo {
width: fit-content;
padding: 0.5rem 1rem;
}
</style>
<div class="demo">Width that follows content</div>
Width that follows content with native CSS. The preview includes a small shared demo stylesheet.
Open this example in the interactive library
<style>
.demo {
width: fit-content;
padding: 0.5rem 1rem;
}
</style>
<div class="demo">Width that follows content</div>