How to remove the placeholder text of input[type="date"]?

Viewed 7080

I have an input[type="date"] with min/max range. What I am trying to achieve is to hide the placeholder text displayed in any language as of dd/mm/yyyy. What have tried so far is adding the following CSS.

input[type="date"]:in-range::-webkit-datetime-edit-year-field, 
input[type="date"]:in-range::-webkit-datetime-edit-month-field, 
input[type="date"]:in-range::-webkit-datetime-edit-day-field {
    color: transparent;
}

But that doesn't produce the intended output, as I have a range validator on the element.

4 Answers

You could swap out placeholders using a ::before pseudo-element:

input[type="date"]::before {
  content: attr(placeholder);
  position: absolute;
  color: #999999;
}

input[type="date"] {
  color: #ffffff;
}

input[type="date"]:focus,
input[type="date"]:valid {
  color: #666666;
}

input[type="date"]:focus::before,
input[type="date"]:valid::before {
  content: "";
}
<input type="date" placeholder="Date" required>

The following works on Chrome. I am not sure about the other browsers. Safari doesn't seem to have an input of type date

const $input = $('input');
$input.on('input', function(){
    $input.addClass('focused')
});
input::-webkit-datetime-edit { 
    color: transparent;
    user-select: none;
}

.focused::-webkit-datetime-edit{ 
  color: #000; 
  user-select: none;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type='Date' />

Check out this Stack Overflow post for more information

try this:

.box{
  display: inline-block;
  background-color: red;
  position: relative
}
.box::after{
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  bottom: 2px;
  width: 80%;
  background-color: #fff;
}
<div class="box">
  <input type="date">
</div>

Placeholder?

input[type="date"]::before{
content: attr(placeholder);
position: absolute;
color: rgba(0,0,0,0);
}

input[type="date"]{color: rgba(0,0,0,1);}
Related