How to Create a Simple HTML Form: Code and Email Delivery
You paste a basic HTML form onto your page, type a quick test message, and click "Send". Then the browser shows a 404 screen, or the page just reloads and nothing ever reaches your inbox.
Writing the tags takes five minutes. Getting those answers into your email without inviting a flood of bot spam is the half most tutorials leave out.
Build a basic contact form step by step
Start with three fields: full name, email address, and message. Skip br tags for spacing and let clean HTML5 structure do the work.
- Open form with a real destination. Add action="YOUR_ENDPOINT_URL" and method="POST" so the browser knows where and how to send what a visitor types.
- Pair every label for with a matching id. Clicking the label jumps straight into the box on desktop and mobile, and screen readers announce each field clearly.
- Give every field a unique name. If an input has no name attribute, the browser quietly leaves it out when sending the message.
- Use specific input types and autocomplete. Setting type="email" opens the "@" keyboard on phones and checks the email format before sending.
- Finish with button type="submit". Visitors can tap the button or press Enter to send their note.
- Only id, no name
Bad: input id="mail" type="email" sends nothing at all.
Better: Include both id="mail" and name="email", matching the rule in the W3Schools form guide. - Using GET for private details
Bad: method="GET" puts names and messages straight into the page URL, where they sit in browser history and server logs.
Better: Use method="POST" so personal details travel inside the request body. - Placeholders instead of labels
Bad: input placeholder="Email" vanishes the second someone types and leaves screen readers guessing.
Better: Pair a visible label for="mail" with id="mail", following the semantics in the MDN first form guide. - File picker without enctype
Bad: input type="file" with default encoding sends only the filename text.
Better: Add enctype="multipart/form-data" so the browser sends the real file bytes. - The browser runs built-in checks. It verifies required, minlength, and type="email", pausing if anything is missing or mistyped.
- It gathers every named field. Each control with a name adds its name=value pair, while unnamed fields get skipped.
- It packs and sends the request. The browser sends an HTTP POST request to your action URL using the encoding you chose.
- Your destination replies. A server script or hosted handler saves the entry, emails your inbox, and shows a thank-you page.
- PHP or server script
Setup: Write a handler with authenticated SMTP, such as PHPMailer.
Best fit: Sites already running a custom server. - Hosted endpoint
Setup: Paste the endpoint URL into action.
Best fit: Static pages that only need simple inbox mail. - Embedded builder
Setup: Build visually and paste one embed snippet.
Best fit: Teams needing alerts, file uploads, or surveys. - Try it on a phone. Tap the email box and make sure the "@" keyboard pops up cleanly.
- Submit empty fields. Check that browser required messages appear without breaking your layout.
- Watch the Network tab. Open DevTools, send a test entry, and confirm every name=value pair shows up in the POST body.
- Check both inbox and spam. Send yourself a real test note and confirm it lands in your main inbox instead of junk.
- Four embed formats. Place your project as an inline frame, a pop-up modal, a slide-out tab, or a full page, plus a direct link and QR code inside Pollsar distribution tools.
- Inbox alerts and webhooks. Route entries to webhooks, Zapier, Slack, Telegram, or Google Sheets, and alert yourself, teammates, or visitors with Pollsar email notifications.
- Ready-made inputs and themes. Combine text, email, rating, choice, NPS, and file upload fields across 80 matched themes without writing CSS, using the Pollsar question types library.
- Instant charts and exports. Read single replies or summary tables in one workspace, then export CSV, XLSX, JSON, or PDF files without running a database.
Complete contact form HTML
<form class="contact-box" action="https://example.com/contact" method="POST">
<label for="full-name">Full name</label>
<input id="full-name" name="full_name" type="text" autocomplete="name" required>
<label for="reply-email">Email address</label>
<input id="reply-email" name="email" type="email" autocomplete="email" required>
<label for="user-message">Message</label>
<textarea id="user-message" name="message" rows="5" required></textarea>
<button type="submit">Send message</button>
</form>Replace "https://example.com/contact" with your real server route or form backend URL before publishing. Also notice one tag detail: input stands on its own without a closing tag, while textarea always needs a closing /textarea.
Five key attributes on the form tag
Before you add more fields, get familiar with the five attributes on the opening form tag. They tell the browser where answers go and how to package them.
| Attribute | What it does |
|---|---|
| action | Sets the destination URL, such as a server script or hosted endpoint, that receives submitted answers. |
| method | Picks how data travels. "POST" sends values inside the request body; "GET" tacks them onto the page URL. |
| enctype | Sets the encoding format. Use "multipart/form-data" whenever visitors upload files. |
| autocomplete | Lets browsers fill in saved names, emails, and addresses. It stays on by default. |
| novalidate | Turns off default browser error popups if you prefer to write your own validation checks. |
Core HTML form elements and when to use each
Most contact, feedback, signup, and order pages come down to six elements. Pick the tag that fits the answer instead of dropping plain text boxes everywhere.
| Element | Where it fits best |
|---|---|
| input | One-line answers like names, emails, phone numbers, or passwords, paired with matching autocomplete. |
| textarea | Longer comments or project notes. Set rows="5" and close the tag with /textarea. |
| Checkbox | Consent toggles or multi-select questions using type="checkbox". Wrap groups inside fieldset. |
| Radio button | One choice from a short list using type="radio". Give every option in the group the same name. |
| select | A dropdown menu with option items for long lists like countries or support topics. |
| Hidden field | Passes extra values like a page ID or security token via type="hidden". Never store secrets here, because anyone can view source. |
Textarea, checkboxes, and short survey code
Multi-line messages belong in an HTML form textarea. Giving it rows="5" lets visitors read their whole reply at once, and adding maxlength="1000" keeps long notes from running away.
Use HTML checkboxes for consent toggles or questions where visitors can pick more than one option. Wrap grouped checkboxes and radio buttons in fieldset with a legend heading so assistive tools read the question first.
<form class="contact-box" action="https://example.com/survey" method="POST">
<input type="hidden" name="page_source" value="homepage">
<fieldset>
<legend>How easy was checkout?</legend>
<label><input type="radio" name="ease" value="easy" required> Easy</label>
<label><input type="radio" name="ease" value="okay"> Okay</label>
<label><input type="radio" name="ease" value="hard"> Hard</label>
</fieldset>
<fieldset>
<legend>Which topics interest you?</legend>
<!-- topics[] collects multiple checked boxes into a list -->
<label><input type="checkbox" name="topics[]" value="guides"> Guides</label>
<label><input type="checkbox" name="topics[]" value="updates"> Product updates</label>
</fieldset>
<label for="role">Your role</label>
<select id="role" name="role" required>
<option value="">Choose one</option>
<option value="owner">Site owner</option>
<option value="dev">Developer</option>
<option value="marketing">Marketer</option>
</select>
<button type="submit">Send answers</button>
</form>File upload and registration variants
Adding a file upload input takes one extra attribute on the opening form tag. Pair enctype="multipart/form-data" with method="POST", or the browser sends only the filename text and leaves the actual file behind.
For a signup or login form template, pair type="password" with minlength="8" and autocomplete="new-password". On a sign-in page, switch that value to "current-password" so password managers fill credentials cleanly.
<!-- File upload with enctype -->
<form class="contact-box" action="https://example.com/upload" method="POST" enctype="multipart/form-data">
<label for="project-brief">Upload PDF or image</label>
<input id="project-brief" name="brief" type="file" accept=".pdf,.png,.jpg" required>
<button type="submit">Upload file</button>
</form>
<!-- Simple registration -->
<form class="contact-box" action="https://example.com/signup" method="POST">
<label for="reg-email">Work email</label>
<input id="reg-email" name="email" type="email" autocomplete="email" required>
<label for="reg-pass">Password</label>
<input id="reg-pass" name="password" type="password" minlength="8" autocomplete="new-password" required>
<button type="submit">Create account</button>
</form>Submit button: button vs input type="submit"
Choose button type="submit" instead of input type="submit" value="Send". Both send the answers, while button lets you add icons or styled text inside and fits right into modern CSS button styles.
Add clean CSS and dark mode styles
Plain browser fields look cramped on phones. About twenty lines of scoped CSS give you full-width stacking, comfortable tap areas, clear keyboard focus outlines, and automatic dark mode styling that follows the visitor's system theme.
.contact-box {
display: grid;
gap: 0.75rem;
max-width: 28rem;
font-family: system-ui, sans-serif;
}
.contact-box label {
font-weight: 600;
}
.contact-box input:not([type="checkbox"]):not([type="radio"]),
.contact-box textarea,
.contact-box select {
box-sizing: border-box;
width: 100%;
padding: 0.65rem 0.75rem;
border: 1px solid #cbd5e1;
border-radius: 6px;
font: inherit;
}
.contact-box button[type="submit"] {
padding: 0.75rem 1.25rem;
border: 0;
border-radius: 6px;
background: #111827;
color: #ffffff;
font-weight: 600;
cursor: pointer;
}
.contact-box :focus-visible {
outline: 2px solid #2563eb;
outline-offset: 2px;
}
@media (prefers-color-scheme: dark) {
.contact-box input:not([type="checkbox"]):not([type="radio"]),
.contact-box textarea,
.contact-box select {
background: #1e293b;
color: #f8fafc;
border-color: #475569;
}
}If your site already uses a CSS framework, skip custom rules. Adding class="form-control" and class="form-select" turns plain HTML inputs and dropdowns into styled Bootstrap form controls right away.
Four silent bugs that break beginner code
Browsers will not warn you when one of these attributes goes missing. The page looks finished, a visitor clicks "Send", and half the data disappears or leaks into browser history.
What happens when a visitor clicks Submit
Knowing what the browser does behind the scenes makes troubleshooting much faster. One click kicks off four quick steps:
Want the page to submit without reloading, or show custom inline messages as visitors type? Add that layer separately in JavaScript with FormData and fetch once your plain HTML works.
How to send submissions to your email inbox
Plain HTML cannot email you by itself. Web browsers have no built-in mail server, so leaving action empty just refreshes the page and throws away everything the visitor wrote.
To route an HTML form to email reliably, point your code at one of three real destinations.
Option 1: PHP or your own server
If your host runs PHP, Node, or Python, set action="/contact.php" and read submitted fields on the server. Skip raw PHP mail, which inbox providers often reject or flag as spam, and send through authenticated SMTP with valid SPF and DKIM records on your domain.
Option 2: Hosted endpoint without PHP
Static hosts like GitHub Pages or Netlify do not run PHP. Keep your exact contact HTML, point the action attribute at a hosted endpoint service, and let it forward every reply straight to your inbox.
Option 3: Embedded no-code builder
Once a simple contact box grows into a multi-step signup, file intake, or short questionnaire, writing your own backend stops being worth the time. An online form builder handles design, email alerts, and storage with no server upkeep.
Stopping spam bots and where a honeypot falls short
Public contact pages attract automated bots within days of launch. A light first filter is a honeypot: an extra text box tucked off-screen with CSS that real visitors never see while basic scripts fill every input on the page.
<div class="hp-wrap" aria-hidden="true">
<label for="company-url">Leave this blank</label>
<input id="company-url" name="company_url" type="text" tabindex="-1" autocomplete="off">
</div>Move .hp-wrap off-screen in CSS using position: absolute and left: -9999px. On your server, quietly ignore any submission where company_url has text in it.
Quick pre-launch check for hand-coded pages
When to code by hand vs embed with Pollsar
Hand-code your markup when you already run a backend, need tight hooks into a custom web app, or just want a three-field contact box on a static portfolio.
Move to a hosted form generator once a project asks for branching rules, file uploads, multi-page flows, or response charts. You can skip the backend plumbing with Pollsar for websites.
Decision rule
Code a three-field contact box by hand if you already maintain a server. Embed a ready-made builder the moment you need conditional paths, file uploads, or instant reporting.
Frequently asked questions
Put a working form live without touching PHP
Copy the HTML5 snippets above whenever you want lean markup on your own server. When you want a styled contact box, signup flow, or site survey live in minutes with inbox alerts and exports, describe your goal and start free with Pollsar.