:placeholder-shown
Quick Summary for :placeholder-shown
The :placeholder-shown CSS pseudo-class represents any <input> or <textarea> element that is currently displaying placeholder text.
Code Usage for :placeholder-shown
/* Selects any element with an active placeholder */ :placeholder-shown {   border: 2px solid silver; } 
More Details for :placeholder-shown

:placeholder-shown

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

/* Selects any element with an active placeholder */ :placeholder-shown {   border: 2px solid silver; } 

Syntax

:placeholder-shown

Examples

Basic example

This example applies special font and border styles when the placeholder is shown.

HTML
<input placeholder="Type something here!"> 
CSS
input {   border: 1px solid black;   padding: 3px; }  input:placeholder-shown {   border-color: teal;   color: purple;   font-style: italic; } 
Result

Overflowing text

When form fields are too small, placeholder text can get cropped in an undesirable way. You can use the text-overflow property to alter the way overflowing text is displayed.

HTML
<input id="input1" placeholder="Name, Rank, and Serial Number"> <br><br> <input id="input2" placeholder="Name, Rank, and Serial Number"> 
CSS
#input2:placeholder-shown {   text-overflow: ellipsis; } 
Result

Customized input field

The following example highlights the Branch and ID code fields with a custom style.

HTML
<form id="test">   <p>     <label for="name">Enter Student Name:</label>     <input id="name" placeholder="Student Name"/>   </p>   <p>     <label for="branch">Enter Student Branch:</label>     <input id="branch" placeholder="Student Branch"/>   </p>   <p>     <label for="sid">Enter Student ID:</label>     <input type="number" pattern="[0-9]{8}" title="8 digit ID" id="sid" class="studentid" placeholder="8 digit id"/>   </p>   <input type="submit"/> </form> 
CSS
input {   background-color: #E8E8E8;   color: black; }  input.studentid:placeholder-shown {   background-color: yellow;   color: red;   font-style: italic; } 
Result

Specifications

Specification
Selectors Level 4 # placeholder

See also

The ::placeholder pseudo-element styles the placeholder itself. Related HTML elements: <input>, <textarea> HTML forms Select your preferred language English (US)DeutschEspañolFrançais日本語Русский中文 (简体) Change language

No Items Found.

Add Comment
Type in a Nick Name here
 
Other Categories in CSS
css
Search CSS
Search CSS by entering your search text above.
Welcome

This is my test area for webdev. I keep a collection of code here, mostly for my reference. Also if i find a good link, i usually add it here and then forget about it. more...

You could also follow me on twitter. I have a couple of youtube channels if you want to see some video related content. RuneScape 3, Minecraft and also a coding channel here Web Dev.

If you found something useful or like my work, you can buy me a coffee here. Mmm Coffee. ☕

❤️👩‍💻🎮

🪦 2000 - 16 Oct 2022 - Boots
Random Quote
In this case my anchor this week becomes driving almost 2hrs outside of Atlanta to one of my favorite hard core gyms in the world.. MetroFlex aka The Dungeon. The gym owners turn the heat way up so it becomes a fun sweat box and the gym members just watch from afar and leave me alone. I happily drive myself long distances to find MY ANCHOR. Our anchor allows us to have balance, focus and be as productive as possible. And if you're in the middle of a heavy set and your headphones start to fall off your head, like mine did here.. well.. f*ck the headphones. Let em break and fall. You can always get a new pair, but the iron ain't ever gonna lift itself.
Unknown
Random CSS Property

mask-composite

The mask-composite CSS property represents a compositing operation used on the current mask layer with the mask layers below it.
mask-composite css reference