JSFiddle - React, Tailwind, and code Playground
CSS
@import url('https://fonts.googleapis.com/css2?family=Neucha&display=swap');
:root {
--color: red;
}
* {
box-sizing: inherit;
}
html {
box-sizing: border-box;
}
body {
margin: 0;
font-family: 'Neucha', cursive;
}
div {
display: flex;
align-items: center;
justify-content: center;
flex-wrap: wrap;
width: 100px;
height: 100px;
background: #eee;
text-align: center;
}
div::after {
content: "";
display: block;
width: 100%;
height: 30px;
background: var(--color);
}
JavaScript
const block = document.querySelector('div');
block.addEventListener('click', () => {
block.style.setProperty('--color', 'blue');
})