:placeholder-shown
Widely availableSince 202097% of users
A selector that matches an <input> or <textarea> element ONLY while it is currently showing its placeholder text (meaning the field is empty).
What's modern
From web-features, MDN's browser data and our snippets, checked dailyModernIn every major browser since January 2020. Widely available since July 2022.
The old way and the modern waySee the snippet: Floating labels without JavaScript →
Old way 10 lines
/* .filled class toggled by JS on every keystroke */
.field.filled label,
.field input:focus + label {
translate: 0 -1.4rem;
font-size: .75rem;
}
/* JS: toggle .filled on input */
input.addEventListener('input', () => {
input.closest('.field').classList.toggle('filled', input.value.length > 0);
});Modern 6 lines
input:not(:placeholder-shown) + label,
input:focus + label {
translate: 0 -1.4rem;
font-size: .75rem;
}
/* no .filled class, no JS */See how modern your own CSS is.Check your CSS →
Quick example
input:placeholder-shown {
/* Adds a subtle border until the user starts typing */
border: 1px dashed #ccc;
background-color: #fafafa;
}:placeholder-shown browser support
BaselineWidely availableThis feature is well established and works across many devices and browser versions. It has been available across browsers since 2020.Safe to use without fallbacks.
Usage97%of people can use this3% use a browser without it.
Browsers
47+
51+
9+
79+Mobile
47+Android
51+Android
9+iOS