Build a CSS Property Fandom Survey
Goal: Build a playful survey form about favorite CSS properties while learning form structure, input types, and validation. We know you have opinions about CSS properties. This is a safe space to share them.
What you'll learn:
Goal: Create your first form with properly associated labels and inputs.
Forms collect user input. Every input needs a labelβnot just for sighted users, but for screen readers and form autofill. Let's start with the basics.
π Research checkpoint: Read MDN: Your first form.
Key concepts to understand:
<form> β Container for all form elements<label> β Descriptive text for an input<input> β Field where users enter datafor attribute β Connects label to input via idfor attribute matches an input's id, clicking the label focuses the input. This is crucial for accessibility and makes forms easier to use on mobile!
Your task: In the CodePen workspace, add two form fields inside the <form id="property-survey">.
id="name"for="name" that says "Your name (or alias)"id="email" and type="email"for="email" that says "Email (for CSS newsletter)"Structure each label/input pair in a container:
<div class="form-group">
<label for="name">Your name (or alias)</label>
<input type="text" id="name" name="name">
</div>
<div class="form-group">
<label for="email">Email (for CSS newsletter)</label>
<input type="email" id="email" name="email">
</div>
name attribute is what gets sent to the server when the form submits. It's different from id (which is for label association). You often make them the same for simplicity.
<form> wrapper with id="property-survey"for="name"type="email" and matching labelClick on a label. What happens? Why does this matter for accessibility and mobile users?
Goal: Create a radio button group with proper semantic structure.
Radio buttons let users pick one option from a set. They need special structure: a <fieldset> to group them, a <legend> to describe the group, and matching name attributes.
π Research checkpoint: Read MDN: Radio buttons.
Key concepts:
<fieldset> β Groups related form controls together<legend> β Provides a caption for the fieldsetname attributeid for its labelname, the browser knows they're mutually exclusiveβselecting one automatically deselects the others.
Your task: Add a radio button group to your form.
<fieldset> after your email input<legend> that says "How did you discover your favorite CSS property?"name="discovery"id and valuefor attributechecked on one radio by defaultRadio button options (pick 3-4):
Example structure:
<fieldset>
<legend>How did you discover your favorite CSS property?</legend>
<div class="form-group">
<input type="radio" id="tutorial" name="discovery" value="tutorial" checked>
<label for="tutorial">A tutorial showed me the way</label>
</div>
<div class="form-group">
<input type="radio" id="stackoverflow" name="discovery" value="stackoverflow">
<label for="stackoverflow">Stack Overflow called to me</label>
</div>
<!-- more radios -->
</fieldset>
name="discovery"id, value, and labelchecked by defaultTry selecting different radios. What happens to the previously selected one? Why do radios need matching name attributes?
Goal: Add checkboxes to let users select multiple favorite properties.
Unlike radios, checkboxes allow multiple selections. Each checkbox needs its own unique name and value.
π Research checkpoint: Read MDN: Checkboxes.
Key difference from radios:
name, pick onename, pick manyYour task: Add a checkbox group to your form.
<fieldset> after your radio group<legend>: "Which properties spark joy? (select all that apply)"checkboxname (e.g., name="flexbox", name="grid")id and meaningful valueforCSS property options (use all 6):
flexbox β "flexbox β The Container Whisperer"grid β "grid β The Layout Legend"border-radius β "border-radius β The Corner Softener"box-shadow β "box-shadow β The Depth Maker"hover β ":hover β The Interaction Enchanter"transition β "transition β The Smooth Operator"Example structure:
<fieldset>
<legend>Which properties spark joy? (select all that apply)</legend>
<div class="form-group">
<input type="checkbox" id="flexbox" name="flexbox" value="flexbox">
<label for="flexbox">flexbox β The Container Whisperer</label>
</div>
<div class="form-group">
<input type="checkbox" id="grid" name="grid" value="grid">
<label for="grid">grid β The Layout Legend</label>
</div>
<!-- more checkboxes -->
</fieldset>
name and idvalue attributeWhen would you use radio buttons vs checkboxes? Give a real example for each.
Goal: Add a dropdown menu (select) and a multi-line text area.
Sometimes you have too many options for radio buttons, or you need longer text input.
π Research checkpoints:
When to use each:
Your task: Add a <select> dropdown after your checkbox group.
<select> with id="favorite" and name="favorite"value=""<option> elements (use the same properties from your checkboxes)Example:
<div class="form-group">
<label for="favorite">Your desert island CSS property?</label>
<select id="favorite" name="favorite">
<option value="">Select one...</option>
<option value="flexbox">flexbox</option>
<option value="grid">grid</option>
<option value="border-radius">border-radius</option>
<option value="box-shadow">box-shadow</option>
<option value="hover">:hover</option>
<option value="transition">transition</option>
</select>
</div>
value="" acts as a placeholder. We'll use this later for validation!
Your task: Add a <textarea> for longer text input.
<textarea> with:
id="love-letter" and name="love-letter"rows="5" to set the heightplaceholder with hint textExample:
<div class="form-group">
<label for="love-letter">Write a 3-sentence love letter to your favorite CSS property</label>
<textarea
id="love-letter"
name="love-letter"
rows="5"
placeholder="Why does it spark joy? What did it unlock for you?"></textarea>
</div>
for/idvalue=""for/idrows attributeWhy use a textarea instead of a regular text input? What's gained by having multiple lines?
Goal: Add native HTML validation and a submit button.
HTML has built-in validationβno JavaScript required. Let's use it!
π Research checkpoint: Read MDN: Client-side form validation.
Your task:
required to your name and email inputstype="email" (enables email validation)required to your dropdown (the empty first option allows validation)<button type="submit">Submit Your Survey</button>Example:
<div class="form-group">
<label for="name">Your name (or alias)</label>
<input type="text" id="name" name="name" required>
</div>
<div class="form-group">
<label for="email">Email (for CSS newsletter)</label>
<input type="email" id="email" name="email" required>
</div>
<!-- At the end of your form -->
<button type="submit">Submit Your Survey</button>
Take your form to the next level with these enhancements:
minlength="50" to your textarea to require thoughtful responsesmaxlength="300" to prevent novelspattern attribute for custom validation (e.g., must start with capital letter):focus or :focus-visible in CSS:invalid pseudo-classBonus CSS to try:
input:focus,
select:focus,
textarea:focus {
outline: 2px solid #3b82f6;
outline-offset: 2px;
}
input:invalid {
border-color: #ef4444;
}
input:valid {
border-color: #10b981;
}
More ideas to try in your CodePen:
min="1" and max="10"<input type="range"><input type="date"><input type="color"> for "Pick your favorite CSS color"disabled and readonly attributesWhy rely on native HTML validation instead of JavaScript? What are the trade-offs?
Save your reflections directly in your CodePen HTML so they're preserved with your work.
π Steps:
</form> tag)Code along as you follow the tutorial β