JSFiddle - React, Tailwind, and code Playground
HTML
<div class="test1">
<label for="test1">Test</label>
<input type="text" id="test1">
</div>
<div class="test2">
<label for="test2">Test</label>
<input type="text" id="test2">
</div>
CSS
div {margin-bottom: 2em;}
label {
border: 1px solid red;
padding: 0 .5em;
transition-property: font-size, padding;
transition-duration: 1s;
}
.test1:focus-within label {
padding: 0 1em;
font-size: .5em;
}
.test2 label {border-color: lime;}
.test2:focus-within label {
padding: 0 1.001em;
font-size: .5em;
}