Skip to content

Login Form with Floating Labels

Clean pure CSS login card with animated floating labels, show/hide password, inline validation and a simulated sign-in state in vanilla JavaScript.

Also known as: login form floating label, animated sign in form, login card with password toggle, sign in page

Login Form with Floating Labels live demo

Open in new tab

Pure CSS code (HTML, CSS, JS)

A clean login card with animated floating labels, built with pure CSS and a small vanilla JavaScript file for validation, a show/hide password button and a simulated submit. Drop it into an app sign-in page, an admin panel, a member area or a checkout step.

How it works

The outer .lfl-wrap centers the white section.lfl-card on a soft mint background. Inside, the form.lfl-form holds two .lfl-field blocks. Each field contains an input.lfl-input, then its label.lfl-label, then a p.lfl-error message. The floating effect is CSS only: every input has placeholder=" ", so it matches :placeholder-shown while it is empty. The label sits centered inside the input, and when the input has :focus or is no longer :placeholder-shown, the adjacent + .lfl-label is translated up and scaled down. Because the label follows the input in the markup, the sibling selector works without any JavaScript.

Below the fields are a custom .lfl-check checkbox (a hidden native input styled through .lfl-check-box), a forgot-password link and the .lfl-submit button with a CSS .lfl-spinner.

The script finds every .lfl-card and wires up its form. It reveals the .lfl-reveal button and toggles the password input between password and text. Fields are validated on blur and re-checked on input once they show an error. On submit both fields are checked; the first invalid one receives focus. A valid form gets the .is-loading class, which shows the spinner and disables the button, and after a short setTimeout a success text appears in .lfl-message. Replace that timeout with a fetch() call to your login endpoint.

Customization

  • --lfl-accent and --lfl-accent-dark on .lfl-wrap: the brand color of the floating label, focus ring, checkbox, links and the button and its hover state.
  • --lfl-field-height: height of the inputs; the label start position and the password button follow it.
  • --lfl-radius: corner radius of the inputs and the submit button.
  • --lfl-error: color of error messages, invalid borders and invalid labels.
  • --lfl-speed: duration of the label float and other transitions.
  • MIN_PASSWORD and EMAIL_PATTERN at the top of script.js: the minimum password length and the email check.
  • --lfl-bg: the page background behind the card.

Use cases

  • Web app sign-in pages: users log in with floating labels, inline validation and a show or hide password button
  • Admin panels and dashboards: a clean centered card collects email and password with a remember-me checkbox
  • Member areas: a forgot-password link and loading spinner on submit make the form feel complete
  • Checkout steps: returning customers sign in with clear error messages before continuing

Accessibility

Every input has a real label connected through for, so the floating text is also the accessible name. Error paragraphs are linked with aria-describedby, and invalid fields get aria-invalid="true". The password button is a button with aria-pressed, aria-controls and a label that switches between Show password and Hide password. The .lfl-message paragraph uses role="status" so the result is announced. Inputs, the checkbox, links and buttons all show a visible green focus ring. With prefers-reduced-motion: reduce labels move without animation.

Usage notes

The form uses novalidate so the custom messages replace browser tooltips. Each copy on a page needs unique id values for inputs and error paragraphs.

Login Form with Floating Labels at a glance

Framework
Pure CSS
Code
HTML, CSS, JavaScript
JavaScript
Vanilla JavaScript, no jQuery
Dependencies
None
Layout
Responsive, works on mobile
Category
Login & Sign Up
License
Free for personal and commercial use

Questions about this template

Can I use the Login Form with Floating Labels code for free?

Yes. You can copy or download the code and use it in personal and commercial projects, including client work. No sign-up is needed. Reselling it as part of a component library or template collection is not allowed; see the license.

How do I add it to my website?

There is nothing to install. Paste the HTML where the component should appear, add the CSS to your stylesheet and load the JavaScript before the closing </body> tag. Download HTML gives you a complete page with everything already linked.

Does it need jQuery or a JavaScript framework?

No. The script is plain vanilla JavaScript, so it works without jQuery, React or Vue. You can still use the markup inside those frameworks.

Does it work on mobile?

Yes. The layout adapts to small screens. Use the Mobile and Tablet buttons above the live demo to check it at phone and tablet width.

Requirements

No dependencies. Pure HTML, CSS and JavaScript.

Login Form with Floating Labels – free Pure CSS login & sign up form template
Login Form with Floating Labels · free Pure CSS login & sign up form template

More Login & Sign Up

Forgot Password Form – free Tailwind CSS login & sign up form template

Forgot Password Form

Tailwind CSS forgot password form with email validation, loading spinner, check-your-inbox success state and a resend cooldown timer.

Signup Form with Validation – free Bootstrap 5 login & sign up form template

Signup Form with Validation

Bootstrap 5 signup form with live password rules, a strength meter, show/hide toggle, password confirmation and a required terms checkbox.

Split Login Page with Image – free Bootstrap 6 login & sign up form template

Split Login Page with Image

Bootstrap 6 split-screen login page with a full-height photo and testimonial on one side and a floating-label form with Google and Apple sign-in on the other.

Forgot Password Form – free Bootstrap 6 login & sign up form template

Forgot Password Form

Bootstrap 6 forgot password form with an email field, inline validation, a loading button, a stepper and a check-your-inbox success state with resend timer.

Login and Signup Tabs – free Bootstrap 6 login & sign up form template

Login and Signup Tabs

Bootstrap 6 card with segmented tabs that switch between a sign-in form and a create-account form, with validation, cross-links and simulated submits.

OTP Verification Form – free Bootstrap 6 login & sign up form template

OTP Verification Form

Bootstrap 6 two-factor verification card using the new OtpInput component, with grouped digit slots, auto-submit, attempt limit, resend countdown and trust-device switch.