Creating a form with dynamic labels

The more modern a form, the more engaging it is. In this article, we'll look at how to create a form with dynamic labels that will increase the engagement of your forms and make your users want to fill them in.
•
Updated on August 14, 2026
•
2 min read
Believemy logo

The more modern a form is, the more engaging it is. In this article, let's see how to create dynamic labels for a form that will increase the engagement of your forms and make your users want to fill them out.

You can find the entire tutorial on our Instagram account.

 

Step 1

To create a form with dynamic labels, you need to have a form! So let's create an HTML form, wrapping each of our inputs in a input-form class.

HTML
<div class="input-form">
        <input type="email" name="email" id="email"
            placeholder=" " />
        <label for="email">Email Address</label>
    </div>
    
    <div class="input-form">
        <input type="password" name="password" id="password"
            placeholder=" " />
        <label for="password">Password</label>
    </div>
    
    <div class="submit-form">
        <button type="submit">Login</button>
    </div>

 

Step 2

Style the form and its email and password fields.

CSS
.input-form {
        display: flex;
        flex-direction: column-reverse;
        margin: 1.2em 0;
    }
    
    input, label, button {
        transition: .3s;
    }
    
    label {
        transform: translate(10px, -15px);
        cursor: text;
        transform-origin: left top;
        position: absolute;
    }
    
    input {
        padding: 10px;
        border: none; outline: none;
        border-bottom: 2px solid grey;
    }

We will directly use flexbox to center an input with its label, which will then allow us, thanks to the translate property, to position the label directly on the input.

 

Step 3

Now let's style the button of our form.

CSS
button {
        border: 0; padding: 10px 15px;
        cursor: pointer; color: white;
        background-color: #ff9234;
    }
    
    button:focus, button:hover {
        background-color: #d92027;
    }
    
    .submit-form {
        text-align: right;
    }

 

Step 4

Now we just need to add the dynamic behavior to the labels. For this, we will use the placeholders of our inputs, and specifically the default behavior they have with the browser.

We will hide the placeholder using opacity: 0, which means it is present but not displayed.

We use this trick to position the form label depending on whether the placeholder is completely hidden or not (which means the user has entered a value or has clicked on the input).

All this is achieved using the CSS sibling selector ~, which allows us to select the label that follows the input (and thus not select all labels).

CSS
input::placeholder {
        opacity: 0;
    }
    
    input:focus,
    input:not(:placeholder-shown) {
        border-bottom: 2px solid red;
    }
    
    input:not(:placeholder-shown) ~ label,
    input:focus ~ label {
        transform: translate(10px, -30px) scale(.8);
        padding-left: 0;
        color: black;
    }
Category: Developers

Share this article

Want to help us? Share this article on your networks or even better: on your site, in an article or in your newsletter.

Believemy logo
Comments (0)

You need to be logged in to comment on this article: log in or sign up.

Read next

Creating a glassmorphic connection form in HTML and CSS

In this article, we're going to create a form with a glassmorphic design. Modern effect guaranteed!

December 9, 2024

Creating animated presentation cards with JavaScript

Whether you're presenting the team behind your project or anything else, using animated presentation cards will give your page a successful finishing touch. Find out how in this article!

December 9, 2024

Animating a checkbox with CSS

Animating the checkboxes in your forms can greatly improve the experience your users have and will undeniably increase their desire to fill them in. A form that's more fun to fill in is a form that your users will fill in more often. In this article, we'll look at how to animate a checkbox using CSS!

December 9, 2024

Creating text with integrated background

If you're looking for a very modern and effective way to style your headlines, take a look at how using a background to style the colour of your text can be incredibly innovative.

December 9, 2024

Create a menu that spans the entire page using CSS

From time to time we have to ask our visitors which page they want to go to, by displaying the main sections of our website. This menu is often not very pleasant to use, so let's find out together in this article how to make it much more modern, with beautiful animations that will make your passers-by want to visit your site!

December 9, 2024

Creating a NEON button with CSS

Creating a button is one thing! But creating a button that your visitors want to click is something else entirely. In any case, this neon button will catch the eye of everyone who visits your pages.

December 9, 2024

Creating a cascading animation on text

For a slogan or for an animation on a very important page of your project, this very modern effect is also very easy to achieve. Let's take a look at how to do it in this article.

December 9, 2024

Create a very modern hover on a link

Here's an easy way to create a very modern hover on a link! There are lots of possible effects for buttons and links: the better they look, the more likely your users will be to click on them.

December 9, 2024

Become the solopreneur you dream of being.

First project, career change, business launch: access our courses, practice on real-world cases, and move forward with clear guidance.