Before you start
A computer, browser and code editor
The lessons are free. You can work locally without buying hosting.
- 01
Write the page first
Pick a small subject, like a recipe or a page about your hobby.
Text basicsDave GrayTry it
Open the starter in your editor. Replace the title and heading, then add a short introduction, a list and one useful link.
Open index.html in your browser. Read it before styling it. The order should make sense.
Use a link people can understand
<a href="https://developer.mozilla.org/en-US/docs/Learn_web_development">Learn web development on MDN</a>Name where the link goes. A reader should not need the words around click here to understand it.
- 02
Give the page some space
Use a small set of colours and keep the text easy to read.
The box modelDave GrayTry it
Add padding around the page, a maximum width for the text and space between sections. Give links a visible style.
The page should still work if you make the text larger. Keep the browser's focus outline.
A small starting point
body { max-width: 44rem; margin: 2rem auto; padding: 1rem; line-height: 1.6; } a { text-underline-offset: 0.2em; }A maximum width stops paragraphs stretching across a large screen. Padding leaves room at the edges on a phone.
- 03
Check the narrow version
Dragging the browser edge is enough to catch a lot of problems.
Media queriesDave GrayTry it
Shrink the window to about 320 pixels. Fix any image, long word or fixed-width box that makes the page scroll sideways.
You should be able to read every line and reach every control without dragging sideways.
Let images shrink
img { max-width: 100%; height: auto; } .long-link { overflow-wrap: anywhere; }Check the actual cause before hiding overflow on the whole page. Hiding it can also hide content.
- 04
Add one useful interaction
Use a real button. The browser already knows how to handle keyboard input for it.
Event listenersDave GrayTry it
Add a button that shows and hides a short note. Update aria-expanded so its state is clear to assistive technology.
Click it, then try Tab and Enter. Open and close it several times.
See a complete example
<button type="button" aria-expanded="false" aria-controls="note">Show note</button> <p id="note" hidden>Your note goes here.</p> <script> const button = document.querySelector("button"); const note = document.querySelector("#note"); button.addEventListener("click", () => { note.hidden = !note.hidden; button.setAttribute("aria-expanded", String(!note.hidden)); button.textContent = note.hidden ? "Show note" : "Hide note"; }); </script>Put the script after the button and note. There is no library to install for this.
Check your result
Open your page on a narrow screen and use it with the keyboard.
- The page has one main heading and working links.
- It fits a 320-pixel-wide window without sideways scrolling.
- Tab reaches every link and button, with a visible focus outline.
- The button works with Enter and Space.
What to do next
Remember a theme choice after a reload. Keep private information out of local storage.
Save a setting in the browserPractice by Abdulrhman Sayed. Video lessons belong to the credited creators.
