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

WordPress Security Checklist for UK Businesses (2026)

Your WordPress site went down last Tuesday at 2pm. You don’t know why, and neither does the person who built it three years ago. By the time it comes back, you’d missed four enquiries and your email had bounced for six hours. This happens to UK businesses every week. WordPress powers around 40% of all … Continued

Isev Team
Isev Team June 10th, 2026
Do businesses need video marketing?

If you aren’t using video, you’re missing out on a target audience discovery and engagement channel. These days, social media platforms tend to push video far more than static posts, so it’s easy to get overlooked without it. The same goes for your website: most people would rather watch a quick video than scroll through … Continued

Isev Team
Isev Team April 29th, 2026
AI Optimisation: An in-depth guide to AEO, LLMO, and GEO

AI optimisation is a digital process that requires websites to be read and understood by AI models. If the content on your site is optimised, AI may quote, reference and link back to your website.

Leanne March 5th, 2026
Magento 2 Guide: Attributes & Attribute Sets

Here we’re going to look at an important, but sometimes overlooked part of Magento – Attributes. You are able to create custom attributes and use these improve the information you show for a product and offer more website navigation options, helping to improve user experience, but before we get into that…. What are attributes? Attributes … Continued

Tim February 16th, 2026