Easy and smart way to add “required” css class to form field labels

Undoubtedly, this is the easiest way to add a red asterisk (*) sign to a required field label in a form.

Here’s HTML part of the form.


And here’s the CSS part

Obviously “content” is the property that adds a string (i.e. *) after label.

Easy and smart way to add “required” css class to form field labels

You can read more about content property here.

Leave a Reply

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