html input how to format placeholder code example

Example 1: html select placeholder

Placeholder attribute does not exist for the  element is using the disabled and selected attributes with the HTML5 hidden global attribute.
  

Example 2: css style placeholder

input::-webkit-input-placeholder {/* Chrome/Opera/Safari/Edge */
	/*styles here*/
}

input::-ms-input-placeholder { /* Microsoft Edge */
   /*styles here*/
}

input:-ms-input-placeholder {/* IE 10+ */
	/*styles here*/
}

input::-moz-placeholder {/* Firefox 19+ */
	opacity: 1; /*Firefox by default has an opacity object that usually is ideal to reset so it matches webkit*/
	/*styles here*/
}

input:-moz-placeholder {/* Firefox 18- */
	opacity: 1; /*Firefox by default has an opacity object that usually is ideal to reset so it matches webkit*/
	/*styles here*/
}

input::placeholder {
	/*styles here*/
}

Example 3: jtextfield placeholder

txtField = new JTextField();
txtField.setForeground(Color.LIGHT_GRAY);
txtField.addFocusListener(new FocusAdapter() {
			@Override
			public void focusGained(FocusEvent e) {
				if(txtField.getText().trim().equals("Hello World")) {
					txtField.setText("");
				}
				
				txtField.setForeground(Color.BLACK);
			}
			@Override
			public void focusLost(FocusEvent e) {
				if(txtField.getText().trim().equals("")) {
					txtField.setText("Hello World");
				}
				
				txtField.setForeground(Color.LIGHT_GRAY);
			}
		});

Example 4: html css placeholder input font-size

Placeholder text will automatically inherit the font family and font size of the regular input text, but you may be in a situation where you want to change the placeholder text color. You can accomplish that with the ::placeholder pseudo-element.

Tags:

Misc Example