Contact Form Mockup
What you'll build
A `contact.html` file with a form containing labeled name (text), email (email type), and message (textarea) fields, plus a submit button. The form is accessible but does not submit anywhere.
Goals
- Use the form element to group related inputs
- Associate every input with a label using for/id
- Choose the right input type (text, email, textarea) for each field
- Add the required attribute to mark mandatory fields
Prerequisites
- HTML document structure
- Headings and paragraphs
Steps
- 1
Set up the page and form shell
Create
contact.htmlwith a heading and an empty form. The form element is the container that groups all inputs; action and method can be left off for a mockup.Code<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Contact</title> </head> <body> <h1>Contact me</h1> <form></form> </body> </html>Expected result
A page with a heading and an empty form container.
- 2
Add the name field
Inside the form, add a label and an input. The label's for attribute must match the input's id — this is what makes the field accessible to screen readers and makes clicking the label focus the input.
Code<label for="name">Name</label> <input type="text" id="name" name="name" required>Expected result
A text field with a clickable label; submitting empty shows a browser validation message.
Hint
The required attribute triggers built-in browser validation — no JS needed.
- 3
Add the email field
Add a second label/input pair, this time with type="email". The email type gives the user a mobile-friendly keyboard and built-in format validation for free.
Code<label for="email">Email</label> <input type="email" id="email" name="email" required>Expected result
An email field that rejects non-email input on submit.
- 4
Add the message textarea and submit button
Use a textarea (not an input) for multi-line message text. Finish with a button type="submit". The button text describes the action — avoid generic "Submit" when something clearer fits.
Code<label for="message">Message</label> <textarea id="message" name="message" rows="4" required></textarea> <button type="submit">Send message</button>Expected result
A multi-line message field and a submit button complete the form.
- 5
Add minimal layout CSS
Stack the fields vertically with a small style block. Form fields are easier to fill out when each label sits above its input with consistent spacing.
Codeform { display: flex; flex-direction: column; gap: 0.75rem; max-width: 24rem; } label { font-weight: 600; }Expected result
The form fields stack neatly with consistent spacing.
Try it yourself
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Contact</title>
</head>
<body>
<h1>Contact me</h1>
<form>
<!-- TODO: name, email, message, submit -->
</form>
</body>
</html><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Contact</title>
<style>
form { display: flex; flex-direction: column; gap: 0.75rem; max-width: 24rem; }
label { font-weight: 600; }
</style>
</head>
<body>
<h1>Contact me</h1>
<form>
<label for="name">Name</label>
<input type="text" id="name" name="name" required>
<label for="email">Email</label>
<input type="email" id="email" name="email" required>
<label for="message">Message</label>
<textarea id="message" name="message" rows="4" required></textarea>
<button type="submit">Send message</button>
</form>
</body>
</html>What you learned
You built an accessible contact form with properly associated labels, the right input types, built-in validation, and a submit button — the same pattern every real form uses, before any backend is added.
Related Resources
Related Lessons
Related Practice
- Form Elements MCQ
Quiz on choosing the right input type and element.
- Accessibility MCQ
Label association and required fields — the accessibility basics used here.
Related Tools
- HTML/CSS/JS Minifier
Format your form markup to verify the structure.
Related Cheatsheets
- HTML Cheatsheet
Reference for form, label, input, textarea, and button.
Related Reference
- HTML Elements Reference
Reference for form, label, input, textarea, and button.
Related Errors
- 404 Not Found
Page not found errors.
- CORS Error
Cross-origin resource sharing issues.
Related Glossary
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Related Errors
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
- 404 Not Found
Page not found errors.
- CORS Error
Cross-origin resource sharing issues.