HTML5 Input type "number" in Firefox

The HTML5 input type "number" provides built-in validation and spinner controls for numeric input. However, browser support for certain attributes like min and max has varied across different versions of Firefox.

Browser Support Overview

Modern Firefox versions (52+) fully support the min and max attributes for number inputs. Earlier Firefox versions had limited support, but this is no longer an issue for current web development.

Example

Here's a complete example demonstrating the number input with validation attributes:

<!DOCTYPE html>
<html>
<head>
    <title>HTML5 Number Input</title>
</head>
<body>
    <form action="" method="get">
        <label for="numberInput">Enter a number between 1 and 10:</label><br>
        <input type="number" id="numberInput" name="num" min="1" max="10" step="1" required><br><br>
        <input type="submit" value="Submit">
    </form>
    
    <script>
        document.querySelector('form').addEventListener('submit', function(e) {
            const input = document.getElementById('numberInput');
            const value = parseInt(input.value);
            
            if (value < 1 || value > 10) {
                e.preventDefault();
                alert('Please enter a number between 1 and 10');
            }
        });
    </script>
</body>
</html>

Key Attributes

Attribute Purpose Firefox Support
min Minimum allowed value Firefox 52+
max Maximum allowed value Firefox 52+
step Increment/decrement value Firefox 52+

JavaScript Validation Fallback

For legacy browser support or enhanced validation, you can add JavaScript validation:

function validateNumber(input) {
    const value = parseInt(input.value);
    const min = parseInt(input.getAttribute('min'));
    const max = parseInt(input.getAttribute('max'));
    
    if (value < min || value > max) {
        console.log('Invalid number: must be between ' + min + ' and ' + max);
        return false;
    }
    
    console.log('Valid number: ' + value);
    return true;
}

// Example usage
const numberInput = document.createElement('input');
numberInput.type = 'number';
numberInput.min = '1';
numberInput.max = '10';
numberInput.value = '5';

console.log(validateNumber(numberInput));
Valid number: 5

Conclusion

Modern Firefox browsers fully support HTML5 number input validation attributes. For older browser compatibility, consider JavaScript validation as a fallback method.

Updated on: 2026-03-15T23:18:59+05:30

989 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements