Codecademy Forums

Can we set a placeholder value for the input field?

Question

In the context of this exercise, can we set a placeholder value for the input field?

Answer

Yes, there are a few ways you can do this. The first method was covered in the previous exercise, which is done by setting an initial value to the state. This method places some actual text in the field, so a user would have to edit it. For instance,

this.state = { userInput: 'Some initial text' };

Another method is to utilize the input HTML element’s attribute placeholder, which sets some placeholder text in the field, but unlike the previous method, it will not be an actual value. It can be done like so, by adding the parameter,

<input placeholder="placeholder text" />

6 Likes