--- layout: post title: "Very Basic Form Styling" date: 2019-11-13 --- Web forms can be great - I'm borderline obsessed with them. I love tinkering with pre-existing logins / sign up pages and I've also open sourced a minimal CSS form-styling plugin: [Normform](https://normform.netlify.com/). While simple CSS plugins like these can be helpful, I often feel like we are over-engineering our web forms. I'm certainly guilty of it. That's not to say developers should just use default browser styling for their forms and call it a day - that is far from ideal. Just pull-back on adding so much styling garbage to the forms themselves. Let's check out an embedded demo below to see what some bare-bones form styling could look like: [Live CodePen Example](https://codepen.io/bradleytaunt/pen/oNwzvMa) This form isn't going to win any design awards or blow anyone away with its creativity. That's okay - because it gets the job done. Users understand it's a form and items are broken down into digestible chunks. Mission accomplished, right? ## Breaking the form down Let's take a look at the HTML of the entire form:
Personal Details

Contact Details

Select an Option

Notifications

Notice the `fieldset` and `legend` elements? I bet you don't see or hear about those HTML items very often. By default, `fieldset` allows sibling or related inputs to be semantically grouped together. The `legend` elements give the user great visual cues about which items are grouped together, helping to focus on each section individually as they complete the form. Use these grouping elements as much as possible (when it makes sense of course) for a better guided experience for your users. Avoid making your own custom sections and instead use these existing HTML semantics. ## Almost no CSS at all Now it's time to style this form with only 6 property declarations: form label { display: block; } form input { display: inline-block; margin-bottom: 10px; padding: 10px; width: 100%; } form input[type="radio"], form input[type="checkbox"], form input[type="reset"], form input[type="submit"] { width: auto; } Of course, you can always add minor adjustments (like in my demo example above) - Legend typeface and sizing - Form and fieldset background colors - Extra margin and padding - Custom reset / submit buttons But the main point of this post is to showcase how little CSS is needed to implement decent web forms - so any further improvements are up to you, dear reader. Just try not to reinvent the wheel. ## Final rant - don't ignore the reset A lot of "modern" web forms have moved away from including the reset input on their forms, which I think is fairly short-sighted. Resetting all form fields might be a smaller edge case, but it is certainly a better option than relying on the user to refresh or in some cases, individually deleting each input. Yikes. Happy form building!