<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/invalid-sorta-sucks-but-there-s-an-alternative-now-xd3p5p53i" -->

---
title: :invalid sorta sucks... but there's an alternative now
description: CSS's classic :valid and :invalid pseudo-classes are awkward for form styling because they mark empty required fields as invalid before a user even interacts...
canonical: https://daily.dev/posts/invalid-sorta-sucks-but-there-s-an-alternative-now-xd3p5p53i
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: :invalid sorta sucks... but there's an alternative now | daily.dev
og:description: CSS's classic :valid and :invalid pseudo-classes are awkward for form styling because they mark empty required fields as invalid before a user even interacts...
og:url: https://daily.dev/posts/invalid-sorta-sucks-but-there-s-an-alternative-now-xd3p5p53i
og:image: https://api.daily.dev/og/posts/xd3P5P53I.png
og:image:alt: :invalid sorta sucks... but there's an alternative now
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# :invalid sorta sucks... but there's an alternative now

**[Kevin Powell](https://daily.dev/sources/kevinpowell)** · 1 min read · 38 upvotes · 4 comments

## Summary

CSS's classic :valid and :invalid pseudo-classes are awkward for form styling because they mark empty required fields as invalid before a user even interacts with them. The newer :user-valid and :user-invalid pseudo-classes fix this by only applying styles after the user has actually interacted with a field, combined with attributes like minlength and pattern for immediate client-side feedback. This is framed as a first line of defense for user experience, not a replacement for server-side validation.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://www.youtube.com/watch?v=3hVffhSpldo>

## Questions this post answers

### Why does :invalid in CSS mark an empty required input as invalid before the user types anything?

Because :invalid applies as soon as a field fails HTML validation constraints, including a required field being empty, regardless of whether the user has interacted with it yet. This makes forms appear to show errors prematurely. The newer :user-invalid and :user-valid pseudo-classes solve this by only applying styles after the user has actually interacted with the field, giving more sensible, delayed feedback.

_Developers refining form UX can compare validation pseudo-class behavior and edge cases on daily.dev._

### How can I make a password field show invalid styling until it meets a minimum length in plain CSS?

Add a minlength attribute to the input, such as minlength="8", and the browser will automatically mark the field as invalid via :user-invalid until enough characters are entered, without needing JavaScript. Combine this with a pattern attribute using a regex for stricter rules, like requiring at least one digit, to get further client-side validation feedback before form submission.

_Anyone building form validation logic can track CSS validation techniques like this on daily.dev._

## Community discussion

Top comments from developers on daily.dev.

**@theace92** · 1 upvotes

> Finally, it was so annoying and confusing, getting red errors on a form I didn’t even start filling up😂

**@fari\_yey** · 0 upvotes

> Doesn't writing the validations in the frontend would be threat to safety?

**@nosfair** · 0 upvotes

> "And if you're really adventurous you can add a regex...."
> Not so really x)

## Similar posts on daily.dev

- [Stop Using :invalid and :valid Pseudo-Classes. Use THIS Instead\!](https://daily.dev/posts/stop-using-invalid-and-valid-pseudo-classes-use-this-instead--6whqu4etf) · CSS Weekly · 23 upvotes · 4 comments
- [The CSS :has\(\) selector](https://daily.dev/posts/the-css-has-selector-csw5i3bag) · Flavio Copes · 20 upvotes · 1 comments
- [Practical CSS: Combining :has, :not, :only-child and :placeholder-shown pseudo-classes](https://daily.dev/posts/practical-css-combining-has-not-only-child-and-placeholder-shown-pseudo-classes-5gvvbff0w) · RUBYLAND · 7 upvotes · 0 comments
- [CSS \`n of\` Selectors for Conditional Validation – Frontend Masters Blog](https://daily.dev/posts/css-n-of-selectors-for-conditional-validation-frontend-masters-blog-wsa8a9f2p) · Frontend Masters · 16 upvotes · 1 comments
- [Chris’ Corner: Lovingly Esoteric CSS](https://daily.dev/posts/chris-corner-lovingly-esoteric-css-znejy2bhb) · CodePen · 20 upvotes · 0 comments

---

Tags: [#css](https://daily.dev/tags/css), [#html](https://daily.dev/tags/html)

[View this post on daily.dev](https://daily.dev/posts/invalid-sorta-sucks-but-there-s-an-alternative-now-xd3p5p53i)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":":invalid sorta sucks... but there's an alternative now","url":"https://daily.dev/posts/invalid-sorta-sucks-but-there-s-an-alternative-now-xd3p5p53i","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/invalid-sorta-sucks-but-there-s-an-alternative-now-xd3p5p53i"},"datePublished":"2026-09-10T13:21:21.808Z","dateModified":"2026-10-15T02:22:57.705Z","description":"CSS's classic :valid and :invalid pseudo-classes are awkward for form styling because they mark empty required fields as invalid before a user even interacts...","image":"https://i.ytimg.com/vi/3hVffhSpldo/sddefault.jpg","thumbnailUrl":"https://i.ytimg.com/vi/3hVffhSpldo/sddefault.jpg","isAccessibleForFree":true,"articleSection":"Kevin Powell","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Kevin Powell","logo":"https://media.daily.dev/image/upload/s--XK5Rf0kM--/f_auto/v1717745137/logos/kevinpowell","url":"https://daily.dev/sources/kevinpowell"},"commentCount":4,"discussionUrl":"https://daily.dev/posts/invalid-sorta-sucks-but-there-s-an-alternative-now-xd3p5p53i","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":38},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":4}],"keywords":"css,html","timeRequired":"PT1M","video":{"@type":"VideoObject","name":":invalid sorta sucks... but there's an alternative now","description":"CSS's classic :valid and :invalid pseudo-classes are awkward for form styling because they mark empty required fields as invalid before a user even interacts...","thumbnailUrl":"https://i.ytimg.com/vi/3hVffhSpldo/sddefault.jpg","uploadDate":"2026-09-10T13:21:21.808Z","duration":"PT1M","url":"https://api.daily.dev/r/xd3P5P53I","embedUrl":"https://www.youtube.com/embed/3hVffhSpldo"}}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Kevin Powell","item":"https://daily.dev/sources/kevinpowell"},{"@type":"ListItem","position":3,"name":":invalid sorta sucks... but there's an alternative now"}]}
{"@context":"https://schema.org","@type":"WebPage","@id":"https://daily.dev/posts/invalid-sorta-sucks-but-there-s-an-alternative-now-xd3p5p53i","comment":[{"@type":"Comment","text":"Finally, it was so annoying and confusing, getting red errors on a form I didn’t even start filling up😂","datePublished":"2026-09-10T15:59:34.472Z","url":"https://daily.dev/posts/xd3P5P53I#c-GEx0UyvIz","author":{"@type":"Person","name":"Theace","url":"https://daily.dev/theace92","image":"https://avatars.githubusercontent.com/u/211419990?v=4"},"interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":1}},{"@type":"Comment","text":"Doesn’t writing the validations in the frontend would be threat to safety?","datePublished":"2026-09-10T23:31:21.501Z","url":"https://daily.dev/posts/xd3P5P53I#c-XVc4361OS","author":{"@type":"Person","name":"Faris Shamsudeen","url":"https://daily.dev/fari_yey","image":"https://media.daily.dev/image/upload/s--SsPxK7VX--/f_auto/v1783512371/avatars/avatar_k4pQRbkDElGW5kPtlcybp?_a=BAMAMicg0"}},{"@type":"Comment","text":"“And if you’re really adventurous you can add a regex…”\nNot so really x)","datePublished":"2026-09-11T06:44:56.618Z","url":"https://daily.dev/posts/xd3P5P53I#c-IvzcureAq","author":{"@type":"Person","name":"Thialon","url":"https://daily.dev/nosfair","image":"https://avatars.githubusercontent.com/u/70216808?v=4"}}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/invalid-sorta-sucks-but-there-s-an-alternative-now-xd3p5p53i#faq","mainEntity":[{"@type":"Question","name":"Why does :invalid in CSS mark an empty required input as invalid before the user types anything?","acceptedAnswer":{"@type":"Answer","text":"Because :invalid applies as soon as a field fails HTML validation constraints, including a required field being empty, regardless of whether the user has interacted with it yet. This makes forms appear to show errors prematurely. The newer :user-invalid and :user-valid pseudo-classes solve this by only applying styles after the user has actually interacted with the field, giving more sensible, delayed feedback. Developers refining form UX can compare validation pseudo-class behavior and edge cases on daily.dev."}},{"@type":"Question","name":"How can I make a password field show invalid styling until it meets a minimum length in plain CSS?","acceptedAnswer":{"@type":"Answer","text":"Add a minlength attribute to the input, such as minlength=\"8\", and the browser will automatically mark the field as invalid via :user-invalid until enough characters are entered, without needing JavaScript. Combine this with a pattern attribute using a regex for stricter rules, like requiring at least one digit, to get further client-side validation feedback before form submission. Anyone building form validation logic can track CSS validation techniques like this on daily.dev."}}]}
```

