Hide calendar icon in date-type HTML input on Firefox – Html

by
Ali Hasan
css-loader html

The Problem:

How to hide the calendar icon in the date-type HTML input field on Firefox desktop and mobile browsers? Using the provided CSS code works on Chrome, but not on Firefox. Is it even possible to hide the calendar icon on Firefox?

The Solutions:

Solution 1: Using a Text Input Overlay

This solution involves overlaying a text input box over the date input and triggering the date picker dialog box when the text input gains focus. Here’s a step-by-step explanation:

  1. Create a Text Input Box: Define a text input element with an appropriate placeholder (e.g., ‘yyyy/mm/dd’) to display the desired date format.

  2. Position the Text Input: Position the text input absolutely within a container and set its inset property to 0 to overlap the date input completely.

  3. Create a Date Input: Place a regular date input element beneath the text input. Position it absolutely with a high z-index to ensure it’s always behind the text input.

  4. Handle Focus Event: Add an event listener to the text input to trigger the date picker dialog box when the text input gains focus. This is done using the showPicker() method.

  5. Handle Change Event: Add an event listener to the date input to update the text input with the selected date value whenever the date selection changes. This ensures that the displayed date in the text input reflects the actual date chosen.

This solution allows you to hide the calendar icon from the date input while providing a text-based interface for date selection.

Solution 2: Use text input

The simplest solution is to replace the `<input type="date">` with a text input using `<input type="text">`. This disables the calendar icon since it is only available for date inputs. However, this approach may not be suitable if the desired behavior is to have a date picker appear when the user interacts with the input.

Solution 3: Hide datepicker icon using wrapper overlay

This approach hides the native datepicker icon in both Chrome and Firefox by utilizing a combination of the following techniques:

  1. Chrome:

    In Chrome, the native ::-webkit-calendar-picker-indicator pseudo-element is utilized to hide the icon.

  2. Firefox:

    For non-webkit browsers like Firefox, an after element is added to the wrapper as an overlay to conceal the native icon. This overlay is not used in Chrome.

Here’s a code snippet demonstrating the implementation:

<div class="date-input-wrapper">
  <input type="date">
</div>
.date-input-wrapper {
  width: fit-content;
}

input {
  width: 100%;
}

 input[type=date]::-webkit-calendar-picker-indicator {
   visibility: hidden;
}

.date-input-wrapper {
  position: relative;
}

.date-input-wrapper::after {
  display: none;
  width: 17px;
  height: 16px;
  background: red;
  position: absolute;
  content: "";
  right: 0px;
  top: 2px;
}

@supports not selector(::-webkit-calendar-picker-indicator) {
  .date-input-wrapper::before {
    display: block;
  }
}

Q&A

How To Hide calendar icon in date-type HTML input on Firefox?

Overlay a text input box on top of the date picker then use the showPicker() method to trigger the date picker dialog box.

Can I just use instead of ?

Yes, you can use instead of .

Is there a CSS method that can work on both Chrome and Firefox?

Yes, you can use CSS to hide the native datepicker icon in both Chrome and Firefox.

Video Explanation:

The following video, titled "How to remove placeholder from input type date - YouTube", provides additional insights and in-depth exploration related to the topics discussed in this post.

Play video

How to add icon in placeholder. Rahana Islam•24K views · 5:54. Go to ... Input date and time in HTML and Javascript || (flatpickr.js). RavenJS ...