Building a dark mode switch in three boxes
A playground is the quickest way to see how HTML, CSS and JavaScript split the work of a page. Here is one small feature built from nothing: a button that switches a card between light and dark. Each box does one job, and the order you write them in shows why.
Start with the HTML box. Type <div class="card"><h2>Notes</h2><p>Three things to buy.</p><button id="mode">Dark mode</button></div>. The preview shows plain black text and a grey button. That is the content and its structure, with no look and no behaviour yet. A screen reader or a search engine already gets everything it needs from this.
Now the CSS box. Type .card { padding: 16px; border-radius: 8px; background: white; color: black; } and then .card.dark { background: #222; color: #eee; }. The card gets padding and rounded corners at once, because CSS re-renders as you type. The second rule does nothing yet, because no element has the class dark. That is the idea to hold on to: the CSS describes both looks in advance, and the script only has to choose between them.
Last, the JavaScript box. Type const card = document.querySelector('.card'); and then document.getElementById('mode').addEventListener('click', () => { const on = card.classList.toggle('dark'); console.log('dark is', on); });. Press Run. Click the button in the preview and the card turns dark; click again and it turns back. The Console shows "dark is true" and then "dark is false", because classList.toggle returns whether the class is now present. Notice the script never sets a colour. It flips one class, and the CSS does the rest. Keeping the look in CSS like this means a designer can change both colours without touching the script.
A mistake teaches as much. Change getElementById('mode') to getElementById('moed') and press Run. The Console shows an Uncaught TypeError, because getElementById found nothing and returned null, and null has no addEventListener. The message names the line of your script it came from, which is the line to fix.
This playground has limits. It does not load anything from the network, so a framework from a CDN, a web font or an image by URL will not work; the Console says so when something is blocked. There is no npm and no build step, so TypeScript, JSX and import statements for packages do not work. The editor is a plain text box with no autocomplete or syntax colours. An endless loop can freeze the tab. Nothing is saved, so keep a copy of anything you want to keep.