<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/add-error-messages-to-your-css-wm6trmayj" -->

---
title: Add error messages to your CSS | daily.dev
description: You can use CSS alone to throw visible error messages when markup is misused, like a missing heading inside a card component. Using selectors that detect a...
canonical: https://daily.dev/posts/add-error-messages-to-your-css-wm6trmayj
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Add error messages to your CSS | daily.dev
og:description: You can use CSS alone to throw visible error messages when markup is misused, like a missing heading inside a card component. Using selectors that detect a...
og:url: https://daily.dev/posts/add-error-messages-to-your-css-wm6trmayj
og:image: https://api.daily.dev/og/posts/wM6TrMAYj.png
og:image:alt: Add error messages to your CSS
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.

# Add error messages to your CSS

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

## Summary

You can use CSS alone to throw visible error messages when markup is misused, like a missing heading inside a card component. Using selectors that detect a missing H2, H3 or H4, you apply an outline plus a text hint such as 'This card needs a heading' so the problem can be found when inspecting the element. The same kind of check could be used for missing alt text, dialogs without an aria-labelledby, or a layout container with too many children. The technique, credited to Heydon Pickering, works well for enforcing accessibility rules early, before dedicated tests run. The video ends with a plug for the creator's CSS Demystified course and a 32% Black Friday discount.

## Full article

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

## Questions this post answers

### How can I use CSS alone to show an error when an HTML element is missing a required child like a heading?

You write a CSS selector that targets the container when it lacks a matching H2, H3 or H4 child, then apply a visible outline plus a generated content hint, such as 'This card needs a heading', using CSS so the problem is visible directly in the browser when inspecting the element, before any automated test runs.

_Developers enforcing markup conventions across a team can track CSS patterns like this on daily.dev._

### What accessibility issues can be flagged using CSS selectors instead of automated tests?

CSS selectors can flag a dialog missing an aria-labelledby attribute, images missing alt text, or a card missing a heading element, by matching the absence of the required attribute or child and rendering an outline with a text hint. This enforces accessibility standards at the moment the markup is authored, rather than later during a dedicated accessibility testing phase.

_Anyone building accessibility checks into a workflow can follow CSS-based techniques like this on daily.dev._

## Community discussion

Top comments from developers on daily.dev.

**@markozakrajsekgeozs** · 4 upvotes

> ![GIF](https://static.klipy.com/ii/4493325008d34b7bf8cd6813cd5c1619/70/e0/EqShyX7xtKq0zvzaAA2K.gif)

**@itsmnthn** · 2 upvotes

> wait what?

**@harshitmanepally** · 1 upvotes

> That's new...

**@aliahmeddiyweb** · 0 upvotes

> The missing-heading example fits well because the outline and hint show up right in the inspector instead of waiting for a test run. One thing I wonder about is how the selectors hold up when a card wraps its heading in extra containers, since a direct-child check could flag false positives. Is this meant only for development builds, or would it also stay in production CSS?

## Similar posts on daily.dev

- [Lost, forgotten, and unfamiliar HTML](https://daily.dev/posts/lost-forgotten-and-unfamiliar-html-gzqwgcxgb) · thoughbot · 75 upvotes · 3 comments
- [Chris’ Corner: Check It B4 U Wreck It](https://daily.dev/posts/chris-corner-check-it-b4-u-wreck-it-0p1c5wdtd) · CodePen · 4 upvotes · 1 comments

---

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

[View this post on daily.dev](https://daily.dev/posts/add-error-messages-to-your-css-wm6trmayj)

```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":"Add error messages to your CSS","url":"https://daily.dev/posts/add-error-messages-to-your-css-wm6trmayj","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/add-error-messages-to-your-css-wm6trmayj"},"datePublished":"2026-11-18T14:16:41.249Z","dateModified":"2026-11-18T14:17:05.252Z","description":"You can use CSS alone to throw visible error messages when markup is misused, like a missing heading inside a card component. Using selectors that detect a...","image":"https://i.ytimg.com/vi/zXAXpMYnJV8/sddefault.jpg","thumbnailUrl":"https://i.ytimg.com/vi/zXAXpMYnJV8/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/add-error-messages-to-your-css-wm6trmayj","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":65},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":4}],"keywords":"css,html,accessibility","timeRequired":"PT4M","video":{"@type":"VideoObject","name":"Add error messages to your CSS","description":"You can use CSS alone to throw visible error messages when markup is misused, like a missing heading inside a card component. Using selectors that detect a...","thumbnailUrl":"https://i.ytimg.com/vi/zXAXpMYnJV8/sddefault.jpg","uploadDate":"2026-11-18T14:16:41.249Z","duration":"PT4M","url":"https://api.daily.dev/r/wM6TrMAYj","embedUrl":"https://www.youtube.com/embed/zXAXpMYnJV8"}}
{"@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":"Add error messages to your CSS"}]}
{"@context":"https://schema.org","@type":"WebPage","@id":"https://daily.dev/posts/add-error-messages-to-your-css-wm6trmayj","comment":[{"@type":"Comment","text":"","datePublished":"2026-11-19T08:34:19.004Z","url":"https://daily.dev/posts/wM6TrMAYj#c-uY0vrMkq1","author":{"@type":"Person","name":"Marko Zakrajsek","url":"https://daily.dev/markozakrajsekgeozs","image":"https://media.daily.dev/image/upload/s--slY3-STy--/f_auto/v1783585373/avatars/avatar_SbncGJHaRHf7KoebEkT1L?_a=BAMAMicg0"},"interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":4}},{"@type":"Comment","text":"wait what?","datePublished":"2026-11-19T12:15:04.107Z","url":"https://daily.dev/posts/wM6TrMAYj#c-M8xEfuNZD","author":{"@type":"Person","name":"Manthankumar Satani","url":"https://daily.dev/itsmnthn","image":"https://media.daily.dev/image/upload/s--XpFWj1ND--/f_auto/v1749054653/avatars/avatar_iBTDQoV5Y?_a=BAMClqUq0"},"interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":2}},{"@type":"Comment","text":"That’s new…","datePublished":"2026-11-20T03:35:57.067Z","url":"https://daily.dev/posts/wM6TrMAYj#c-eb6L264Wm","author":{"@type":"Person","name":"HARSHIT MANEPALLY","url":"https://daily.dev/harshitmanepally","image":"https://media.daily.dev/image/upload/s--O0TOmw4y--/f_auto/v1715772965/public/noProfile"},"interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":1}},{"@type":"Comment","text":"The missing-heading example fits well because the outline and hint show up right in the inspector instead of waiting for a test run. One thing I wonder about is how the selectors hold up when a card wraps its heading in extra containers, since a direct-child check could flag false positives. Is this meant only for development builds, or would it also stay in production CSS?","datePublished":"2026-11-20T11:56:39.286Z","url":"https://daily.dev/posts/wM6TrMAYj#c-zRQt70JNd","author":{"@type":"Person","name":"Ali Ahmed","url":"https://daily.dev/aliahmeddiyweb","image":"https://media.daily.dev/image/upload/s--b4sqNNv5--/f_auto,pg_1/v1792538576/avatars/avatar_lsiC0qqIxPUeSVlhCejTA?_a=BAMAMicg0"}}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/add-error-messages-to-your-css-wm6trmayj#faq","mainEntity":[{"@type":"Question","name":"How can I use CSS alone to show an error when an HTML element is missing a required child like a heading?","acceptedAnswer":{"@type":"Answer","text":"You write a CSS selector that targets the container when it lacks a matching H2, H3 or H4 child, then apply a visible outline plus a generated content hint, such as 'This card needs a heading', using CSS so the problem is visible directly in the browser when inspecting the element, before any automated test runs. Developers enforcing markup conventions across a team can track CSS patterns like this on daily.dev."}},{"@type":"Question","name":"What accessibility issues can be flagged using CSS selectors instead of automated tests?","acceptedAnswer":{"@type":"Answer","text":"CSS selectors can flag a dialog missing an aria-labelledby attribute, images missing alt text, or a card missing a heading element, by matching the absence of the required attribute or child and rendering an outline with a text hint. This enforces accessibility standards at the moment the markup is authored, rather than later during a dedicated accessibility testing phase. Anyone building accessibility checks into a workflow can follow CSS-based techniques like this on daily.dev."}}]}
```

