JSFiddle - React, Tailwind, and code Playground
HTML
<!-- STYLE TO APPLY SIZE -->
<style>
img {
width: 20%;
}
.img20 {
width: 20%;
}
.img40 {
width: 40%;
}
.img60 {
width: 60%;
}
</style>
<!-- BUTTONS TO SET SIZES FROM 20% TO 60% -->
<button onclick="setImgClass('img20');">20%</button>
<button onclick="setImgClass('img40');">40%</button>
<button onclick="setImgClass('img60');">60%</button>
<!-- LINE SEPARATOR -->
<hr>
<!-- 3 IMAGES FROM PUBLIC -->
<img src="https://images.unsplash.com/photo-1679683287672-c5cf1859958f?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxleHBsb3JlLWZlZWR8Mnx8fGVufDB8fHx8&auto=format&fit=crop&w=500&q=60" />
<img src="https://images.unsplash.com/photo-1679325965190-0530dc29c512?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxleHBsb3JlLWZlZWR8NHx8fGVufDB8fHx8&auto=format&fit=crop&w=500&q=60" />
<img src="https://images.unsplash.com/photo-1679597454485-d1d04f88b78a?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxleHBsb3JlLWZlZWR8MTJ8fHxlbnwwfHx8fA%3D%3D&auto=format&fit=crop&w=500&q=60" />
<script>
function setImgClass(pClass) {
var elements = document.getElementsByTagName('img')
for (i = 0; i < elements.length; i++) {
elements[i].classList.remove('img20');
elements[i].classList.remove('img40');
elements[i].classList.remove('img60');
elements[i].classList.add(pClass);
}
}
</script>