<input type="number" min="1" max="5" value="8" id="range">
@import url("https://fonts.googleapis.com/css2?family=Exo:wght@600&display=swap");
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
:root {
--startColor: red;
}
body {
width: 100vw;
min-height: 100vh;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
font-family: "Exo", Arial, sans-serif;
background: linear-gradient(var(--startColor), #a24927, #1f23b3, #08124a);
color: #fff;
}
input {
min-width: 30vw;
min-height: 44px;
display: inline-flex;
align-items: center;
padding: 10px 15px;
font-size: 2rem;
border-radius: 3px;
outline-offset: 3px;
}
input:out-of-range {
color: var(--startColor);
outline: 5px solid currentColor;
}
input:in-range {
color: var(--startColor);
outline: 5px solid currentColor;
}
View Compiled
const input = document.getElementById('range')
const themeColor = document.getElementById('theme__color')
const rootElement = document.documentElement
input.addEventListener('change', (etv) => {
let val = etv.target.value
let valMin = etv.target.min
let valMax = etv.target.max
if (val <= valMin || val >= valMax ){
rootElement.style.setProperty('--startColor', 'red')
themeColor.setAttribute("content", 'red')
} else if (valMin < val && val < valMax){
rootElement.style.setProperty('--startColor', 'green')
themeColor.setAttribute("content", 'green')
} else {
console.log(val)
}
})
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.