Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to style placeholder attribute across all browsers? [duplicate]

Tags:

html

css

I have an element like this <input type="text" placeholder="lorem ipsum">.

How do I style thisplaceholder attribute in CSS, so that it works across all browsers?

like image 795
user1753622 Avatar asked Feb 06 '13 11:02

user1753622


People also ask

How do you give a placeholder style?

Use the ::placeholder pseudo-element to style your placeholder text in an <input> or <textarea> form element. Most modern browsers support this, but for older browsers, vendor prefixes will be required.

Can you style placeholder text?

The ::placeholder selector selects form elements with placeholder text, and let you style the placeholder text. The placeholder text is set with the placeholder attribute, which specifies a hint that describes the expected value of an input field.

How do I change placeholder position in CSS?

In most of the browsers, placeholder texts are usually aligned in left. The selector uses text-align property to set the text alignment in the placeholder. This selector can change browser to browser.

How do I change placeholders?

Select the placeholder, position the pointer over a sizing handle, and then drag the handle until the placeholder is the size that you want. Select the placeholder, and then drag it to its new location. Select the placeholder, click the Format tab, and then make the changes that you want.


1 Answers

Placeholder text in inputs has (in the browsers implementing it so far) a light gray color. To style it, you'll need vendor prefix CSS properties.

::-webkit-input-placeholder {
   color: red;
}

:-moz-placeholder { /* Firefox 18- */
   color: red;  
}

::-moz-placeholder {  /* Firefox 19+ */
   color: red;  
}

:-ms-input-placeholder {  
   color: red;  
}

You may also check this very similar question:

  • Change an HTML5 input's placeholder color with CSS
like image 170
Tom Sarduy Avatar answered Oct 18 '22 21:10

Tom Sarduy