Automatically add an asterisk to a required field

Very quick one this.

Add the class ‘required’ to your label

<label for="epass" class="required">Password</label>
<input type="password" required="required" id="epass" name="epass" class="form-control">

and define the class in your stylesheet

label.required::after {
content: '*';
margin-left: .4rem;
color: #dc3545;
}

hey presto!

Leave a Reply

Your email address will not be published. Required fields are marked *