HTML | size Attribute

The size attribute in HTML is used to specify the initial width for the input field and a number of visible rows for the select element.

Note:This attribute is only used by <input>, <hr> and <select> element.

  • with <input> This attribute specifies the visible width
    Syntax:

    <input size = "value">

    Example:

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <!DOCTYPE html>
    <html>
        <head>
            <title>HTML size Attribute</title>
            <style>
                h1, h2 {
                    text-align: center;
                
            </style>
        </head>
        <body>
            <h1 style = "color: green;">
                GeeksforGeeks
            </h1>
              
            <h2>
                HTML size Attribute
            </h2>
              
            <input type="text" value = "This is the default size."><br><br>
            <input type="text" size="50" value = "This is user specified size with value equals 50">
        </body>
    </html>

    chevron_right

    
    

    Output:
    input

  • with <select> This attribute specifies the number of visible options in a drop-down list.
    Syntax:

    <select size = "value"> option values...</select>

    Example:

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <!DOCTYPE html>
    <html>
        <head>
            <title>HTML size Attribute</title>
            <style>
                h1, h2 {
                    text-align: center;
                
            </style>
        </head>
        <body>
            <h1 style = "color: green;">
                GeeksforGeeks
            </h1>
              
            <h2>
                HTML size Attribute
            </h2>
            <p>Sorting Algorithms</p>
            <select size="3">
                <option value="merge">merge sort</option>
                <option value="bubble">bubble sort</option>
                <option value="selection">selection sort</option>
                <option value="quick">quick sort</option>
                <option value="insertion">insertion sort</option>
            </select>
        </body>
    </html>

    chevron_right

    
    

    Output:
    select

  • with <hr> This attribute specifies the height of the horizontal line.
    Syntax:

    <hr size = "value">

    Example:

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <!DOCTYPE html>
    <html>
        <head>
            <title>HTML size Attribute</title>
            <style>
                h1, h2 {
                    text-align: center;
                
                hr {
                    background: green;
                }
            </style>
        </head>
        <body>
            <h1 style = "color: green;">
                GeeksforGeeks
            </h1>
              
            <h2>
                HTML size Attribute
            </h2>
            <hr size = "26">
        </body>
    </html>

    chevron_right

    
    

    Output:
    hr

Supported Browsers: The browser supported by size attribute are listed below:

  • Apple Safari 1.0
  • Google Chrome 1.0
  • Firefox 1.0
  • Opera 1.0
  • Internet Explorer 2.0


My Personal Notes arrow_drop_up


If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.