You can't handle with HTML code u need to write some code for validation on file size limit
For Example :
var uploadField = document.getElementById("file");
uploadField.onchange = function() {
if(this.files[0].size > 2097152){
alert("File is too big!");
this.value = "";
};
};
This example should work fine. I set it up for roughly 2MB, 1MB in Bytes is 1,048,576 so you can multiply it by the limit you need.
Check or preview Here
You Can also go with JQuery like this
$("input[type='file']").on("change", function() {
if (this.files[0].size > 2000000) {
var size = this.files[0].size;
size = ( size >>> 20 ) + '.' + ( size & (2*0x3FF ) ) + ' ' ;
alert("Please upload file less than and your file size is " + size + " Thanks!! ");
$(this).val('');
return size;
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.js"></script>
<input type="file">