Skip to content
Related Articles

Related Articles

HTML | DOM Input URL size Property
  • Difficulty Level : Basic
  • Last Updated : 18 Mar, 2019

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.






<!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.




<!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
  • Internet Explorer 10.0 +
  • Firefox
  • Opera
  • Safari

full-stack-img

My Personal Notes arrow_drop_up
Recommended Articles
Page :