CodexBloom - Programming Q&A Platform

advanced patterns of `<input type='number'>` with min and max attributes in Safari 16.2

👀 Views: 873 đŸ’Ŧ Answers: 1 📅 Created: 2025-07-18
html safari input HTML

I'm stuck on something that should probably be simple. I'm working with an scenario with an `<input type='number'>` field in a form where I have set both `min` and `max` attributes. The field works as expected in Chrome and Firefox, but in Safari 16.2, it allows values outside the specified range, specifically when using the up and down arrow keys for incrementing and decrementing the value. The HTML code looks like this: ```html <form> <label for='quantity'>Quantity:</label> <input type='number' id='quantity' name='quantity' min='1' max='10' value='5'> <input type='submit' value='Submit'> </form> ``` I have tried using JavaScript to enforce the boundaries, but that feels like a workaround rather than a proper solution. The following script is what I implemented: ```javascript const quantityInput = document.getElementById('quantity'); quantityInput.addEventListener('input', function() { if (this.value < 1) this.value = 1; if (this.value > 10) this.value = 10; }); ``` This code works, but I want to understand why Safari isn't respecting the min and max attributes as one would expect. Is this a known scenario with Safari, or is there something specific I'm missing in my implementation? Any insights would be appreciated! What am I doing wrong?