UNIT 9 • STAGE 4 OF 7

The Community Form

Build an HTML form and style it with CSS :focus states

UNIT
STEP 1

HTML Forms

A form is how a web page collects information from a visitor. Every time you fill out a contact form, submit a comment, or sign up for something online, you are using an HTML form.

In this stage you will build a community recipe submission form. Visitors can share their name, their community, a traditional recipe, and how they feel about the food sovereignty movement.

Try clicking into one of the fields below. Notice the green border that appears when a field is active:


That green highlight when the input is active is the CSS :focus state. You are about to build exactly that.

New HTML elements in this stage

<form>, the container for all form fields. <label>, names a field and links to it via the for attribute. <input type="text">, a single-line text field. <input type="email">, a text field that validates email format. <input type="radio">, a circular option where only one can be selected. <textarea>, a multi-line text area. <button type="submit">, a button that submits the form.

STEP 2

Add the Form CSS

Find </style> in your editor and add this CSS just above it:

👉 Add inside <style>, just above </style>: #community-form {
  background: #e8f0fe;
  padding: 60px 40px;
}

#community-form h2 {
  font-size: 1.75rem;
  color: #1a1a1a;
  margin-bottom: 8px;
}

.form-wrap {
  background: white;
  padding: 36px;
  border-radius: 8px;
  max-width: 560px;
  margin-top: 28px;
}

.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  font-size: 0.9375rem;
  font-weight: 700;
  color: #1a1a1a;
  margin-bottom: 6px;
}

.form-group input[type="text"],
.form-group input[type="email"],
.form-group textarea
{
  width: 100%;
  padding: 10px 14px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 1rem;
  font-family: Georgia, serif;
  box-sizing: border-box;
}

.form-group input[type="text"]:focus,
.form-group input[type="email"]:focus,
.form-group textarea:focus
{
  outline: none;
  border-color: #2d4a1e;
  box-shadow: 0 0 0 3px rgba(45, 74, 30, 0.15);
}

.form-group textarea {
  height: 120px;
  resize: vertical;
}

.radio-label {
  display: block;
  font-size: 0.9375rem;
  font-weight: 400;
  margin-bottom: 6px;
  cursor: pointer;
}

.submit-btn {
  background: #2d4a1e;
  color: white;
  border: none;
  padding: 12px 28px;
  border-radius: 6px;
  font-size: 1rem;
  cursor: pointer;
  margin-top: 8px;
}
STEP 3

Why These Styles?

  • background: #e8f0fe on #community-form, a soft blue-indigo. The section colors now move through the page: green hero, light green pillars, warm cream recipes, blue form. Each section has its own identity while the page reads as a whole.
  • display: block on .form-group label, by default, labels are inline elements and sit beside their input field. Setting display: block stacks the label above the field, which is much easier to read and fill in.
  • width: 100% and box-sizing: border-box on inputs, makes every field stretch to fill the form container. Without box-sizing: border-box, the padding would add to the width and fields would overflow.
  • border: 1px solid #d1d5db, a light gray border on the input. It outlines the field without drawing too much attention before the user clicks.
  • :focus, a CSS pseudo-class that applies styles when a user clicks into an element. This is how the browser knows which field is currently active.
  • outline: none on :focus, removes the browser's default blue focus ring (which looks different in every browser) so your custom styles take over completely.
  • border-color: #2d4a1e and box-shadow: 0 0 0 3px rgba(45, 74, 30, 0.15) on :focus, the green border and the soft green outer glow together make the active field clearly visible. The box-shadow uses the same green as the hero, keeping the palette consistent.
  • resize: vertical on textarea, allows users to drag the textarea taller but not wider. Preventing horizontal resize keeps the form from breaking its layout.
STEP 4

Add the Form HTML

Find the closing </section> of your recipes section and add this HTML right after it:

👉 Add after the closing </section> of #recipes: <section id="community-form">
  <h2>Share Your Recipe</h2>
  <p class="section-intro">Have a traditional recipe or food memory to share? Add it to this community resource.</p>
  <div class="form-wrap">
    <form id="recipe-form">

      <div class="form-group">
        <label for="name">Your Name</label>
        <input type="text" id="name" placeholder="Full name">
      </div>

      <div class="form-group">
        <label for="email">Email Address</label>
        <input type="email" id="email" placeholder="email@example.com">
      </div>

      <div class="form-group">
        <label>How connected do you feel to traditional foods?</label>
        <label class="radio-label">
          <input type="radio" name="connection" value="very"> Very connected
        </label>
        <label class="radio-label">
          <input type="radio" name="connection" value="learning"> Still learning
        </label>
        <label class="radio-label">
          <input type="radio" name="connection" value="new"> Just getting started
        </label>
      </div>

      <div class="form-group">
        <label for="recipe">Share a recipe or food memory</label>
        <textarea id="recipe" placeholder="Describe a traditional dish, where it comes from, or a memory connected to food..."></textarea>
      </div>

      <button type="submit" class="submit-btn">Submit Recipe &rarr;</button>

    </form>
  </div>
</section>

Stage 4 Complete!

The form is built and styled. Right now the submit button reloads the page when clicked, which is the default browser behavior. In Stage 5 you will write your first JavaScript to intercept that click and show a thank-you message instead.

Code Editor
Live Preview