Get your own website Result Size: 625 x 565
x
 
<!DOCTYPE html>
<html>
<head>
<style>
#myDIV {
  text-decoration: underline;
  text-underline-position: auto;
}
</style>
</head>
<body>
<h1>Change text-underline-position with JavaScript</h1>
<div id="myDIV">
C<sub>6</sub>H<sub>12</sub>O<sub>16</sub> (glucose).
</div>
<p>Click the "Try it" button to change the text-underline-position of the div.</p>
<button onclick="myFunction()">Try it</button>
<script>
function myFunction() {
  document.getElementById("myDIV").style.textUnderlinePosition = "under";
}
</script>
</body>
</html>