Home How do I set the size of an HTML text box?

# How do I set the size of an HTML text box?

user225269
1#
user225269 Published in 2010-01-24 01:24:04Z
 How do I set the size of an HTML text box?
Rowno
2#
 Just use: textarea { width: 200px; }  or input[type="text"] { width: 200px; }  Depending on what you mean by 'textbox'.
Dan Herbert
3#
Dan Herbert Reply to 2011-09-15 20:55:34Z
 Your markup:   The CSS: .resizedTextbox {width: 100px; height: 20px}  Keep in mind that text box size is a "victim" of the W3C box model. What I mean by victim is that the height and width of a text box is the sum of the height/width properties assigned above, in addition to the padding height/width, and the border width. For this reason, your text boxes will be slightly different sizes in different browsers depending on the default padding in different browsers. Although different browsers tend to define different padding to text boxes, most reset style sheets don't tend to include  tags in their reset sheets, so this is something to keep in mind. You can standardize this by defining your own padding. Here is your CSS with specified padding, so the text box looks the same in all browsers: .resizedTextbox {width: 100px; height: 20px; padding: 1px}  I added 1 pixel padding because some browsers tend to make the text box look too crammed if the padding is 0px. Depending on your design, you may want to add even more padding, but it is highly recommend you define the padding yourself, otherwise you'll be leaving it up to different browsers to decide for themselves. For even more consistency across browsers, you should also define the border yourself.
animuson
4#
 input[type="text"] { width:200px } 
Lightsaber
5#
 Your textbox code:   Your CSS code: input[type="text"] { height: 10px; width: 80px; }  or .textboxclass { height: 10px; width: 80px; }  So, first you select your element with attributes (look at first example) or classes(look last example). Later, you assign height and width values to your element.
joym8
6#
 This works for me in IE 10 and FF 23  
Johnny Vikrant
7#
Johnny Vikrant Reply to 2015-06-18 09:58:51Z
 If you don't want to use the class method you can use parent-child method to make changes in the text box. For eg. I've made a form in my form div. HTML Code: 
 Now CSS code will be like: .form textarea{ height: 220px; width: 342px;  Problem solved.
Erol Balci
8#
Erol Balci Reply to 2013-02-08 03:28:32Z
 Try: input[type="text"]{ padding:10px 0;}  This is way it remains independent of what textsize has been set for the textbox. You are increasing the height using padding instead
brenjt
9#
 Try this code : input[type="text"]{ padding:10px 0;}  This way it remains independent of what textsize has been set for the textbox. You are increasing the height using padding instead.
Matchu
10#
 Elements can be sized with the height and width attributes.
R Keene
11#
R Keene Reply to 2016-05-20 18:56:23Z
 Lookout! The width attribute is clipped by the max-width attribute. So I used.... 

URI


Nivedhya
12#