Skip to content

Instantly share code, notes, and snippets.

@elfacht
Created January 5, 2022 11:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elfacht/558d56ea48f32d7d75aad2e452aaa464 to your computer and use it in GitHub Desktop.
Save elfacht/558d56ea48f32d7d75aad2e452aaa464 to your computer and use it in GitHub Desktop.
Check empty inputs with CSS
input {
width: 100%;
font: inherit;
padding: 0.25em 0.5em;
border: 0.125em solid hsl(30, 76%, 10%);
outline: none;
}
/* Show red borders when filled, but invalid */
input:not(:placeholder-shown) {
border-color: hsl(0, 76%, 50%);;
}
/* Show green borders when valid */
input:valid {
border-color: hsl(120, 76%, 50%);
}
<div class="input">
<label for="input" >Label </label>
<input type="text" name="input" id="input" required placeholder="Type something in here" pattern=".*\S.*">
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment