According to MDN:
For maxLength
Valid for text, search, url, tel, email, and password, it defines the maximum number >of characters (as UTF-16 code units) the user can enter into the field. This must be >an integer value 0 or higher. If no maxlength is specified, or an invalid value is >specified, the field has no maximum length. This value must also be greater than or >equal to the value of minlength.
So type=number
is ignored. Here is a work around using the pattern
<input type="text" pattern="d*" maxlength="4">