You design a web page with JavaScript by deciding what the page must do, laying out semantic HTML and CSS first, then adding scripts that change that structure and respond to users. The key condition is that JavaScript belongs last in the chain: markup defines meaning, CSS handles appearance, and JavaScript adds behavior, state, and dynamic content. Skipping that order produces pages that break for keyboard users, screen readers, slow connections, and search engines. The steps below walk from a blank folder to a tested, accessible page, with checks at each stage.

Understand the three-layer model before writing code

A web page is three cooperating languages. HTML describes what things are: a heading, a navigation list, a form field, an image. CSS describes how they look. JavaScript describes what happens when states change: a menu opens, a filter narrows a list, a form validates before submission. The browser parses HTML into the Document Object Model, a tree of nodes. JavaScript reaches into that tree through the document object and changes it live.

This model drives the whole workflow. If you build a menu entirely in JavaScript, the links exist only after scripts run. Search crawlers may miss them, and if a script fails the navigation vanishes. If you build it in HTML and use JavaScript only to toggle an attribute, the links survive every failure mode. Most real-world JavaScript bugs are design-order bugs, not syntax bugs.

The reference environment here is evergreen browsers as of late 2026. Modern syntax like ES modules, const/let, arrow functions, and querySelector is safe. Features vary by browser, so check compatibility on a service like MDN or Can I Use before shipping anything exotic.

Step 1: Define the page's job and the JavaScript must-haves

Write one sentence describing the page's purpose and audience, then list the interactive behaviors you actually need. A portfolio page might need a mobile menu, a lightbox for project screenshots, and a contact form with inline validation. That is three JavaScript features. Nothing else should ship in the initial script.

For each feature, decide what happens without JavaScript. A contact form can submit to a server endpoint normally. A menu can be a CSS-only disclosure. A filterable gallery is harder, so decide whether a plain list of all items is an acceptable no-JS fallback. This decision, made before coding, prevents the common trap of retrofitting accessibility and fallbacks into a fully script-built interface.

Also define success: what does a working page look like on a phone, on a keyboard, with a screen reader, and on a slow connection. You will test against these later.

Step 2: Create the project folder and base files

A minimal, well-organized structure looks like this:

index.html — the page markup css/styles.css — presentation js/main.js — behavior, loaded as a module assets/ — images and fonts

Some teams combine CSS and JavaScript into bundlers. For a small page, plain files are simpler, cache well, and need no build step. Open index.html directly in a browser and use the developer tools console to catch errors.

In index.html, start with a valid skeleton: , a lang attribute matching the page language, a , a viewport meta tag, a , and a description. Link the stylesheet in the head and the script at the end of the body, or in the head with the defer attribute. Modules are deferred by default:

Expect this to work immediately: the page renders with no console errors. Check by opening DevTools and confirming the Network tab loads the script with a 200 status.

Step 3: Write semantic HTML for structure and content

Build the whole page in HTML first, with all content present and all controls usable. Use landmarks: , , , , with accessible names where needed. Use one and a logical heading order. Label every form control with a . Use for actions and for navigation. Real buttons are focusable and fire click events from the keyboard for free. Groups of links belong in a . Images need alt text that conveys purpose, or alt="" if decorative. Interactive widgets that JavaScript will enhance should start in their fully functional HTML state. A dialog can be a plain section that is visible; a tab interface can be a list of sections with headings. Then style with CSS, including focus-visible outlines, hover states, and responsive breakpoints. At this point the page should pass a basic audit: tab through it, confirm visible focus, confirm text contrast, and zoom to 200 percent without content loss. Do not write a line of JavaScript yet. Success check: with JavaScript disabled in DevTools, the page's content and primary tasks still work. If they do not, fix the HTML before continuing. Step 4: Add JavaScript progressively, starting with the simplest features Progressive enhancement means each script adds capability on top of a working baseline. Start with the smallest feature, usually a navigation toggle, and make it robust. The pattern: select the button and the target, then toggle a state on the target and an attribute on the button. CSS handles the visual change through [data-open]. The aria-expanded attribute tells assistive technology whether the menu is open. Because the HTML contains real links, the menu works even if the script never loads. Repeat this pattern for each feature: one listener, a class or data attribute for state, ARIA attributes where the widget's state is not communicated by the element itself. Work in small increments and reload the page after each change. If something breaks, you know exactly which edit caused it. The console's error messages, including line numbers, are your fastest diagnostic. Step 5: Manage state separately from the DOM As pages grow past a few interactive bits, ad hoc DOM manipulation becomes fragile. Adopt a simple discipline: keep the data that describes your page in one JavaScript object, and write a function that renders the DOM from that data. For a task list, the state might be an array of objects with id, text, and done. Every user action updates the array and then calls render(). Render rebuilds the list from the array. This makes behavior predictable: there is one source of truth, and the screen always reflects it. This pattern scales further than most beginners expect and is the conceptual core of frameworks like React. If the page later needs server data, fetch it, store the result in state, and render. If it needs persistence, save the state to localStorage on change and load it on startup. These are small additions rather than rewrites because the render function is the single place that touches the DOM. Step 6: Handle events, forms, and user input correctly Event handling is where JavaScript design most often fails users. Three habits prevent most problems. First, delegate. Instead of attaching a listener to every list item, attach one to the list container and use event.target.closest() to find the relevant item. This survives re-rendering and keeps listeners to a minimum. Second, prevent default only when you are replacing native behavior completely. A form submission handler should call event.preventDefault() only when you validate and submit via fetch. If validation fails, show errors next to the fields, move focus to the first invalid field, and keep the form data intact. Third, debounce expensive work like live search filtering. A 200–300 millisecond delay after typing stops is a common starting point; tune it based on how fast results appear. Without debouncing, every keystroke triggers work that can lag on low-end phones. For asynchronous work, use async/await with try/catch. Handle the failure path visibly: a status message that says the save failed and offers a retry. Silent failures are the most damaging kind because users repeat actions and lose data. Success check: submit the form with valid data, invalid data, and no network connection (throttle in DevTools). Each case should produce a clear, visible outcome. Step 7: Build for accessibility from the first commit Accessibility is a design constraint, not a cleanup phase. The essentials for a JavaScript-driven page: Every interactive control must be reachable and operable by keyboard. Focus must be visible and must move sensibly when content changes, such as opening a dialog or removing a list item. Dynamic updates should be announced. A polite live region (aria-live="polite") for status messages is usually enough. Custom widgets need the right roles and states. A disclosure uses aria-expanded; a dialog uses role="dialog", aria-modal, a label, and focus management, or the native element which handles much of this. Never use a as a button. Test with the keyboard alone: Tab, Shift+Tab, Enter, Space, Escape. Then run a screen reader briefly, such as VoiceOver on macOS or NVDA on Windows. You do not need to master assistive technology to catch the common failures: unlabeled buttons, invisible focus, and content that changes without announcement. A useful rule: if you cannot operate the page with the keyboard, redesign before adding features. Keyboard support often reveals structural problems that also affect touch users. Step 8: Optimize performance and loading behavior JavaScript is the most expensive resource a page loads, because the browser must download, parse, and execute it before the page becomes interactive. Keep the initial script small and defer the rest. Practical measures: load scripts as modules or with defer; split large features so a lightbox's code loads only when the lightbox is first opened, using dynamic import(); avoid blocking third-party scripts in the head; and lazy-load images below the fold with loading="lazy". Measure rather than guess. Chrome DevTools' Performance panel and Lighthouse give you a load timeline and a score with specific opportunities. Look for long tasks (over 50 milliseconds) that delay interactivity and for layout shifts caused by content injected after render. Reserve space for anything inserted dynamically so the page does not jump. These numbers vary by device and network, so test on a throttled profile that resembles your users, not just on a fast desktop. Step 9: Test across browsers, devices, and failure conditions Run a short, repeatable checklist before calling the design finished: 1: Load the page on a phone-sized viewport and a desktop viewport. 2: Complete every primary task with the keyboard only. 3: Disable JavaScript and confirm the fallback behavior you designed. 4: Throttle the network to "Slow 3G" and confirm the page is usable while scripts load. 5: Check the console for errors and warnings on every page load. 6: Validate the HTML and run an automated accessibility check, then manually verify its findings. Keep a note of your check results, because a change made later can silently break an earlier state. A small regression list—menu toggle, form validation, filter—takes minutes to re-run and catches most breakage. Step 10: Separate concerns and prepare for growth When a page grows into several pages or many features, structure matters. Split scripts by responsibility: one module for state, one for rendering, one for API calls, one for UI events. Keep configuration like API URLs and timeouts in a single place. Name functions by what they do, not how. If the page needs routing between views, use the History API with pushState and handle the popstate event, or adopt a framework. Frameworks are appropriate when the app has many interacting views and shared state. They are overkill for a brochure page with a menu and a form, where added dependencies cost load time and complexity. The decision should come from the project's actual needs, not from what is popular. Finally, document the page's behaviors and the decisions behind them, especially fallbacks and accessibility measures. A short README with the feature list, the no-JS behavior, and the test checklist helps anyone who maintains the page later, including future you. Common failure cases worth knowing A handful of mistakes account for most broken JavaScript pages. Scripts placed in the head without defer run before the DOM exists, so querySelector returns null and the first line throws. Always load scripts after the markup or defer them, and guard selections when an element may be absent. Another common failure is relying on innerHTML for user-supplied content, which opens cross-site scripting holes. Use textContent for text and createElement for structure. If you must insert HTML, sanitize it with a maintained library. Listeners accumulating on re-render cause duplicate actions; delegation and removing listeners when nodes are discarded prevent this. And state that lives only in the DOM—reading values back from elements to decide the next action—becomes impossible to reason about. Keep the source of truth in JavaScript. FAQ Do I need a framework to design a web page with JavaScript? No. A page with a few interactive features is faster, lighter, and easier to maintain with plain JavaScript. Adopt a framework when you have many views sharing complex state. Should JavaScript go in the head or the end of the body? Either works if it is deferred. Modules are deferred by default; classic scripts should use defer or sit at the end of the body. How much JavaScript is too much? There is no fixed number, but if the page cannot complete its main task with JavaScript disabled and the task does not inherently require scripting, reconsider the design. Otherwise, watch load and interactivity timings on a throttled connection rather than counting bytes. How do I keep a JavaScript-heavy page accessible? Start with semantics, make state changes explicit with ARIA attributes, manage focus on content changes, and test with a keyboard and a screen reader before shipping. Accessibility checks are cheapest when they run every time, not once.