In this shot, we learn about the size
attribute in HTML.
The size
attribute specifies the visible width of an input element. It is provided as the number of characters.
The default visible width of an input element is 20
characters.
<input size="number">
We can use the above syntax to use the size
attribute, where number
specifies the width of the input element in characters.
Let’s take a look at an example.
In the following example, we create four input elements of different sizes.
<html><head></head><body><div id="content"><!-- size attribute --><p>Input element with size 5</p><input type="text" size="5"><p>Input element with size 10</p><input type="text" size="10"><p>Input element with size 15</p><input type="text" size="15"><p>Input element with default size</p><input type="text"></div></body></html>
Here is a line-by-line explanation of the above code:
5
characters.10
characters.15
characters.20
characters.