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

Display the text above overlapping div elements

I need a design where one div overlaps another, but the text inside the overlapping div must still be visible. <div class='box1'> <div class='sendAbove'> This message should remain visible in this div </div> ...

As each new line is added, the span text starts from the bottom and moves up by one line

I am facing an issue where I want a span to start from the top and expand as the text length increases, but it is currently starting from the bottom and moving upwards. See the image below for reference: View Image <div style="width:70%;margin-left: ...

working with html data in a bootstrap modal using javascript

Utilizing an id, I pass data to a bootstrap modal and link that id with stored data. $("#fruit").html($(this).data("fruit")); In addition, I am appending data to the bootstrap modal $('#mymodal').find('.modal-body').append('< ...

Is it possible to modify a website's CSS permanently using just the browser?

Is there a way to make changes to CSS in a large project using Firefox's built-in developer tools and have them saved permanently? I've been trying to edit the style sheets, but couldn't locate the specific property I needed. Since I can&apo ...

Interactive carousel featuring responsive image zoom effect on hover

Utilizing the flickity carousel, I have crafted an example which can be found at this link to codepen.io. Here is the CSS code that has been implemented: CSS .image-hoover { overflow: hidden; } .image-hoover img { -moz-transform: scale(1.02); -web ...

The positioning and floating of two divs are set to fixed without using percentage width, however, the functionality is not

Apologies for my poor English writing :) I am attempting to float two divs side by side in a fixed position, without using percentages. This code works well on most browsers but is not compatible with IE 6. HTML <div class="right"></div> < ...

Customizing CSS for Various Browser Sizes

I have a query regarding window-dependent CSS. It seems to be a common issue, but I am facing some difficulties with it on Wordpress. I am currently using the script recommended by Nettuts. My goal is to apply different CSS styles based on the user's ...

Find the ID of the clicked table row using HTML and JavaScript

Currently, I am trying to implement this code snippet: <td align="center"> <div class="dropdown"> <button onclick="DropdownShow(this)" class="btn btn-default glyphicon glyphicon-picture"></button> <div id="@TableR ...

Using jQuery to apply a CSS class to a chosen radio button

How can I dynamically add a CSS class to a radio button based on its selection? $("input[type=radio][name=align]").on('change', function() { var radVal = $("input[type=radio][name=align]").val(); if (radVal == 'center') { $(" ...

Switching the typeface within the content data

Recently, I incorporated this code: <div data-content="Reach" class="main-image"> along with the following CSS styling: .main-image:before { content: attr(data-content); I am now wondering if there is a method to adjust the font size and ...

I am searching for answers to solve issues related to a JSON file

I am currently working on a tool that searches for matches in an input field by comparing the keywords entered by the user with a JSON. During my testing phase, I focused on using a single API that provides information about different countries and fortun ...

What is the best method for retaining just a specific portion of HTML code within Webbrowser VB.Net?

As a web developer accustomed to working with websites, I am now faced with the task of creating a Windows-based program using VB.net. In this project, I have two domains - A and B, where B is embedded within A using an iframe element. The code snippet for ...

Developing a sliding menu with AngularJS

Currently, I am developing an AngularJS application. One of the features I am working on involves having a menu at the top of my page that, when an item is selected, will slide down to reveal content specific to that selection in the same area as the menu. ...

To determine whether a variable is an integer in PHP

Is there a more elegant solution to this problem? if( $_POST['id'] != (integer)$_POST['id'] ) echo 'not an integer'; I attempted if( !is_int($_POST['id']) ) However, I encountered issues with is_int(). This ...

Tips for adding images using v-for in Vue 3

Having some trouble creating a set of images using a v-for loop, as it seems to be not recognizing the variables inside the tag. The picture is broken and the alt attribute just shows me {{ item.alt }}. Here is my HTML: <section class="our-technolo ...

What steps should be taken to enlarge a checkbox within a table?

I need help with resizing the checkboxes that are inside a table. When I try using width:###px; height:###px;, it only seems to make them smaller, not bigger. Even when I set the values higher than the default size, the checkboxes stay the same while the d ...

Remove identical options from the dropdown menu

After hard-coding and adding items to the dropdown list for team size, such as 1, 2, 3, I am encountering an issue when loading it for editing or updating. Duplicate values are appearing in the list: 1 1 2 3 4... How can I remove these duplicate value ...

Maximizing the functionality of PHP switch to create clickable list items

I have successfully created a simple switch for my website, but I am encountering an issue with clickable list items. The concept is that when I click on any of the list items, the switch should display the appropriate greeting (whether it's Night or ...

Tips for styling React Material-UI list items with fontAwesome icons and Tailwind.css

I would like to align the text of my list items to the left. Additionally, I want all the icons to be the same size as the envelope icon used in Gmail list item. Currently, my code looks like this: https://i.stack.imgur.com/9LNOs.png How can I achieve th ...

How can you verify a phone number input?

I have a phone number field in my form that needs validation. The conditions are that the numbers may be 8 digits or 10 digits long, otherwise an error message should be displayed. Is this code snippet correct? <input class="form-control" name="phone_n ...