<!-- :in-range -->
<section class="example-cntr ranges in-range">
    <h1>CSS <code>:in-range</code> pseudo-class</h1>
    <p>The <code>:in-range</code> pseudo-class targets elements that use a range and that the values are within the defined range.</p>
    <p>In the input below, the range is between 5 and 10: Values inside this range create a <span class="green">green</span> border.</p>
    <p>Type <em>555</em> and border color turns red. Type <em>8</em> and border color turns green.</p>
    <input type="number" min="5" max="10">
    <small><em>Press <code>TAB</code> if border color doesn't change when typing.</em></small>
</section>

<!-- :out-of-range -->
<section class="example-cntr ranges out-of-range">
    <h1>CSS <code>:out-of-range</code> pseudo-class</h1>  
    <p>The <code>:out-of-range</code> pseudo-class targets elements that use a range and that the values fall outside the defined range.</p>    
    <p>In the input below, the range is between 5 and 10: Values outside this range create a <span class="red">red</span> border.</p>
    <p>Type <em>555</em> and border color turns red. Type <em>8</em> and border color turns green.</p>
    <input type="number" min="5" max="10">
    <small><em>Press <code>TAB</code> if border color doesn't change when typing.</em></small>
</section>
body {
    width: 100vw;
    display: flex;
    justify-content: center;
}
//'ranges' generic styles
.ranges {
    margin: 5px;
    input[type=number] {
        box-sizing: content-box;
        width: 80px; height: 40px;
        padding: 4px;        
        border-radius: 3px;
        font-size: 22px;
        cursor: text;
        transition: .5s;
    }    
}

//:in-range
.in-range {
    input[type=number] {
        border: 5px solid $r;
    }    
    input[type=number]:in-range {
        border: 5px solid $g;
    }    
}

//:out-of-range
.out-of-range {
    input[type=number] {
        border: 5px solid $g;
    } 
    input[type=number]:out-of-range {
        border: 5px solid $r;
    }
}


//Styling stuff not needed for demo
body { text-align: left; }
h1 {
    text-transform: none;
    border-bottom: #636363 1px dotted;
    code {
        display: inline-block;
        margin-bottom: 10px;
        color: $y;
        background: none;
        box-shadow: none;
    }
}
code { font-size: 1em; }
.example-cntr {
    max-width: 800px;
    margin: 0 auto 50px;
    padding: 30px;
    box-shadow: 0 1px 2px rgba(black,.3);
    background: rgba(black,.15);
    &:last-of-type { margin-bottom: 0; }
}

.flex-ctnr {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
}
small {
    display: block;
    margin: 20px 0 10px;
    padding-top: 10px;    
    text-align: center;
}
View Compiled

External CSS

  1. https://s3-us-west-2.amazonaws.com/s.cdpn.io/9988/codepen-base_3.scss

External JavaScript

This Pen doesn't use any external JavaScript resources.