Difference between :placeholder-shown and ::placeholder in CSS

The :placeholder-shown Pseudo-class

A CSS pseudo-class is a selector that selects elements that are in a specific state.

The :placeholder-shown pseudo-class selects any <input> or <textarea> element that is currently displayin…


This content originally appeared on DEV Community and was authored by Sandra Lewis

The :placeholder-shown Pseudo-class

A CSS pseudo-class is a selector that selects elements that are in a specific state.

The :placeholder-shown pseudo-class selects any <input> or <textarea> element that is currently displaying a placeholder text.

HTML

<input type="text" placeholder="Search university">

CSS

input[type=text] {
  width: 100px;
}

:placeholder-shown {
   text-overflow: ellipsis;
}

Result

Alt Text

The ::placeholder Pseudo-element

A CSS pseudo-element is a selector that lets you style a specific part of an element.

The ::placeholder pseudo-element can be used to style the placeholder text in an <input> or <textarea> element.

HTML

<input type="email" placeholder="Enter your email">

CSS

::placeholder {
   color: red;
}

Result

Alt Text

Thanks for giving it a read.

Happy Coding!


This content originally appeared on DEV Community and was authored by Sandra Lewis


Print Share Comment Cite Upload Translate Updates
APA

Sandra Lewis | Sciencx (2021-05-09T13:21:09+00:00) Difference between :placeholder-shown and ::placeholder in CSS. Retrieved from https://www.scien.cx/2021/05/09/difference-between-placeholder-shown-and-placeholder-in-css/

MLA
" » Difference between :placeholder-shown and ::placeholder in CSS." Sandra Lewis | Sciencx - Sunday May 9, 2021, https://www.scien.cx/2021/05/09/difference-between-placeholder-shown-and-placeholder-in-css/
HARVARD
Sandra Lewis | Sciencx Sunday May 9, 2021 » Difference between :placeholder-shown and ::placeholder in CSS., viewed ,<https://www.scien.cx/2021/05/09/difference-between-placeholder-shown-and-placeholder-in-css/>
VANCOUVER
Sandra Lewis | Sciencx - » Difference between :placeholder-shown and ::placeholder in CSS. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/05/09/difference-between-placeholder-shown-and-placeholder-in-css/
CHICAGO
" » Difference between :placeholder-shown and ::placeholder in CSS." Sandra Lewis | Sciencx - Accessed . https://www.scien.cx/2021/05/09/difference-between-placeholder-shown-and-placeholder-in-css/
IEEE
" » Difference between :placeholder-shown and ::placeholder in CSS." Sandra Lewis | Sciencx [Online]. Available: https://www.scien.cx/2021/05/09/difference-between-placeholder-shown-and-placeholder-in-css/. [Accessed: ]
rf:citation
» Difference between :placeholder-shown and ::placeholder in CSS | Sandra Lewis | Sciencx | https://www.scien.cx/2021/05/09/difference-between-placeholder-shown-and-placeholder-in-css/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.