Menu
CoddyTech

Content-Aware Empty States

Part of the Responsive UI Patterns section of Coddy's Tailwind CSS journey. Lesson 39 of 55.

A list can present different UI when it contains no items. empty:hidden hides an element only when it has no child elements or text nodes. Whitespace text can prevent this match, so the supplied behavior removes children completely when clearing the list.

<section class="group"><ul class="empty:hidden"></ul><p class="group-has-[li]:hidden">No library holds</p></section>

An empty-state paragraph is a sibling of the list, so it needs a shared ancestor condition. Mark the wrapper group and use group-has-[li]:hidden to hide the message when that wrapper contains a list item. The selector observes actual content rather than a manually maintained visual flag.

The example separates empty-list visibility from empty-message visibility. Supplied code owns adding and removing data; your utilities present those states. Test both transitions and more than one item so the populated layout is also useful.

challenge icon

Challenge

Medium

Hide the supplied list when it contains no child content. Show the empty-state paragraph only while its shared group has no list items. Adding a session must reveal the list and hide the message; clearing must restore the empty state. Keep the supplied add and clear behavior.

Preserve the supplied content, semantic elements and IDs. Edit the requested utility classes. Press Run preview after edits, then Check/Run code to grade the result. Supplied JavaScript is read-only.

Try it yourself

<!doctype html>
<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Interface workshop</title><link rel="stylesheet" href="./styles.css"></head><body>
<section class="group"><ul id="list" class="block"></ul><p id="empty" class="block">No saved sessions</p></section><button id="add">Add session</button><button id="clear">Clear sessions</button>
<script src="./controls.js"></script>
</body></html>
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Responsive UI Patterns