Checking if an input is empty with CSS
Published on:Is it possible to know if an input is empty with only CSS?
I had that question when I tried to make an autocomplete component for Learn JavaScript. Basically, I wanted to:
- Hide a dropdown if the input is empty
- Show the dropdown if the input is filled
<Image src="/assets/2018/empty-input-validation-css/autocomplete.gif" alt="autocomplete demo from https://learnjavascript.today" />
I found a way to do it. It's not perfect. There are a few nuances involved, but I want to share it with you.