VOOZH about

URL: https://www.geeksforgeeks.org/html/html-input-size-attribute/

⇱ HTML <input> size Attribute - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

HTML <input> size Attribute

Last Updated : 26 May, 2026

The size attribute is used to specify the visible width of an input field in terms of characters. It helps control the display size of form elements.

  • Defines the visible width of text input fields.
  • The width is measured in character units, not pixels.
  • In <select> tags, it specifies the number of visible options.

Syntax:

<input size="number"> 

Attribute values: It contains the numeric value which specifies the width of an input field in terms of the number of characters. Its default value is 20.

Example: Implementation of HTML <input> size Attribute.

  • The first <input> element lacks a size attribute, so it displays with the default width for text input fields.
  • The second <input> element has size="50", making it wider, accommodating up to 50 characters within the visible area.
  • Demonstrates how the size attribute affects the width of input fields, allowing users to input text comfortably based on the specified size.

HTML <input> size Attribute Use Cases

  • Width Control in Text Inputs: The size attribute specifies the visible width of an <input type="text"> field in terms of characters.
  • Input Field Sizing in HTML5: It helps define the display width of text input elements without using CSS.
  • Visible Options in <select> Tags: In <select> elements, the size attribute determines how many options are visible at once.
Comment
Article Tags: