Guide: HTML5 Placeholder Attribute: Quick Guide
HTML5 has a new feature called Placeholder text that makes it easy to add text to input fields. This text is used to give users a hint as to what input is expected in that field. Once users start typing in the input field, the placeholder text disappears.
var myVar = “value”; console.log(myVar); This prints “value” on the console.
HTML5 is a newer technology that is more efficient than older technologies like HTML. This means that it can be used to create more efficient websites and applications.
The placeholder attribute is used to provide a placeholder value for an input field when the user has not provided a value. The placeholder attribute can be used in conjunction with the autofocus and autocomplete attributes. ..If we look at it in the browsers, the input should now have the gray text as seen below; However, if we look at it in Safari, it still looks like this:
The specification recommends that the placeholder attribute not be used as an alternative to a label, and that it be applied only to input types that require text, such as Text, password, search, email, text box and tel.
Radio and checkbox make no difference.
Placeholder and CSS
This is an article about how to format text for web browsers.
In both Safari and Chrome, we can change the placeholder text to green by using the following code: var color = ‘#ff0000’; document.getElementById(‘placeholder’).innerHTML = color; ..
The webkit-input-placeholder and -moz-placeholder are both placeholder values that can be used to input data. The webkit-input-placeholder is a color value that is used to indicate that the input should be displayed in a green color, while the -moz-placeholder is a color value that is used to indicate that the input should be displayed in a blue color.
However, keep in mind that the webkit-input-placeholder and: -moz-placeholder will only affect the text and cannot be written in parallel. ..
The webkit-input-placeholder is a placeholder for input that is used with thewebkit-input-placeholder. The input: -moz-placeholder is a placeholder for input that is used with themoz-input-placeholder.
This code will not work. ..
This feature is available in CSS3 with the introduction of the [placeholder] attribute selector.
This imports the green border into the document.
In this example, we select each entry that has the placeholder attribute and change the border to green.
Browser compatibility
HTML5 is not supported in older browsers and is currently only fully supported in Firefox 4+, Chrome 4+, Safari 5+, Opera 11.6 and Internet Explorer 10.
However, if we need to display the placeholder in older browsers, but can still use the placeholder attribute, we can use Polyfills. There are many Placeholder Polyfills beyond that, but in this example we’re going to use the PlaceMe.js; The PlaceMe.js polyfill provides a way to display placeholder text in older browsers without having to use a custom element or plugin.