DEV Community

Benjamin Wehner for Etribes Connect GmbH

Posted on

5

Label as input-placeholder and autofill

Everybody knows the fancy input placeholders that will move out of the input-field if you set the focus on it.

Input with label as placeholder

So it's relatively easy:

input:focus ~ label {/* ..do stuff*/}
Enter fullscreen mode Exit fullscreen mode
<input id="user"><label for="user">Input</label>
Enter fullscreen mode Exit fullscreen mode

The problem

If your page is ssl encrypted and the user has used
your login-form before. The browsers will autofill your form.

But they wont really fill your form. Its just a preview.
And they will do it on page-load they dont need the focus.

If you use javascript to check if the form-value is filled, it will appear empty.

And in the end, the filled in preview-data, will overlap your label-/placeholder.

Input with overlapping text

The Solution

To prevent this, you could use a construct like the following.
So you will check for the placeholder. You should also set the color of the input-placeholder to transparent.

input:not(:placeholder-shown) ~ label,
input:focus ~ label {/* ..do stuff*/}
Enter fullscreen mode Exit fullscreen mode
<input placeholder="input" id="user"><label for="user">Input</label>
Enter fullscreen mode Exit fullscreen mode

Hope that will help somebody. :D

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more