Home > Web Front-end > Front-end Q&A > How to style a textbox in HTML

How to style a textbox in HTML

PHPz
Release: 2023-04-13 11:13:50
Original
3407 people have browsed it

In web design, the text box is a commonly used element that allows users to enter information on the page. This article will introduce how to set up text boxes in HTML.

  1. Using the tag

To create a text box, use the tag and set its type to "text". Here is a basic example:

<input type="text" name="username">
Copy after login

In this example, we create a text box and name it "username".

  1. Set the text box size and maximum length

You can use the "size" attribute to set the size of the text box, for example:

<input type="text" name="username" size="30">
Copy after login

In this example , we set the size of the text box to 30 characters wide.

In addition, you can also use the "maxlength" attribute to set the maximum length of the text box, for example:

<input type="text" name="username" maxlength="20">
Copy after login

In this example, we set the maximum length of the text box to 20 characters.

  1. Set default value and placeholder

You can use the "value" attribute to set the default value of the text box, for example:

<input type="text" name="username" value="请输入用户名">
Copy after login

In this example , we set the default value of the text box to "Please enter the user name".

In addition, you can also use the "placeholder" attribute to set the placeholder of the text box, for example:

<input type="text" name="username" placeholder="请输入用户名">
Copy after login

In this example, we set the placeholder of the text box to "Please enter username". The placeholder will automatically disappear when the user enters the text box.

  1. Using the