Introduction to Chrome DevTools
Chrome DevTools is a set of web developer tools built directly into the Google Chrome browser. It provides deep access into the internals of any web application, letting you inspect the DOM, debug JavaScript, analyze network requests, audit performance, and much more. Mastering DevTools is one of the highest-leverage investments you can make as a frontend developer.
Opening DevTools
- Mac:
Cmd + Option + I(or right-click and select "Inspect") - Windows/Linux:
Ctrl + Shift + IorF12 - Open to specific panel:
Cmd + Shift + Copens Elements with the element picker active - Command Palette:
Cmd + Shift + Pinside DevTools to search all commands
The Elements Panel
The Elements panel is your window into the live DOM tree and the computed CSS for any element on the page. You can edit HTML in real time, toggle CSS properties, add new styles, and see changes instantly reflected in the browser viewport. This is essential for debugging layout issues, tweaking designs, and understanding how styles cascade.
Key Features in Elements
- DOM Tree Navigation: Click any element to inspect it. Use arrow keys to navigate the DOM hierarchy. Press
Enterto edit an attribute,F2to edit as HTML. - Computed Styles: The Computed tab shows the final resolved value for every CSS property, including inherited styles and the box model visualization.
- CSS Grid and Flexbox Overlays: Click the grid or flex badge next to any element using those layout modes to visualize tracks, gaps, and alignment.
- Event Listeners: The Event Listeners tab shows all JavaScript event handlers attached to the selected element, with links to the source code.
- DOM Breakpoints: Right-click an element and set a breakpoint for subtree modifications, attribute changes, or node removal to catch scripts that mutate the DOM.
# Useful keyboard shortcuts in Elements panel
# H - Toggle element visibility (sets display:none)
# Delete - Delete the selected element
# Cmd+Z - Undo DOM changes
# Cmd+F - Search the DOM by string, CSS selector, or XPath
# Ctrl+Shift+C - Activate element picker to click-select on page
The Console Panel
The Console is far more than a place to read console.log output. It is a fully interactive JavaScript REPL connected to the current page context. You can query the DOM, invoke functions, inspect objects, monitor events, and even run async operations.
Console Utilities
// $0 refers to the currently selected element in the Elements panel
$0.style.border = '2px solid red';
// $() is shorthand for document.querySelector()
$('.my-class');
// $$() is shorthand for document.querySelectorAll() returning an array
$$('div.card').length;
// $_ refers to the result of the last evaluated expression
2 + 2;
$_; // 4
// copy() copies any value to clipboard
copy(JSON.stringify($$('a').map(a => a.href)));
// monitor() logs every call to a function
function fetchData() { /* ... */ }
monitor(fetchData); // "function fetchData called"
// monitorEvents() logs events on an element
monitorEvents($0, 'click');
// unmonitorEvents($0) to stop
// queryObjects() finds all instances of a constructor
queryObjects(Promise); // all Promise instances in memory
// console.table() displays data as a sortable table
console.table([
{ name: 'React', version: '18.2' },
{ name: 'Next.js', version: '14.0' },
]);
The Sources Panel
The Sources panel is a full-featured debugger and code editor. You can set breakpoints, step through code, inspect variables, and even edit source files with Workspaces to persist changes to disk.
Breakpoint Types
- Line Breakpoints: Click the line number gutter. The debugger pauses before that line executes.
- Conditional Breakpoints: Right-click the gutter and add a condition. Pauses only when the expression is truthy.
- Logpoints: Right-click the gutter and choose "Add logpoint." Logs a message without pausing execution.
- XHR/Fetch Breakpoints: Pause on any network request whose URL contains a specified string.
- Event Listener Breakpoints: Pause when specific events fire (click, scroll, keypress, etc.).
- Exception Breakpoints: Pause on caught or uncaught exceptions to find error origins.
Debugging Keyboard Shortcuts
# Debugger stepping controls
F8 / Cmd+\ - Resume / pause execution
F10 / Cmd+' - Step over (next line)
F11 / Cmd+; - Step into (enter function)
Shift+F11 - Step out (exit current function)
Cmd+Shift+P - Command palette (search any action)
The Application Panel
The Application panel provides tools for inspecting all forms of browser storage and Progressive Web App features. Here you can view and edit localStorage, sessionStorage, IndexedDB, cookies, cache storage, and service worker registrations.
- Local Storage / Session Storage: View, edit, and delete key-value pairs. Double-click a value to modify it in place.
- Cookies: View all cookies for the current domain with their attributes (HttpOnly, Secure, SameSite, Expiry). Filter and delete individual cookies.
- IndexedDB: Browse object stores, query by key range, and inspect complex stored objects.
- Service Workers: See registered workers, trigger push events, test offline mode, and force updates.
- Cache Storage: Inspect cached assets from service worker caching strategies.
Advanced DevTools Features
Device Mode and Responsive Design
Toggle device mode with Cmd + Shift + M to simulate mobile viewports. You can select predefined devices (iPhone, iPad, Pixel), set custom dimensions, throttle the network and CPU, and simulate touch events. The ruler overlays help you verify breakpoints and spacing.
Workspaces for Live Editing
DevTools Workspaces let you map local source files to the page, so changes you make in the Sources or Elements panel are saved directly to disk. This turns DevTools into a real code editor for CSS and JavaScript tweaking.
Local Overrides
If you cannot set up Workspaces (e.g., on a production site you do not control), use Local Overrides. Go to Sources > Overrides, select a local folder, and any file you edit will be served from your override instead of the network. This persists across page reloads and is invaluable for debugging production issues.
Snippets
Snippets are reusable scripts you can save and run from the Sources panel. Use them for common tasks like clearing all cookies, extracting page data, or injecting debug utilities. They persist across browser sessions.
// Example Snippet: Log all images on a page with their sizes
const images = document.querySelectorAll('img');
const data = Array.from(images).map(img => ({
src: img.src,
naturalWidth: img.naturalWidth,
naturalHeight: img.naturalHeight,
displayWidth: img.width,
displayHeight: img.height,
alt: img.alt || '(no alt)',
}));
console.table(data);
DevTools Settings and Customization
Press F1 inside DevTools to open Settings. Key configuration options include:
- Theme: Switch between light, dark, and system themes.
- Experiments: Enable experimental features like CSS Overview, full-page accessibility tree, and new performance panel features.
- Ignore List: Add patterns to blackbox third-party scripts during debugging (e.g.,
node_modules, framework internals). - Shortcuts: Customize keyboard shortcuts or switch between DevTools default and VS Code keybindings.
- Network: Enable persistent logs, disable cache, and configure throttling profiles.
Pro Tips
- Color Picker: Click any color swatch in the Styles panel to open the color picker. Hold Shift and click to cycle through color formats (hex, RGB, HSL).
- Screenshot: Use the Command Palette (
Cmd+Shift+P) and type "screenshot" to capture the full page, visible viewport, a specific node, or area. - Design Mode: Run
document.designMode = 'on'in the Console to make the entire page content-editable. - Force Element State: Right-click an element in Elements panel and force
:hover,:active,:focus, or:visitedstates for CSS debugging.