Make form fields with floating labels
Type the fields you need, one per line, or paste your form. Get animated inputs and copy the HTML, CSS and JavaScript or a React component.
- Free, no sign-up
- Runs in your browser
- HTML, CSS, JS, React
Add (optional), (long) for a message box, Topic: Sales, Support for a choice, and | help text. Or paste your form's HTML, or .
No form handy? Try one:
How it works
- List your fields. One per line, or paste the HTML of a form you already have. A field named Email, Phone, Website, Date or Message gets the right kind of box by itself.
- See them working. The preview runs the exact code you copy. Click into a field and watch the label rise; press Show errors to see the shake and the messages, or Fill in to see the check marks.
- Pick the look. Outlined, filled or underline, the movement, when answers are checked, the colours and the button text.
- Check it. The page flags label movement that is too fast, too slow or mechanical, a shake that is too big, errors shown while people type, text that makes phones zoom, and colours that are hard to read, and fixes most in one press.
- Copy it. HTML, CSS and JavaScript together or apart, a React component, or a demo page to open in a browser. Set the form's
actionto where the answers go.
Questions
- How do I make a floating label with CSS?
- Put the label after the input inside a wrapper with
position: relative, place the label over the input withposition: absolute, and give the input a placeholder of a single space. Then move the label up withtransformwhen the input has focus or is no longer empty:input:focus + labelandinput:not(:placeholder-shown) + label. This page writes that CSS for your fields. - How fast should a floating label move?
- About 150 to 200 milliseconds with an ease-out curve, so it reads as a quick, settled movement. The focus border should change a little faster, in 100 to 150 milliseconds, and an error shake should last about 300 milliseconds and move 4 to 6 pixels.
- Are floating labels accessible?
- Yes, when the label is a real label element tied to its field, which is what this page writes. A placeholder is not a label: it disappears once people type. The code also ties each error message to its field, marks wrong fields with
aria-invalid, keeps text at 16 px so phones do not zoom, and stops all movement for people who ask for less motion. - Why do dates and choices keep their label up?
- A date box and a drop-down show their own text (a date format or the first choice), so a label sitting inside them would overlap it. Their labels stay in the raised position.
- Does it need a library?
- No. The script is plain JavaScript with no dependencies. It uses the browser's own checks for email, web address and number fields and adds the messages, the shake and the check marks. The React version runs the same script from a
useEffect. - Is anything I type uploaded?
- No. The fields, the preview and the code are all made in your browser. The optional AI step sends your description and the field list only when you press its button.