Range Overflow and Range Underflow properties in JavaScript.

JavascriptWeb DevelopmentObject Oriented Programming

Range Underflow − If the element value is less than that of the specified in min attribute, it sets to true.

Range Overflow − If the element value is more than that of the specified in max attribute, it sets to true.

Following is the code for Range overflow and range underflow property in JavaScript −


 Live Demo

<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
   body {
      font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
   .result {
      font-size: 20px;
      font-weight: 500;
<h1>Range Overflow and Range Underflow property</h1>
Enter a number between 0 to 20<input type="number" class="num" min="0" max="20"
<button class="Btn">CHECK</button>
Click on the above button to check if the number is between 0 and 20.
<div style="color: green;" class="result"></div>
   let resEle = document.querySelector(".result");
   let numEle = document.querySelector('.num');
   document.querySelector(".Btn").addEventListener("click", () => {
         resEle.innerHTML = 'Number exceeds the range';
      else if(numEle.validity.rangeUnderflow){
         resEle.innerHTML = 'Number is lower than the range ';
         resEle.innerHTML = 'Number lies in the range';


The above code will produce the following output −

On entering a number above 20 −

On entering a number below 0 −

Published on 16-Jul-2020 10:28:48