<button onclick="myFunction()">Try it</button> <p id="demo"></p> <script> function myFunction() { var x = "Total Width: " + screen.width + "px"; document.getElementById("demo").innerHTML = x; } </script>