<style type="text/css"> input:invalid { background-color: #FFFF00; } </style> <form> <input type="text" pattern="\S{0,5}" /> </form>