I would like to insert a descriptive text inside an input element that disappers when the user click on it.
I know it is a very common trick, but I do not know how to do that..
What is the simplest/better solution?
A way around this is to place the input inside another element, such as a <div> and emulate the look of an input field. Removing the <input> 's border and outline, we place them on the <div> . We can now add a text label to the input field. While any element can be used, a <label> element is the best choice.
Using table cell attribute in display property: Make a label inside a div and give the display property. To make the input element and span as equally placed use table-cell attribute in those tags. This attribute makes the element behaves a td element.
When using input elements of “type” checkbox and radio the label element should always be placed after the <input> element. Label elements should be associate with the following form elements: Input type = "text"
The <label> tag is used to specify a label for an <input> element of a form. It adds a label to a form control such as text, email, password, textarea etc. It toggles the control when a user clicks on a text within the <label> element.
If you're using HTML5, you can use the placeholder
attribute.
<input type="text" name="user" placeholder="Username">
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With