w3resource

HTML size attribute

size

The purpose of the HTML size attribute is to specify the initial width (in pixels / characters) for input field and a number of visible rows for the select element.

Supported elements

HTML size attribute supports hr, input and select elements.

Syntax

<ElementName size="value" >.....</ElementName>

Where ElementName is any supported element.

Type of value

A number.

Value

A number indicating a number of characters can be entered for input fields with type text or password. For remaining type of input fields, it indicates width in pixels.

For select element, the number as value indicates the number of rows visible.

Default value

There is not default value of HTML size attribute.

Supported doctypes

HTML 4.01 strict, HTML 4.01 transitional, HTML 4.01 frameset.

Example of HTML size attribute with input element

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Example of HTML size attribute with input element</title>
</head>
<body>
<form name="user_info" action="action_get.php" method="get"> 
Name : <input type="text" name="name" size="20"><br>
email  : <input type="text" name="email" size="20"><br>
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>

Result

html size attribute with input element

View this example in a separate browser window

Example of HTML size attribute with input element

Example of HTML size attribute with select element

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Example of HTML size attribute with select element</title>
</head>
<body>
<form name="user_info" action="action_get.php" method="get"> 
<label>Select your favourite sports</label> 
<select size="2">
<option value="Soccer">Soccer</option>
<option value="Hockey">Hockey</option>
<option value="Tennis">Tennis</option>
<option value="Golf">Golf</option>
</select><br/>
<input type="submit" name="submit" value="Submit" />
</form>
</body>
</html>

Result

html size attribute with select element

View this example in a separate browser window

Example of HTML size attribute with select element

Previous: HTML shape attribute
Next: HTML span attribute

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.