Conceal the calendar icon from the date-type HTML input field specifically on the Firefox

The situation at hand is quite straightforward.

<input type="date />

When viewed on Firefox (both desktop and mobile), it appears as follows:

https://i.stack.imgur.com/S2i0s.png

While the internet provides a solution specifically for Chrome:

input {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
}

input[type="date"]::-webkit-inner-spin-button,
input[type="date"]::-webkit-calendar-picker-indicator {
    display: none;
    -webkit-appearance: none;
}

This method does effectively conceal the calendar icon in Chrome, but proves unsuccessful on Firefox. Despite various attempts, I have yet to find a workaround that works on Firefox. The question remains whether such a solution is feasible. My goal is to hide the calendar icon. I understand that on desktop, clicking the calendar icon is necessary to access the date picker. However, this is not an issue for my mobile application.

Answer №1

If you're looking for a way to enhance your date picker, one interesting approach is to overlay a text input box on top of the date picker. Then, using the showPicker() method, you can trigger the date picker dialog box. By listening to the change event, you can update the text input with any changes made in the date picker. To improve the formatting of the date, consider leveraging the Intl.DateTimeFormat object for locale-specific settings.

Keep in mind that this solution may not work on platforms like CodePen or snippet editors due to security restrictions. You might need to test it on localhost or within your development environment instead.

const textInput = document.querySelector('.datepicker input[type="text"]');
const dateInput = document.querySelector('.datepicker input[type="date"]');
textInput.addEventListener('focus', (e) => {
  dateInput.showPicker();
});
dateInput.addEventListener('change', (e) => {
  textInput.value = dateInput.value; //You can utilize the Intl API for date formatting.
});
.datepicker {
  width: 8rem;
  position: relative;
}

.datepicker input {
  width: 100%;
  box-sizing: border-box;
}

.datepicker input[type='date'] {
  position: absolute;
  inset: 0;
  z-index: -1;
}
<div class='datepicker'>
  <input type=text placeholder='yyyy/mm/dd'>
  <input type=date>
</div>

Answer №2

Technique for concealing the default datepicker icon that is effective in both Chrome and Firefox.

Chrome

The native ::-webkit-calendar-picker-indicator selector is utilized.

Firefox and Other Non-Webkit Browsers

An additional after element is added to the wrapper as an overlay to hide the default icon. This method is exclusive to non-webkit browsers like Firefox.

Alternative Approaches Tested on Firefox

  • Tried editing the shadow DOM of the datepicker icon -> Deep selector approach did not yield results.
  • Attempted using a pseudo after element on the input instead of the wrapper -> Only functional in chrome but not in firefox.

.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;
  /* background: white; */
  position: absolute;
  content: "";
  right: 0px;
  top: 2px;
}

@supports not selector(::-webkit-calendar-picker-indicator) {
  .date-input-wrapper::before {
    display: block;
  }
}
<div class="date-input-wrapper">
  <input type="date">
</div>

Answer №3

In my experience, I found that using

<input type="text">
was actually the simplest approach compared to using
<input type="date">

It really depends on the specific use case, but for us, triggering our own date picker when the user interacted with the input field was the way to go. Plus, you have the flexibility to add your own icon as needed.

<input type="text">

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Ensuring text is perfectly centered within a div, regardless of its length

In the quest to center text of unknown length within a div, challenges arise. Constraints limit its size to a certain extent, making it unclear whether one or two lines will be needed. As such, traditional methods like line-height are not viable options. A ...

Styling for older versions of Internet Explorer (IE10 and earlier)

Could it be true that IE 10, 9, and others no longer support conditional statements? Is it also accurate to say that JQuery does not support the browser object above version 1.9? I am facing an issue with CSS rendering differently in Chrome and IE. A Goog ...

Prevent scrolling within input field

I have a text entry field with background images that separate each letter into its own box. Unfortunately, an issue arises when I reach the end of the input: the view automatically scrolls down because the cursor is positioned after the last letter enter ...

Is there a way to adjust the transparency of specific text when clicking on a different div?

How can I display a line of text when the "Contact Us" button is clicked on a practice website, similar to this: I have set the current opacity of the submit message to 0 so it is hidden, but is there a way to change its opacity to 1 when the submit link ...

Issues with Bootstrap's hamburger menu not functioning properly when clicked

Can't seem to get my hamburger button working. I've followed the bootstrap documentation and ensured that Bootstrap and jQuery are in the correct order, but still no luck. Any suggestions on what could be causing this issue? Are my links misplace ...

"Exploring the Dynamic Display of Ajax with HTML5 Canvas

This is my first time exploring the world of ajax, and I'm finding it quite challenging to grasp the concept and functionality. What I aim to achieve: I envision a scenario where I can freely draw on a canvas and simply hit save. Upon saving, the da ...

What is the best way to keep a header row in place while scrolling?

I am looking to keep the "top" row of the header fixed or stuck during page scrolling, while excluding the middle and bottom rows. I have already created a separate class for the top row in my header code: view image description ...

Display <div> exclusively when in @media print mode or when the user presses Ctrl+P

Looking for a way to create an HTML division using the div element that is only visible when the print function is used (Ctrl+P) and not visible in the regular page view. Unfortunately, I attempted the following method without success. Any advice or solut ...

Combination of written content and mathematical equations displayed on an HTML webpage

I've been tasked with creating something similar to the following on an HTML page: The math tag in HTML is not suitable because it struggles with handling the line break between parts "/begin()-/end()". To achieve the desired effect (succes ...

ReactJs CSS - This file type requires a specific loader for processing. There are currently no loaders configured to handle this file

I've noticed that this issue has been raised multiple times before. Despite going through all the questions, I still can't seem to resolve it. The transition from Typescript to Javascript went smoothly until I reached the implementation of CSS. U ...

The submission of the form is not functioning correctly when triggered by JavaScript using a button

My website was designed using a CSS/HTML framework that has been seamlessly integrated into an ASP.NET site. Within a ContentPlaceHolder, I have implemented a basic login form. The unique aspect is that I am utilizing the onclick event of an image to subm ...

A div element springs forth into a new window and seamlessly transitions back to its original position with fresh content

Most of us are familiar with Gmail chat, where you can pop out the chat window into a new window with its content, and then pop it back in to its original position. However, I encountered an issue while working on replicating this functionality. While I w ...

CSS: Centralizing a Div Element with Fluid Width

I've created a popup that appears in the center of the screen using: transform: translate(-50%, -50%); and position: absolute. However, I'm facing an issue where the width of the popup remains fixed instead of adjusting dynamically based on the c ...

changing background color smoothly in a short time without using JQuery

Check out this link for some code .back { margin: 20px; padding: 100px; background: yellow; font-size: 30px; } <div class="back"> Fun place to stay. We got a golf cart to see the rest of the island, but the ...

Identifying and categorizing flip switches with jQuery without relying on div elements

Is it possible to have two jQuery flip switches side by side, but only one visible if the screen is too narrow? I've tried assigning different classes to each switch for styling purposes, but it doesn't seem to work correctly. When I assign a cl ...

Using an HTML img tag without success, despite having the correct link

My HTML img tags are not working even though the link is correct. I have been attempting to resolve this issue for quite some time by researching multiple websites and trying various solutions, but unfortunately, nothing seems to be working. All I want i ...

Unable to apply inset box-shadow to image

I've added a box-shadow to my image. box-shadow: 0 0 10px RED inset However, the shadow is not showing up on the image. When I use Firebug to change the image path, I can see that the shadow is behind the image. How can I apply the shadow directly ...

Make the text stand out by highlighting it within a div using a striking blue

Currently, I am working with Angular2 and have incorporated a div element to display multiple lines of text. Positioned below the text is a button that, when clicked, should select the entirety of the text within the div (similar to selecting text manually ...

Applying custom CSS designs to images using Thymeleaf

Currently working on a web application using Spring MVC and Thymeleaf for templating. I'm struggling to figure out how to apply rules to an image, especially when using an external CSS file. I have tested code that works: page.html <a class="nav ...

Click on a div in AngularJS to be directed to a specific URL

I'm currently working on developing an Angular mobile app and I want to be able to navigate to a specific URL, like www.google.com, when a particular div is clicked. Unfortunately, I'm still new to the world of Angular and struggling to achieve t ...