Creating Floating Label/Placeholder for Input with React

Ilona D.
3 min readAug 10, 2018

To make the application fancy, front-end web developers usually visualize it using animations or other effects. And now I am going to explain one of the methods how to apply the most famous floating label effect to the input field with React.

The solutions based on the React project. You can set up one by running the following command in the console:

npx create-react-app my-app
cd my-app
npm start

Or create a React component in the existing project. In the following example, I am writing code in <App /> component and styling in App.css

Let’s start coding!

At first, in the <App /> I have added the constructor, where the state consists of initial inputValue and fieldActive properties. Step by step, in the constructor I am going to add bounded methods.

// App.jsimport React, { Component } from 'react';
import './App.css';
class App extends Component {
constructor() {
super();
this.state = {
inputValue: '',
fieldActive: false
}
}
this.updateInputValue = this.updateInputValue.bind(this);
this.activateField = this.activateField.bind(this);
this.disableFocus = this.disableFocus.bind(this);
}
...

--

--

Ilona D.

Building streams of passive income 🌱 I write about my favourite ways to achieve financial freedom 🕊