Click here to get back home

size attribute of input element: characters not fixed width?

 HomeNewsGroups | Search | About
 comp.infosystems.www.authoring.html    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
size attribute of input element: characters not fixed width? Neil Zanella 01-30-2005
Posted by Neil Zanella on January 30, 2005, 7:26 pm
Please log in for more thread options
The W3C HTML standard sais the following concerning the HTML input
element:

<quote>
size = cdata [CN]
This attribute tells the user agent the initial width of the control.
The width is given in pixels except when type attribute has the value
"text" or "password". In that case, its value refers to the (integer)
number of characters.
</quote>

However, it seems I cannot specify an input element with a size of
two,
as my web browser keeps making the input element wider than specified
in terms of characters. Maybe it's cause the characters are not fixed
width. Feedback appreciated,

Best Regards,

Neil


Posted by Jukka K. Korpela on January 31, 2005, 9:20 am
Please log in for more thread options
nzanella@gmail.com (Neil Zanella) wrote:

> However, it seems I cannot specify an input element with a size of
> two, as my web browser keeps making the input element wider than
> specified in terms of characters.

Setting width in terms of a number of characters is very vaguely defined,
since in most fonts, the widths of characters vary. A common interpretation
is that the _average_ width should be used, though some browsers use
_maximum_ width - which is generally regarded as a flaw. But "average"
isn't well defined either. Average over what? The Unicode character
repertoire? Some other repertoire? With or without weights based on
frequency of characters? (If you calculate the average over all Ascii
letters, you get something that is much bigger than average width in normal
text, since half of Ascii letters are uppercase and typically fairly wide.)

So there is no good answer. I have even seen browsers that implement
<input size="2"> as a box that cannot even accommodate _one_ letter "W".

If you wish to set the width to give a hint of the expected number of
characters (e.g., when asking for a day of month), setting the font to
monospace is probably the best shot. Not 100% safe of course, but at least
it is fairly well defined what a browser _should_ do, since the maximum
width is the same as (any) average width! (The font is best set using CSS,
though a few old browsers might obey <tt><input ...></tt>.)

--
Yucca, http://www.cs.tut.fi/~jkorpela/
Pages about Web authoring: http://www.cs.tut.fi/~jkorpela/www.html



Posted by Mark Parnell on January 31, 2005, 2:46 pm
Please log in for more thread options
Previously in comp.infosystems.www.authoring.html, Neil Zanella

> However, it seems I cannot specify an input element with a size of
> two,
> as my web browser keeps making the input element wider than specified
> in terms of characters.

What browser? What URL?

--
Mark Parnell
http://www.clarkecomputers.com.au


Similar ThreadsPosted
fixed width and bold October 18, 2008, 4:12 pm
How to keep the table a fixed size December 8, 2004, 8:59 pm
fixed image size February 12, 2007, 1:53 pm
Optimized table with fixed size cells? February 4, 2007, 5:17 pm
acclerator key with input element March 23, 2006, 8:14 am
Permissible characters in attribute names February 6, 2008, 2:04 pm
Testing a file-type input element April 11, 2007, 12:43 am
INPUT element not allowed in form, can't find my error July 8, 2004, 11:08 am
100% width element causes scrollbar in IE when dir=rtl December 14, 2007, 5:21 pm
Size of IE input button November 19, 2004, 6:20 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap