Sub topic 1
Opening DevTools and Finding Your Way Around
Prerequisites
This chapter assumes basic HTML, CSS, JavaScript, browser loading, and HTTP request knowledge.
Opening DevTools and Finding Your Way Around
Browser developer tools, or DevTools, are built-in panels for inspecting and diagnosing a web page. In a Chromium-based browser, open them with F12, Ctrl+Shift+I on Windows and Linux, or Cmd+Option+I on macOS. You can also right-click a page and choose Inspect.
The main panels are:
- Elements: the page’s live DOM (Document Object Model) and CSS.
- Console: JavaScript expressions, logs, warnings, and errors.
- Sources: JavaScript files, breakpoints, and step-by-step debugging.
- Network: requests, responses, timing, and caching.
- Application: cookies, storage, and service workers.
- Performance and Memory: runtime and memory analysis.
Panel names and shortcuts can vary slightly between browsers. The central workflow is the same: choose the panel that exposes the part of the page you need to examine.
Inspecting and Editing the DOM
The Elements panel shows the DOM tree: the browser’s current object representation of the HTML. Click the element-picker icon, then select something on the page. DevTools highlights the matching node and shows its attributes and children.
You can edit text, attributes, and element structure directly. These edits are temporary and disappear when the page reloads. Use them to test a hypothesis before changing source code.
Debugging CSS: Styles, Computed Values and the Box Model
The Styles pane lists rules that match the selected element. Uncheck a declaration to test its effect, or add a new declaration. Crossed-out declarations lost the cascade, often because another rule has higher specificity or appears later.
The Computed pane shows the final value for each property after inheritance and the cascade. The box model diagram shows content, padding, border, and margin. If an element is the wrong size or position, inspect these values first.
Exercise
A button is 20 pixels wider than expected. Which DevTools area should you inspect first?
Show answer
Select the button in Elements and inspect the box model and Computed values, especially padding, border, width, and box-sizing.