Code
index.html — the page skeleton
We start with index.html — the page skeleton. The full file is in the code column; it's small, but every line matters.
A few parts:
<!DOCTYPE html>— tells the browser to use modern ("standards") mode. Without it, the browser drops into an old compatibility mode.data-theme="dark"on<html>— our theme. The CSS reacts to it; we'll add the theme toggle later.<meta name="viewport">— so the page looks right on a phone (for responsiveness).<link rel="stylesheet" href="style.css">— loads the styles.style.cssis provided with the project (~800 lines). You built its foundation in the HTML and CSS foundations track; this one hands you the finished sheet so the focus stays on JavaScript. Just place it next toindex.html.<main id="app">— the container JavaScript will render into. For now it holds "Loading Cosmos…".<script type="module" src="js/main.js">— loads our JavaScript.type="module"is the crucial part: it makes the file an ES module, somain.jscanimportother files. Withouttype="module",importwouldn't work.
The structure is always the same: index.html is the one and only page (this will be a single-page app — an SPA), and JavaScript drives all the content.
Tip. Why is
<script>at the end of<body>(not in<head>)? So the browser creates<main id="app">first, then runsmain.js, which looks for it. Withtype="module"this is automatic (modules run after the HTML is parsed), but keeping the script at the end is a good habit.