January 7,2021

Using CSS4’s validity pseudo-classes to make forms epic

by Mitch

css4-classes

This week there has been numerous articles flying around regarding selectors that may be included within CSS4.

One such article was Louis Lazaris’ which really nicely explained some of the new selectors which may be available and how we can use them.

The selectors that really stood out to me were the validity pseudo-classes. These selectors will allow us to change the display of elements depending on whether they are valid or invalid.

Why is this so exciting you ask?

It should be mentioned that this isn’t a solution for validating submitted values for form elements ( you will still need JavaScript or your server side code to do that ).

But this is perfect for helping visitors see that they are not forgetting to add values to inputs, or to even check that the type of value they are adding is right before they hit that submit button.

For instance check out the example below.

The element will be invalid until there is a value, and that value appears to be an email address.

How to use

<input type="text" placeholder="name" required>

The required attribute on the above element help the user to see this cannot be empty, but using these new pseudo-selectors we can improve the UX even more.

/* this will display until the input value is valid */
input[ type=text ]:invalid {
 border-color: red;
}
/* once a value is found, show the user */
input[ type=text ]:valid {
 border-color: green;
}

Once the input has a value, the border colour will change to green.

When using an email input field, the user will need to add a value and for that value to appear to be an email address before it becomes valid.

<input type="email" placeholder="email address" required>

How widely is this supported?

This is supported in the latest versions of IE, Firefox and Chrome, but Safari provides only partial support. Check out CanIUse.com for more information.

Continue Reading

What is ecommerce? A Complete Guide for 2025

Ecommerce has completely changed the way we consume and sell. From browsing products on websites and apps to buying directly through social media, selling online makes it easier than ever for businesses to reach customers without the high costs of a traditional store. We’ll explore what e-commerce is, how it works, the different types of … Continued

Isev Team
Isev Team September 2nd, 2025
PPC in 2025: Why Your Business Should Consider Using Google Ads

Google Ads remains a powerful and constantly evolving solution. It's an great tool for businesses that want to be seen, stay competitive, and achieve tangible growth

Isev Team
Isev Team August 6th, 2025
Editing Magento 2 Mega Menu with Venustheme

To edit your the Mega Menu, using the Venustheme extension in Magento 2 To get to the menu, you will need to go to the lef thand navigation and Venustheme > Manage menus. Select menu you want to edit. If you have a separate mobile and desktop menu, they will both need to be updated. … Continued

Isev Team
Isev Team June 23rd, 2025
Upgrading Magento 2.4.5 to 2.4.6

Magento is one of the most powerful and flexible ecommerce platforms available. For store owners currently on Magento 2.4.4, moving to version 2.4.6 is more than just a recommended upgrade—it’s a necessary step to keep your business safe, compliant, and competitive in an evolving digital environment.

Isev Team
Isev Team June 11th, 2025