HTML Screen width Property

The HTML Screen width property returns the total width of the user’s screen.


Following is the syntax −



Let us see an example of HTML Screen width Property −

<!DOCTYPE html>
   body {
      color: #000;
      height: 100vh;
      background-color: #FBAB7E;
      background-image: linear-gradient(62deg, #FBAB7E 0%, #F7CE68 100%);
      text-align: center;
   .btn {
      background: #db133a;
      border: none;
      height: 2rem;
      border-radius: 2px;
      width: 40%;
      display: block;
      color: #fff;
      outline: none;
      cursor: pointer;
      margin: 1rem auto;
   .show {
      font-size: 1.2rem;
      margin: 1rem auto;
      font-weight: bold;
      font-family: sans-serif;
<h1>HTML screen width Property</h1>
<button class="btn" onclick="get()">Show Screen Width</button>
<div class="show"></div>
   function get() {
      document.querySelector(".show").innerHTML = "Total width is " + screen.width + "px";


Click on “Show Screen Width” button to display total width of user’s screen −