Form Styling (part 1) (9-4-2026) | CIS311
Overview
Kenan Casey builds a form-styling example using modern CSS features, including custom properties, `color-scheme`, `color-mix()`, `accent-color`, logical sizing, and `field-sizing: content`. Along the way, he styles labels and controls, improves responsive form width and spacing, and addresses practical details such as iOS input zoom and Firefox placeholder opacity.
Key takeaways
- HTML `required` provides built-in browser validation without JavaScript, though the appearance of the validation popup varies by browser.
- The combination of `color-scheme: light dark` with `Canvas` and `CanvasText` makes form surfaces and text respond to the user's system theme.
- `color-mix(in lch, ...)` can produce theme-aware muted text and border colors by blending system colors in a perceptual color space.
- Using `max-inline-size: 40ch` and grid `gap` creates a readable form layout with spacing that does not depend on fixed pixel widths.
- For iOS Safari, setting control text to at least 16 pixels prevents the browser's automatic zoom when users focus a field.
- Textarea `field-sizing: content` can make a text area expand with its content, while `min-block-size`, `max-block-size`, and `lh` units help control its dimensions.
Chapters
- The example form uses `action` and `method="post"`, with each label and control grouped in a `.field` div.
- HTML `required` triggers browser-native validation without JavaScript; the form also includes email input, a select, radio buttons, a textarea, and a submit button.
- Kenan Casey links a stylesheet, sets `box-sizing: border-box`, chooses the system UI font, and recommends images use `display: block` and `max-width: 100%`.
- A `:root` block defines reusable CSS variables with `--name` syntax and references them using `var(--name)`.
- The brand color uses HSL values `155 45% 32%`; the danger and focus colors use separate HSL values for errors and focused controls.
- Kenan favors modern space-separated color components over comma-separated HSL syntax.
- Setting `color-scheme: light dark` lets browser-provided foreground and background colors adapt to the user's operating-system theme.
- The `Canvas` and `CanvasText` system colors provide theme-aware surface and text values that can be stored in CSS variables.
- Kenan uses `color-mix(in lch, ...)` to create muted text and border colors, blending theme-aware colors in a perceptual color space.
- Applying `accent-color: var(--brand)` to the form changes the built-in color of radio buttons and checkboxes.
- The same property can also affect controls such as range sliders and progress bars, helping native elements match the site's brand.
- Setting the form to `display: grid` with `gap` adds consistent spacing between its child fields.
- A `max-inline-size` around `40ch` limits line length using a text-relative unit rather than a fixed pixel width.
- Each `.field` uses its own grid and gap to space labels, controls, and help or error text; logical sizing properties adapt to writing direction.
- Labels receive a heavier font weight, while hint text uses the muted color variable and a smaller font size.
- Text inputs, selects, and textareas get padding, a subtle theme-aware border, a surface background, and rounded corners.
- Using `font-size: max(1rem, 16px)` keeps controls at least 16 pixels tall in text size, avoiding Safari on iOS zooming in when a field is tapped.
- The `::placeholder` pseudo-element can style placeholder text independently, including using the muted color variable.
- Firefox applies its own placeholder opacity, so explicitly setting `opacity: 1` can make placeholder styling consistent with Chrome.
- Kenan finds a hover background distracting during typing and demonstrates adding example placeholders such as “John Smith.”
- A textarea can use `min-block-size` and `max-block-size` instead of physical height properties, with `lh` units sizing it in line heights.
- Setting `field-sizing: content` lets the textarea grow with its text, while a maximum block size limits its growth and allows internal scrolling.
- The example starts at roughly three lines and grows toward a 12-line maximum; the native resize handle can still change its size.
Transcript excerpt
0:04 Okay, I wanted to walk through some examples of styling forms, specifically highlighting some new CSS that exists now that didn't five years ago. uh and therefore I didn't cover in intro to web design. So I'm learning some new CSS as well uh specifically in the context of form design and we'll hit on some some other stuff as well. [clears throat] So let's jump in and then see what we can learn. Let's see. Would you like to
0:52 follow along? Are you follow alongers? Um, what if I were to send you these two files on Discord? Would would that work? So, this is this would be following along in order to learn. That's fair, Emily. It's fair. You're You're a Discord hater. Oh, okay. Well, then I can just make an announcement. Is that easier? Okay. If I send uh
1:42 if I send an announcement that has attachments, does it um does it download the Does it send it in the email? That's what I want to say. How dare you? Wait, sorry. This is Discord. Can I only attach one attachment? Canvas Google Classroom would not have done that to me. That's a
2:35 [clears throat] Okay. So, while that's going through, um, wanted to just let's just note the structure and what some of this markup is. Oh, did I? So we have a form that has an action and a method just like before where our method method is almost always going to be post on a form and the action is going to be the URL on the server that receives the output of this form.
3:23 Um, we've got several input elements that are surrounded by a div with a class of field that then is grouping together the label and the actual input or whatever the
This is the start of the transcript. Save this video free for the whole transcript, searchable and time-coded.
In this course
Related notes
Summary, takeaways, and chapters were generated by AI from the video's transcript and may contain errors. The video belongs to its creator, Kenan Casey.