How to make a text box and a checkbox in HTML
A text box is <input type="text"> or <textarea>. A checkbox is <input type="checkbox">. Add labels so they are easy to click, size and style them with CSS, group them in a form, and decide where the answers go.
Have the file already? Upload it and get a link anyone can open. Free plan, no card.
Get a link freeText boxes and checkboxes are both form inputs. You can add them to any HTML file with a text editor and check the result in a browser. This guide covers the code for each, the attributes worth knowing, simple CSS, and the part most tutorials skip: where the answers go when someone presses Send.
1. A one-line text box
Put this inside the <body> of your page:
<label for="name">Your name</label> <input type="text" id="name" name="name">
The label is the text people read. Its for attribute must match the input's id; then clicking the label puts the cursor in the box, and screen readers announce the label when the box is focused. The name attribute is the field name that gets sent with the answer, so give every input one.
Useful attributes on the same tag:
- ✓placeholder="Sam Lee" shows grey example text inside the empty box. Keep the label as well: the placeholder disappears as soon as someone types.
- ✓required stops the form sending while the box is empty, and the browser shows a message.
- ✓maxlength="80" limits how many characters can be typed.
- ✓value="..." fills the box in advance.
- ✓type="email", type="tel", type="number" or type="url" instead of text: phones show the matching keyboard, and email and url are checked for the right format before sending.
2. A bigger text box for longer answers
For comments or messages, use a textarea. Unlike input, it has a closing tag:
<label for="message">Message</label> <textarea id="message" name="message" rows="5"></textarea>
rows sets the starting height in lines. Anything you put between the tags shows as starting text, so leave it empty for a blank box. Most browsers let people drag the corner to resize it; add textarea { resize: vertical; } to your CSS to allow height changes only.
3. A checkbox
A single yes/no checkbox:
<input type="checkbox" id="updates" name="updates" value="yes"> <label for="updates">Send me updates</label>
The label goes after the box here, because people read the box and the text as one line. Clicking the text ticks the box. Add checked to tick it by default: <input type="checkbox" id="updates" name="updates" value="yes" checked>. Add required if the box must be ticked before sending, for example to agree to terms.
When the form is sent, a ticked box sends its value (yes). An unticked box sends nothing at all, so treat a missing field as "no".
4. A group of checkboxes
For "pick all that apply", give every box in the group the same name and a different value, and wrap them in a fieldset with a legend:
<fieldset> <legend>Which days suit you?</legend>
<input type="checkbox" id="mon" name="days" value="Monday"> <label for="mon">Monday</label>
<input type="checkbox" id="wed" name="days" value="Wednesday"> <label for="wed">Wednesday</label>
<input type="checkbox" id="fri" name="days" value="Friday"> <label for="fri">Friday</label> </fieldset>
The legend acts as the question for the whole group. To allow only one choice, use type="radio" with the same name instead; radio buttons untick the others automatically.
5. Style them with CSS
Add these rules inside a <style> block in the <head>:
label { display: block; margin: 12px 0 4px; }
input[type="text"], input[type="email"], textarea { width: 100%; max-width: 420px; padding: 8px 10px; font: inherit; border: 1px solid #bbb; border-radius: 6px; box-sizing: border-box; }
input[type="checkbox"] { width: 18px; height: 18px; accent-color: #b5541c; }
input[type="checkbox"] + label { display: inline; margin-left: 6px; }
font: inherit makes the boxes use the page font instead of the browser default. box-sizing: border-box keeps the padding inside the 100% width, so the box never pokes past the edge on a phone. accent-color changes the tick color in current browsers. The last rule keeps a checkbox and its label on one line. For more on fonts and colors, see change font and change text color.
6. Put them in a form with a Send button
Inputs only send anything when they sit inside a <form> with a submit button:
<form> ...the labels, text boxes and checkboxes from above... <button type="submit">Send</button> </form>
Press Send and the browser checks the required fields, then sends each name with its value to the address in the form's action attribute. With no action, it reloads the same page with the answers added to the address bar, and they go nowhere. A plain HTML file cannot store answers by itself. For more on the button, see add a button in HTML.
Common problems
- ✓Clicking the label does nothing: the for value does not match the input id exactly, or two inputs share the same id.
- ✓An answer is missing from the results: the input has no name attribute. Fields without a name are not sent.
- ✓The text box is wider than the phone screen: use max-width with width: 100% and box-sizing: border-box, as above, instead of a fixed width in pixels.
- ✓Only one checkbox in a group arrives: each box needs a different value, and whatever reads the answers must accept several values for the same name.
- ✓The box is tiny and hard to tap on a phone: set the checkbox width and height to 18px or more and keep the label clickable.
Using an AI tool to build the form
Claude, ChatGPT and Gemini write forms well from a short brief: list the questions, say which are text boxes, which are checkboxes and which are required, and ask for "a single HTML file with labels for every input". Check the result for the problems above: matching for and id values, a name on every input, and where the form sends its answers.
Collect the answers without a server
Upload the page to FileShare Pro and add one attribute to the form tag: <form data-fsp-form="signup">. Submissions are saved without a page reload and appear on your file under Activity, with a CSV download. A group of ticked checkboxes arrives as one field with the values separated by commas. Limits: up to 10 fields per submission, 500 characters per field and 2 KB per submission. Visitors can only send answers; only you and people you have shared the file with can read them. Sign up free to host your form, or read build a feedback form with no backend for polls and other patterns.
Frequently asked
Use <input type="text" id="name" name="name"> for one line, or <textarea id="message" name="message" rows="5"></textarea> for several lines. Add a <label for="name"> with the same id so people know what to type.
Use <input type="checkbox" id="updates" name="updates" value="yes"> followed by <label for="updates">Send me updates</label>. Add checked to tick it by default.
Add the checked attribute to the input tag: <input type="checkbox" name="updates" value="yes" checked>.
Nowhere on their own. The form needs an action address that stores them. On FileShare Pro, add data-fsp-form="name" to the form tag and answers collect on the file as rows you can download as CSV.
Drop the file, copy the link — live in seconds, free plan included.
Start sharing free