HTML Text Box Generator: Input and Textarea Code
What Is an HTML Text Box?
A text box is the place on a web page where you type: a name field, a search bar, a comment box. In HTML there are
two of them. <input type="text"> is a one-line box, and <textarea> is a
multi-line box that wraps long text and scrolls when it's full. Both look plain and a bit old-fashioned until you add some CSS.
This generator writes that HTML and CSS for you. Pick the kind of box, type your label and placeholder, set the
size, border, corners and focus color, and watch a real, working box change as you go. Then copy the code. It all
runs in your browser, and your last box is remembered for next time.
How to Use It, Step by Step
Five quick steps. The preview is the exact code you copy, so what you see is what you get.
Step 1 Pick a Preset or a Type
Click a tile under Presets (Simple, Rounded, Underline only, Soft filled, Dark, Pill search
box, Big textarea, Bold border) to start from a look you like. Then choose the Type of box:
Text, Textarea, Email, Password, Number, Search, Phone or URL. If you haven't changed the label and placeholder
yet, they switch to match, so an Email box starts with “[email protected]”.
Step 2 Write the Label and Placeholder
Type the Label (what the box is for), a Placeholder (the gray hint) and, if
you want, a Default value that's already filled in. The id and
name are made from the label (“Email address” becomes email-address), or you can type
your own. Quotes, < and & in your text are escaped in the code, so they can't
break your page.
Step 3 Set the Size and Look
- Width: pixels, a percent of its container, or Full width.
- Height or Rows: a one-line box gets its height from the font size and padding (leave Height at 0), a textarea from Rows.
- Border and corners: width, style, color, all sides or just the bottom (for an underline look), and the corner radius. 999 makes a pill.
- Colors: background (or transparent), text and placeholder color.
Step 4 Choose the Focus Style and Behavior
The Focus color and Focus ring set what happens when someone clicks or tabs
into the box. Under Behavior you can make it Required, Read-only or Disabled, set a Max
length, pick an Autocomplete hint, and, for a textarea, choose whether people can resize it.
Step 5 Try It, Then Copy the Code
Click into the preview and type: you'll see your focus style and placeholder for real. Switch the page
behind it to white, gray or dark to check it fits your site. Then pick Class + <style>
(a reusable class, the best choice for most sites) or Inline styles (everything in a
style="" attribute, handy for a quick test), and press Copy all,
Copy HTML or Copy CSS.
💡 Inline styles can't style :focus or ::placeholder, so with inline output the
focus color and placeholder color are left out. The tool tells you when that happens.
How to Make a Text Box in HTML
One line does it: an <input> with type="text". Add a <label> whose
for matches the input's id. Now clicking the label puts the cursor in the box, and screen
readers read the label out. The name is what the value is called when a form is sent.
The code:
<label for="name">Name</label>
<input type="text" id="name" name="name">
You'll see (try typing in it):
<input> has no closing tag. The label and the box sit on the same line by default because both
are inline. Add display: block to the label (the generator does) to put the label on top.
Multi-Line Text Box: textarea, rows and cols
For anything longer than a line, like a message, a comment or an address, use <textarea>.
rows is how many lines tall it is and cols how many characters wide. Unlike an input, a
textarea has a closing tag, and whatever you put between the tags is the text it starts with.
The code:
<label for="message">Message</label><br>
<textarea id="message" name="message" rows="4" cols="30"></textarea>
💡 Keep <textarea></textarea> on one line when it should start empty. Spaces, or more than one line
break, between the tags count as text, and the box will start with them in it.
Set the Width and Height (or Make It Bigger)
Set the width with CSS: a fixed width: 300px, or width: 100% to fill the container. Add
box-sizing: border-box so the padding and border stay inside that width; without it, a 100% box with
padding pokes out on the right. To make a box look bigger, raise the font-size and the
padding rather than setting a height: the text stays centered and nothing gets cut off. The old
size attribute sets the width in characters, but CSS gives you much more control.
The code:
<style>
.wide {
box-sizing: border-box;
width: 100%;
}
.big {
font-size: 20px;
padding: 12px 16px;
}
</style>
<p><input type="text" class="wide" placeholder="width: 100%"></p>
<p><input type="text" class="big" placeholder="Bigger text and padding"></p>
<p><input type="text" size="8" placeholder="size=8"></p>
For a textarea, use rows for the height, or a CSS height / min-height if you
want an exact size in pixels.
Placeholder vs Default Value
A placeholder is a gray hint that disappears when you start typing, and it is never sent with the form.
A value is real text that's already in the box, and it is sent unless someone changes it. In a
textarea, the default value goes between the tags instead of in a value attribute.
The code:
<p><input type="text" placeholder="Type your city"></p>
<p><input type="text" value="London"></p>
<textarea rows="2">This text is already in the box.</textarea>
Rounded Corners, Border Color and Focus Style
border-radius rounds the corners (a big number like 999px makes a pill), and border sets
the width, style and color. The :focus rule is what the box looks like while you're typing in it.
Browsers draw an outline there by default. If you remove it with outline: none, always put something
just as clear in its place, like a new border color and a soft ring made with box-shadow. Keyboard
users need it to see where they are.
The code:
<style>
.nice {
padding: 10px 14px;
font-size: 16px;
border: 2px solid #d1d5db;
border-radius: 12px;
}
.nice:focus {
outline: none;
border-color: #4f46e5;
box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.25);
}
</style>
<input type="text" class="nice" placeholder="Click me">
You'll see (click the box):
Want a fancier ring? The CSS Box Shadow Generator makes the
box-shadow part, and the HTML Color Picker helps you find a focus
color that matches your site.
Stop a Textarea From Being Resized
Most browsers put a small handle in the corner of a textarea so people can drag it bigger. resize: none
removes it. resize: vertical is often the better choice: people can still make the box taller for a
long message, but they can't drag it wider than your layout.
The code:
<style>
.no-resize {
resize: none;
}
.tall-only {
resize: vertical;
}
</style>
<p><textarea class="no-resize" rows="2">You can't resize me</textarea></p>
<p><textarea class="tall-only" rows="2">Only taller or shorter</textarea></p>
You'll see (try the corner handle):
Read-Only, Disabled, Required and Max Length
readonly: people can't type, but they can still select and copy the text, and the value is sent with the form. Good for an order number or a generated link. disabled: grayed out, can't be clicked or focused, and the value is not sent. Good for options that don't apply right now. required: the browser won't send the form while the box is empty and shows a short message instead. Still check the value on your server too. maxlength="5": stops typing after 5 characters. It works on text-like inputs and textarea, but not on type="number"; use min and max there.
The code:
<p><input type="text" value="Read-only: select and copy me" readonly></p>
<p><input type="text" value="Disabled: grayed out" disabled></p>
<p><input type="text" placeholder="Max 5 characters" maxlength="5"></p>
Labels and Accessibility
Every text box needs a name that screen readers can read out. The best way is a visible
<label for="..."> whose for matches the box's id. A placeholder isn't a label:
it disappears as soon as you type and is often too light to read. When the design really has no room for a label,
like a search bar with a magnifying glass icon, add aria-label to the input instead. The generator
does this for you when you switch off Show label.
<label for="email">Email</label>
<input type="email" id="email" name="email" required>
<input type="search" name="q" aria-label="Search the site">
Also set autocomplete where it fits (email, name, tel,
new-password…). Browsers and password managers use it to fill the box in one tap.
HTML Input Types
The type attribute changes how a one-line box behaves. On a phone it also picks the keyboard, which
makes forms much quicker to fill in. Here are the types the generator supports:
| Type | Use it for | Phone keyboard |
type="text" | Anything short: names, cities, titles. The default. | Normal keyboard |
type="email" | Email addresses. The browser checks for an @ before the form is sent. | Keyboard with @ and . |
type="password" | Passwords. Typed letters show as dots. | Normal keyboard, no suggestions |
type="number" | Whole numbers and amounts. Add min and max to set limits. | Number keypad |
type="search" | Search boxes. Some browsers add a small ✕ to clear it. | Keyboard with a Search key |
type="tel" | Phone numbers. No format check, since numbers differ by country. | Phone dial pad |
type="url" | Web addresses. The browser checks it starts with something like https://. | Keyboard with / and .com |
Try them here. On a phone, tap each one to see its keyboard:
Email and URL checks only happen in the browser, and only when the form is sent. They catch typos, not fake
addresses, so always check the value on your server as well.
What This Generator Doesn't Do
- It makes one field at a time. Put several together inside a
<form> with a submit button yourself, or try it in the HTML Editor. - It doesn't write JavaScript, so there's no live “check as you type”. The browser's own checks (
required, type="email", maxlength) still work. - It doesn't send anything anywhere. A form needs a server (or a form service) to receive what people type.
- Browsers paint autofilled boxes their own color (often light blue or yellow), and a few details like the ✕ in search boxes or the arrows on number boxes look a little different in each browser.
Building the rest of the page? Make a table with the HTML Table Generator, test
your whole form in the HTML Editor, and check it with the
HTML Validator.
Frequently Asked Questions
How do I make a text box in HTML?
Use an input element with type="text": <input type="text" id="name" name="name">. Give it a label so people (and screen readers) know what it is for: <label for="name">Name</label>. The for of the label must match the id of the input. That one line is a working text box; CSS only changes how it looks.
How do I make a bigger, multi-line text box?
Use a textarea instead of an input: <textarea id="message" name="message" rows="5"></textarea>. rows sets how many lines tall it is, and cols sets how many characters wide, but most people set the width with CSS (width: 100%) and keep rows for the height. A textarea needs a closing tag, and any text between the tags is its starting value.
How do I change the width and height of a text box?
With CSS: .text-box { width: 300px; } or width: 100% to fill its container. For a one-line input, the height comes from the font size and padding, so padding: 12px 14px is usually nicer than a fixed height. For a textarea, use the rows attribute or a CSS height. Add box-sizing: border-box so the padding and border stay inside the width you set.
What is the difference between input and textarea?
An input is a single line: pressing Enter submits the form instead of starting a new line. A textarea is multi-line, wraps long text and keeps line breaks. Inputs also come in types (email, password, number, search, tel, url) that change the phone keyboard and add simple checks. Use a textarea for messages, comments and addresses, and an input for everything short.
How do I stop a textarea from being resized?
Add resize: none to its CSS. If you only want to stop people making it wider (which can break your layout) but still let them make it taller, use resize: vertical instead. That’s usually the friendlier choice, because long messages are easier to write in a taller box.
What is the difference between readonly and disabled?
Both stop typing. A readonly box can still be focused, selected and copied, and its value is sent with the form. A disabled box is grayed out, can’t be focused or clicked, and its value is not sent at all. Use readonly for values people should see but not change (like an order number) and disabled for options that don’t apply right now.
Is a placeholder enough, or do I need a label?
Use a label. The placeholder disappears as soon as someone types, so they can forget what the box was for, and its light gray text is hard to read for many people. A visible <label for="..."> fixes both. If the design really has no room for a label (a search box with an icon, say), add aria-label="Search" to the input so screen readers still announce it. The generator does that for you when you switch Show label off.
How do I change the border color when someone clicks into the text box?
Style the :focus state: .text-box:focus { border-color: #4f46e5; outline: none; box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.25); }. Only remove the outline when you replace it with something just as visible, because keyboard users rely on it to see where they are. The Focus color and Focus ring controls in the generator write this rule for you.
Why does my phone zoom in when I tap a text box?
iPhones and iPads zoom into any input or textarea with a font size under 16px. The fix is simple: set font-size: 16px (or bigger) on your text boxes. Don’t disable zooming in the viewport meta tag to stop it, because people who need to zoom couldn’t any more.