Open In App

HTML | DOM Input URL size Property

Last Updated : 26 Aug, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

The DOM Input URL size Property in HTML DOM is used to set or return the value of the size attribute of an Input url Field. The size attribute is used to define the width of a url field. Its default value is 20

Syntax: 

  • It returns the Input url size property.
urlObject.size
  • It is used to set the Input url size property.
urlObject.size = number

Property Values: It contains a single value number which is used to specify the width of a url field in terms of the number of characters. 

Return Value: It returns the numeric value which represents the width of a url field in terms of the number of characters. Example-1: This example illustrates how to return Input URL size property. 

html




<!DOCTYPE html>
<html>
 
<head>
    <title>
        DOM Input URL size Property
    </title>
</head>
 
<body>
    <center>
        <h1 style="color:green;">
                GeeksForGeeks
            </h1>
 
        <h2>
          DOM Input URL size Property
      </h2>
 
        <label for="uname"
               style="color:green">
            <b>Enter URL</b>
        </label>
 
        <input type="url"
               id="gfg"
               placeholder="Enter URL"
               size="20">
 
        <br>
        <br>
 
        <button type="button"
                onclick="geeks()">
            Click
        </button>
 
        <p id="GFG"
           style="color:green;
                  font-size:25px;">
      </p>
 
        <script>
            function geeks() {
               
                var link =
                    document.getElementById(
                      "gfg").size;
               
                document.getElementById(
                  "GFG").innerHTML =
                  link;
            }
        </script>
    </center>
</body>
 
</html>


Output: 

Before Clicking On Button:

  

After Clicking On Button:

  

Example-2: This Example illustrates how to set the size Property. 

html




<!DOCTYPE html>
<html>
 
<head>
    <title>
        DOM Input URL size Property
    </title>
</head>
 
<body>
    <center>
        <h1 style="color:green;">
                GeeksForGeeks
            </h1>
 
        <h2>
          DOM Input URL size Property
      </h2>
 
        <label for="uname"
               style="color:green">
           
            <b>
              Enter URL
          </b>
        </label>
 
        <input type="url"
               id="gfg"
               placeholder="Enter URL"
               size="20">
 
        <br>
        <br>
 
        <button type="button"
                onclick="geeks()">
            Click
        </button>
 
        <p id="GFG"
           style="color:green;
                  font-size:25px;">
      </p>
 
        <script>
            function geeks() {
               
                var link =
                    document.getElementById(
                      "gfg").size = "40";
               
                document.getElementById(
                  "GFG").innerHTML =
                  "The value of the size"+
                  " attribute was change to "
                + link;
            }
        </script>
    </center>
</body>
 
</html>


Output: 

Before Clicking On Button:

  

After Clicking On Button :

  

Supported Browsers: The browser supported by DOM input URL size Property are listed below:

  • Google Chrome 1
  • Edge 12
  • Firefox
  • Opera 11
  • Safari


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads