Design placeholder css. How to change the color of the tooltip text in a placeholder using CSS styles? Task: make your own CSS style for placeholder

💖 Do you like it? Share the link with your friends
Typically the placeholder attribute on input and textarea is used to provide a call to action within those elements. In this note I will describe several options for styling the text of placeholders, as well as options for their animation

So, the text color of our placeholder can be changed using, for example, the following set of CSS rules:

::-webkit-input-placeholder ( color : #c0392b ;) ::-moz-placeholder ( color : #c0392b ;) /* Firefox 19+ */ :-moz-placeholder ( color : #c0392b ;) /* Firefox 18- */ :-ms-input-placeholder ( color : #c0392b ;)

The length of code for styling such a simple property is due to the lack of a common standard, and therefore each browser has implemented support for placeholder styling in its own way.

Also, not all are supported css properties. Here is a list of exactly supported properties:

font (and related)
background (and related)
color
word-spacing
letter-spacing
text-decoration
vertical-align
text-transform
line-height
text-indent
text-overflow
opacity

It also happens that the placeholder text “extends” the width of the input or textarea element (a common case for mobile devices). At the same time, it is automatically cut off unsightly.

A CSS property like text-overflow: ellipsis will help us fix this problem, which will add an aesthetic ellipsis to the cropped area of ​​the placeholder. In styles we write like this:

input [ placeholder ] ( text-overflow : ellipsis ;) input ::-moz-placeholder ( text-overflow : ellipsis ;) input :-moz-placeholder ( text-overflow : ellipsis ;) input :-ms-input-placeholder ( text-overflow : ellipsis ;)

To add even more aesthetics to our placeholders, it is possible to add the effect of hiding it when the corresponding element receives focus.

Some examples of such hiding with animation elements:

/* smooth change in placeholder transparency when focused */.input ::-webkit-input-placeholder ( opacity : 1 ; transition : opacity 0.3s ease ;) .input ::-moz-placeholder ( opacity : 1 ; transition : opacity 0.3s ease ;).input :-moz- placeholder (opacity: 1; transition: opacity 0.3s ease;).input:-ms-input-placeholder (opacity: 1; transition: opacity 0.3s ease;).input (opacity: 0; transition: opacity 0.3s ease; ) .input :focus::-moz-placeholder ( opacity : 0 ; transition : opacity 0.3s ease ;).input :focus:-moz-placeholder ( opacity : 0 ; transition : opacity 0.3s ease ;).input :focus :-ms-input-placeholder ( opacity : 0 ; transition : opacity 0.3s ease ;) /* shift the placeholder to the right when focused */.input ::-webkit-input-placeholder ( text-indent : 0px ; transition : text-indent 0.3s ease ;) .input ::-moz-placeholder ( text-indent : 0px ; transition : text-indent 0.3s ease ;).input :-moz-placeholder ( text-indent : 0px ; transition : text-indent 0.3s ease ;).input :-ms-input-placeholder ( text-indent : 0px ; transition : text-indent 0.3s ease ;).input :focus::-webkit-input-placeholder( text-indent : 500px ; transition : text-indent 0.3s ease ;).input :focus::-moz-placeholder ( text-indent : 500px ; transition : text-indent 0.3s ease ;).input :focus:- moz-placeholder ( text-indent : 500px ; transition : text-indent 0.3s ease ;) .input :focus:-ms-input-placeholder ( text-indent : 500px ; transition : text-indent 0.3s ease ;) /* shift the placeholder down when focused */.input ::-webkit-input-placeholder ( line-height : 20px ; transition : line-height 0.5s ease ;) .input ::-moz-placeholder ( line-height : 20px ; transition : line-height 0.5s ease ;).input :-moz-placeholder ( line-height : 20px ; transition : line-height 0.5s ease ;).input :-ms-input-placeholder ( line-height : 20px ; transition : line-height 0.5s ease ;).input :focus::-webkit-input-placeholder( line-height : 100px ; transition : line-height 0.5s ease ;).input :focus::-moz-placeholder ( line-height : 100px ; transition : line-height 0.5s ease ;).input :focus:- moz-placeholder ( line-height : 100px ; transition : line-height 0.5s ease ;).input :focus:-ms-input-placeholder ( line-height : 100px ; transition : line-height 0.5s ease ;)

Let's finish here.

If you are not familiar with the placeholder attribute, then let's explain a little what it is and where it is used. It is used in form input fields. The attribute displays a text in the input field, representing the role of a certain hint. Earlier on our website there was an example, with using javascript, positive side this method It's cross-browser compatible. Now let's talk about styling the placeholder attribute, which is used on input and textarea elements.
The input field code in our example will look something like this:

At the output we get the following field:

Now let's imagine that we need to style the placeholder, for this we need to write a set of rules in CSS:

::-webkit-input-placeholder ( color: #c1c1c1; ) ::-moz-placeholder ( color: #c1c1c1; ) /* Firefox 19+ */ :-moz-placeholder ( color: #c1c1c1; ) /* Firefox 18- */ :-ms-input-placeholder ( color: #c1c1c1; )

We get:

We cannot change all properties, but a list of most of them supported by modern browsers is given below:
font(also related properties)
background(also related properties)
color
word-spacing
letter-spacing
text-decoration
vertical-align
text-transform
line-height
text-indent
text-overflow
opacity

IN different browsers the rule is written differently, because While there is no single standard, this set of records continues to be relevant. In the IE browser, as well as firefox below version 18, placeholder is perceived as a pseudo-class, and in new browsers firefox, webkit and blink it is perceived as a pseudo-element.

Shortening text in placeholder
Sometimes tooltips can be so long that they cannot completely fit into the input field. For these purposes, you can also use additional properties that will allow you to shorten the placeholder text in the input field.

Input ( text-overflow:ellipsis; ) input::-moz-placeholder ( text-overflow:ellipsis; ) input:-moz-placeholder ( text-overflow:ellipsis; ) input:-ms-input-placeholder ( text-overflow :ellipsis; )

As a result, we get an input field with a placeholder like this:

Hide text when clicking on a field
By default, each browser interprets placeholder's response differently. In some browsers it is hidden immediately when you click on the field, in others it is hidden when there is at least one character in the input field. Let's make the text disappear when you click on the field, the same in all browsers.

:focus::-webkit-input-placeholder ( color: transparent; ) :focus::-moz-placeholder ( color: transparent; ) :focus:-moz-placeholder ( color: transparent; ) :focus:-ms-input -placeholder ( color: transparent; )

We get this action:

In an effort to reduce shape and reduce visual noise, designers tag

Badly

Fine

Styling: change placeholder color CSS

Change input field style with placeholder CSS

Badly

Placeholder effect for

The placeholder attribute only works for And