Regrettably, HTML inputs and JavaScript do not natively support a data type for duration. The <input type="time">
element is designed for inputting a time of the day and may display AM/PM selectors based on your location.
Your best approach would be to utilize a text input field and employ JavaScript events to automatically insert :
while disregarding invalid entries. Utilizing the pattern attribute can also aid in this process. Ensure to convert the value into a number before utilizing it within JavaScript. Below is a starting point for you:
let durationIn = document.getElementById("duration-input");
let resultP = document.getElementById("output");
durationIn.addEventListener("change", function (e) {
resultP.textContent = "";
durationIn.checkValidity();
});
durationIn.addEventListener("invalid", function (e) {
resultP.textContent = "Invalid input";
});
input:invalid:not(:focus) { background: red; }
<input id="duration-input" type="text" required pattern="[0-9]{2}:[0-9]{2}:[0-9]{2}:[0-9]{2}" value="00:00:00:00" title="Enter a duration in hh:mm:ss:ms format">
<p id="output"></p>
There are likely numerous open-source libraries available that offer pre-built widgets for handling durations.