Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can the size of an input text box be defined in HTML?

Tags:

html

css

input

Here is an HTML input text box:

<input type="text" id="text" name="text_name" /> 

What are the options to define the size of the box?

How can this be implemented in CSS?

like image 617
osos Avatar asked Sep 25 '11 11:09

osos


People also ask

How do I fix the size of a text box in HTML?

With JavaScript, you can use the setAttribute() method to set the value of the size attribute on the input text box. You can also dynamically change the width of a text box to match the length of the input. We can easily do this by setting the size attribute on key events.

How do you change the width and height of an input box in HTML?

The height attribute specifies the height of the <input> element. Note: The height attribute is used only with <input type="image"> . Tip: Always specify both the height and width attributes for images. If height and width are set, the space required for the image is reserved when the page is loaded.


1 Answers

You could set its width:

<input type="text" id="text" name="text_name" style="width: 300px;" /> 

or even better define a class:

<input type="text" id="text" name="text_name" class="mytext" /> 

and in a separate CSS file apply the necessary styling:

.mytext {     width: 300px; } 

If you want to limit the number of characters that the user can type into this textbox you could use the maxlength attribute:

<input type="text" id="text" name="text_name" class="mytext" maxlength="25" /> 
like image 69
Darin Dimitrov Avatar answered Sep 22 '22 06:09

Darin Dimitrov