Beginner · How the web works · topic 4 of 64 · 25 min
Browser DevTools: look inside any page
Explanation
Opening DevTools
On a laptop, press F12 or Ctrl+Shift+I (Cmd+Option+I on Mac), or right-click any part of a page and choose Inspect. DevTools opens next to the page.
The main panels
| Panel | What it shows | Use it to |
|---|---|---|
| Elements | The live HTML and the CSS of the selected element | Find why something looks wrong; try CSS changes live |
| Console | Messages and errors from JavaScript | Read errors; try small bits of JavaScript |
| Network | Every file and request the page makes | See slow files, 404s and API data |
| Application | Storage such as cookies and localStorage | Check saved data |
| Lighthouse | An automatic report on speed, accessibility and SEO | Find what to improve |
The Console
Your code can write messages to the Console with console.log(). Errors show up in red with the file name and line number. Reading the error message is the fastest way to fix a bug.
const prices = [120, 80, 50];
console.log('Number of items:', prices.length);
console.table(prices);
// A typo makes a red error in the Console:
// console.log(price); -> ReferenceError: price is not definedDevice mode
The phone-and-tablet icon (Ctrl+Shift+M) shows how the page looks on a phone screen. Most visitors in India use phones, so check every page in device mode.
Debugging step by step
- Read the error in the Console: what and which line.
- Add console.log() before the line to see the real values.
- Compare what you expected with what you see.
- Fix one thing, save, reload, check again.
Watch the lesson
Browser DevTools: look inside any page · 1/6
Every browser hides a powerful toolbox. Press F12 or right-click and choose Inspect.
Prefer a video by a teacher? Find free videos on “chrome devtools tutorial for beginners” on YouTube ↗
In real life: Why is the "Pay" button hidden on mobile?
A tester reports that the Pay button of a fee payment page is missing on phones. The developer opens DevTools, switches to device mode, inspects the button and sees a CSS rule "display: none" inside a media query for small screens. She unticks it in DevTools to confirm, then fixes the rule in the CSS file.
Practice (0/2 done)
Open any website on a laptop, open DevTools and explore. Change the text of a heading in the Elements panel, change a colour in the Styles pane, type 2 + 2 in the Console, and reload the page with the Network panel open.
This function should add up all prices in a cart, but it has a bug: it skips the last item. Find and fix it, so cartTotal([120, 80, 50]) returns 250.
Quick quiz
Read more (free)
Pass the quiz (60% or more) or mark this topic as done when you are ready.
Your progress is saved on this device only.