Skip to Content
ExamplesVanilla Contact Form

Vanilla Contact Form

A contact form that collects a name, email, and message, validates the input, and stores submissions in a JavaScript array. Zero dependencies — just open index.html in a browser.

How it works

The form listens for submit, prevents the default reload, validates that no fields are empty, and pushes the entry into a submissions array. Each submission renders into a list below the form so you can see it immediately.

contact-form/ ├── index.html ← form markup + submissions list ├── style.css ← centered card layout └── app.js ← validation, storage, rendering

index.html

Semantic form with three fields and a <ul> below it to render submissions. novalidate lets us handle validation in JS. aria-live="polite" on the status paragraph tells screen readers to announce changes.

index.html

style.css

System font stack, centered card layout, and simple focus styles. The submissions list sits below the form with a top border to separate the two sections.

style.css

app.js

FormData grabs every field by its name attribute. Object.fromEntries() converts it to a plain object. After validation, the entry gets pushed into a submissions array and rendered into the list below the form.

app.js

Run it

mkdir contact-form && cd contact-form # create the three files above open index.html

No server needed — just open the HTML file in a browser. Submissions live in memory and render below the form.

Last updated on