HTML size Attribute

If this site has been useful, we’d love your support! Running this site takes time and resources, and every small contribution helps us keep creating valuable content. Consider buying us a coffee to keep things going strong!

Description

The size attribute in HTML is used to specify the visual size of an input element. Primarily, it is applicable to <input> elements with a type of text, search, tel, url, email, and password, indicating how many characters wide the input field should be. The value of the size attribute is a positive integer that represents the number of characters.

For example, using <input type="text" size="30"> creates a text input field that is 30 characters wide, making it visually larger and capable of displaying more text without scrolling. This does not limit the number of characters that can be entered into the field; for that purpose, the maxlength attribute is used.

It's important to note that the actual visual width of the input field can vary depending on the user's browser and the CSS applied to the element. CSS can be used to override the size specified by the size attribute, offering more flexibility and control over the appearance of the input field.

While the size attribute provides a simple way to control the width of input elements, modern web development practices often favor CSS for styling and layout, including setting the width of form elements, due to its greater consistency and flexibility across different browsers and devices.

Syntax

<tagname size="number">

Values

  • numberFor an input element, the element's width in number of characters. For a select element, the number of visible options.

Applies To

The size attribute can be used on the following html elements.

Example

<label for="username">Name:</label><br>
<input type="text" id="name" size="40" placeholder="Enter your name"><br><br>
<label for="username">Username:</label><br>
<input type="text" id="username" size="20" placeholder="Enter your username">

Browser Support

The following table will show you the current browser support for the HTML size Attribute.

Desktop
Edge Chrome Firefox Opera Safari
YesYesYesYesYes
Tablets / Mobile
Chrome Firefox Opera Safari Samsung Webview
YesYesYesYesYesYes

Last updated by CSSPortal on: 27th March 2024