Chapter practice task
Task: Add dark mode and a validated contact form to your portfolio
- Move your colors into CSS variables and add a dark theme.
- Add a toggle button that switches themes and remembers the choice.
- Respect the visitor’s system setting on their first visit.
- Validate your contact form fields when the visitor submits.
- Show clear error messages next to each field and announce them to screen readers.
By the end of this chapter
- You can build a dark mode toggle that respects system settings and remembers choices
- You can validate forms with built-in HTML rules and custom JavaScript checks
- You can show accessible error messages
Quick answers for this chapter
Is dark mode worth adding?
For portfolios, blogs and tutorial sites, yes. Many people browse in dark mode, especially at night.
Is JavaScript validation enough?
No. It improves the experience, but the server must always check the data again.
Can I validate without JavaScript?
Partly. HTML attributes like required and type="email" give basic validation for free.