espresso — 2009-06-23T11:06:31-04:00 — #1
I'm trying to figure out what the difference is with text input's size vs. witdh. I know that width controls the actual width of the textbox in either pixels or % but I don't understand visually what size does.
And should size be an optional attribute in lets say a custom OOP control?
chris_cressman — 2009-06-23T12:43:39-04:00 — #2
I did a quick experiment on my machine. I created a HTML 4 document and placed a INPUT element inside a P element. I then experimented with size and width attributes. Size changed the visible width of the input element (measured in characters). Width was an invalid attribute and did nothing.
It is also possible to use CSS to set the width of an input element. Size is the HTML way to set the width, while width is the CSS way to set the width. Either can be used, but CSS is generally easier to maintain.
Also, size is an optional attribute.
autisticcuckoo — 2009-06-23T13:22:41-04:00 — #3
size attribute is mainly presentational, and I avoid it unless it's really important to set a width for non-CSS browsers like Lynx. The exception is for
select elements, where it's needed to create a list box instead of a drop-down list.
The widths of text fields etc should be specified with the
width property in CSS. It has the advantage of letting you specify the width in em, as well.
textarea elements the
cols attributes are required, but I still think the dimensions should be overridden with CSS.
espresso — 2009-06-23T13:34:03-04:00 — #4
I actually found that size did nothing and width changed the physical width of the textbox
espresso — 2009-06-23T13:34:51-04:00 — #5
of course I was looking at this page:
looks like at the top this is only HTML 2.0 compliant?
espresso — 2009-06-23T13:35:52-04:00 — #6
espresso — 2009-06-23T13:41:19-04:00 — #7
I take that back size="20px" does physically change the texbox size
somezing — 2009-06-23T14:32:00-04:00 — #8
Isn't size supposed to limit the number of characters the user can insert in the text field?
(Number) This attribute tells the Web browser the initial width of the control. The width is given in pixels except when the type attribute has the value text or password. In such cases, its value is the number of characters.
Width is the one that I think shouldn't be used here.
chris_cressman — 2009-06-23T14:36:52-04:00 — #9
That's actually the purpose of the maxlength attribute.
espresso — 2009-06-23T15:28:23-04:00 — #10
width has been retired. Use size.
felgall — 2009-06-23T15:39:28-04:00 — #11
You have that backwards.
You should always set the width of the field by specifying a width in the stylesheet. For example:
espresso — 2009-06-23T15:47:03-04:00 — #12
If you were to specify the width in a stylesheet then you could end up with hundreds of styles defined in your .css
I don't think that's practical. And you definitely would not want inline styles in your Mark-up period.
felgall — 2009-06-23T18:51:37-04:00 — #13
It is perfectly practical - for most forms you would only ever want the fields to display in a very small number of widths and so would need at most three or four classes to be defined for it.
Defining it via the HTML is completely impractical since different browsers interpret size differently and so what might be big enough to display 3 of a given character in one browser will be big enough for 6 of that character in a different browser and therefore can't look right in both.
It isn't like you are defining how much can be entered into the field or even how much will fit in the display since how much can be entered comes from the maxlength attribute and how much will display depends on what characters are entered and how much width each of them uses - so a lot of iiiiii will fit in the same space as very few MM.
espresso — 2009-06-23T20:21:18-04:00 — #14
what's practical and what's reality depends on how complex your site is, especially if it's an ecommerce site. On our site, every product has a dynamic set of fields spit out from a custom control. Those textboxes vary and we have about 100 variances because each product has different configurations for it..it's a configurator.
autisticcuckoo — 2009-06-24T01:18:21-04:00 — #15
size attribute doesn't allow you to specify a unit, only a number. According to the specification,
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.
Sounds like bad design and poor usability to me. As Stephen said, a handful of classes should do it. It's often a good idea to make text fields span the whole width of the form, unless it's really important to point out that a particual field only accepts a small number of characters.