Browser DevTools is your most powerful ally as a web developer. Whether you're debugging a broken layout, tracing a network failure, or profiling performance — DevTools has a panel for it. Mastering these tools will dramatically accelerate your development workflow.
Opening DevTools
| Browser | Shortcut (Mac) | Shortcut (Windows) |
|---|---|---|
| Chrome/Edge | Cmd+Option+I | Ctrl+Shift+I |
| Firefox | Cmd+Option+I | Ctrl+Shift+I |
| Safari | Cmd+Option+I | Enable in Preferences first |
Right-click any element and select "Inspect" to jump directly to that element in the Elements panel.
DevTools Panels Overview
| Panel | Purpose | Key Features |
|---|---|---|
Elements | Inspect and edit DOM/CSS | Live CSS editing, computed styles, box model |
Console | JavaScript REPL and logging | console.log(), errors, warnings, evaluation |
Sources | Debug JavaScript | Breakpoints, call stack, watch expressions |
Network | Monitor HTTP requests | Request/response, timing, filtering |
Performance | Profile runtime performance | Recording, flame charts, FPS |
Application | Storage and service workers | Cookies, localStorage, cache |
Elements Panel
The Elements panel shows the live DOM tree. You can inspect any element, edit HTML directly, and modify CSS in real-time to experiment with styles.
Inspecting Elements
- Use the selector tool (
Cmd+Shift+C) to click any element on the page - Navigate the DOM tree using arrow keys
- Edit HTML by double-clicking any element or pressing
F2 - Add/remove classes in the Styles pane to test changes
CSS Debugging
| Feature | Location | Usage |
|---|---|---|
| Computed Styles | Computed tab | See final calculated values |
| Box Model | Styles pane bottom | Visualize margin, padding, border |
| Filter Styles | Filter input | Search for specific properties |
| Toggle Properties | Checkbox next to rule | Enable/disable individual CSS rules |
Changes made in DevTools are temporary — they'll reset when you refresh. Use "Local Overrides" to persist changes during development.
Console Panel
The Console is a JavaScript REPL (Read-Eval-Print-Loop). You can execute code, view logs, and debug errors — all in real-time.
Console Methods
// Basic loggingconsole.log("Regular message");console.warn("Warning message");console.error("Error message");// Structured outputconsole.table([{name: "Alice", age: 25}, {name: "Bob", age: 30}]);console.group("Group label");console.log("Inside group");console.groupEnd();// Timingconsole.time("fetch");await fetch("/api/data");console.timeEnd("fetch"); // fetch: 123.45ms
Console Shortcuts
| Shortcut | Action |
|---|---|
$0 | Reference the currently selected element in Elements panel |
$_ | Result of last evaluated expression |
$("selector") | Shorthand for document.querySelector() |
$$("selector") | Shorthand for document.querySelectorAll() |
clear() | Clear the console |
Network Panel
The Network panel records all HTTP requests made by the page. Use it to debug API calls, analyze load times, and identify failed requests.
Request Analysis
- Check the checkbox to "Preserve log" across navigations
- Use the filter bar to search by URL, method, or status
- Click any request to see Headers, Preview, Response, and Timing tabs
- Red requests indicate failures (
4xx,5xxstatus codes)
| Filter | Shows |
|---|---|
XHR | Only AJAX/fetch requests |
JS | JavaScript files |
CSS | Stylesheets |
Img | Images |
status-code:404 | Only 404 responses |
method:POST | Only POST requests |
Timing Breakdown
| Phase | Description |
|---|---|
Queuing | Time waiting in browser queue |
Stalled | Time waiting to send (connection limits) |
DNS Lookup | Domain resolution time |
Initial Connection | TCP handshake |
SSL | TLS negotiation |
TTFB | Time to First Byte (waiting for server) |
Content Download | Receiving response body |
Sources Panel & Debugging
The Sources panel lets you debug JavaScript with breakpoints, step through code line by line, and inspect variable values.
Breakpoint Types
| Type | How to Set | Use Case |
|---|---|---|
| Line Breakpoint | Click line number | Pause at specific line |
| Conditional | Right-click line → Add conditional | Pause only when condition is true |
debugger statement | Add debugger; in code | Programmatic breakpoints |
| DOM Breakpoint | Elements → Right-click → Break on | Pause when DOM changes |
| XHR/Fetch | Sources → XHR Breakpoints | Pause on specific URLs |
// Programmatic breakpointfunction processData(items) {debugger; // Execution pauses herereturn items.filter(item => item.active);}
Remember to remove debugger; statements before pushing code to production!
Hands-On: Debugging Practice
Exercise: Inspect and Modify Styles
- Open DevTools on any website (
Cmd+Option+I) - Select an element using the selector tool
- In the Styles pane, add a new CSS property:
border: 2px solid red - Toggle the property on/off using the checkbox
- View the Computed tab to see the final styles
Exercise: Debug a Network Request
- Open the Network panel
- Enable "Preserve log" checkbox
- Navigate to any website
- Click on the main document request (usually the first one)
- Examine: Headers tab, Response tab, Timing tab
- Identify the TTFB (Time to First Byte)
Exercise: Console Exploration
- Open Console panel
- Type
document.titleand press Enter - Use
$$("a")to select all links on the page - Try
console.table($$("a").map(a => ({text: a.textContent, href: a.href})))