Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove default text/placeholder present in html5 input element of type=date

Tags:

html

date

css

I am using html input element with type as date,

<input type="date"> 

When I use above element it creates a default date format i.e. mm/dd/yyyy text within that input element. How do I remove this default text?

I tried adding below style on my page but it is hiding the selected date value as well,

input[type=date]::-webkit-datetime-edit-text {     -webkit-appearance: none;     display: none; } input[type=date]::-webkit-datetime-edit-month-field{     -webkit-appearance: none;     display: none; } input[type=date]::-webkit-datetime-edit-day-field {     -webkit-appearance: none;     display: none; } input[type=date]::-webkit-datetime-edit-year-field {     -webkit-appearance: none;     display: none; } 
like image 290
Sreekanth Avatar asked Feb 24 '15 00:02

Sreekanth


People also ask

How do I change the default placeholder date in input type?

The placeholder attribute does not work with the input type Date, so place any value as a placeholder in the input type Date. You can use the onfocus=”(this. type='date') inside the input filed.

How do I disable input type date?

< p >To disable the date field, double click the "Disable" button. // Set disabled = true.

What does the html5 placeholder attribute provide on a text input?

The placeholder attribute specifies a short hint that describes the expected value of an input field (e.g. a sample value or a short description of the expected format). The short hint is displayed in the input field before the user enters a value.


2 Answers

::-webkit-datetime-edit-year-field:not([aria-valuenow]), ::-webkit-datetime-edit-month-field:not([aria-valuenow]), ::-webkit-datetime-edit-day-field:not([aria-valuenow]) {     color: transparent; } 
like image 86
Steffi A. Avatar answered Sep 20 '22 19:09

Steffi A.


Possible option

HTML:

<input type='date' required> 

CSS:

input[type=date]:required:invalid::-webkit-datetime-edit {     color: transparent; } input[type=date]:focus::-webkit-datetime-edit {     color: black !important; } 
like image 35
Kenneth Avatar answered Sep 17 '22 19:09

Kenneth