Tips・Browser dev tools

Getting started with developer tools

That screen that pops up on right-click → "Inspect"? It's actually web-building's strongest sidekick. Peek at HTML, tweak CSS on the spot, read errors — narrowed down to just the 3 you should learn first.

Right-click on a page → “Inspect.” Have you ever quietly closed the cluttered screen that popped up? That’s the developer tools — web-building’s strongest sidekick, where you can peek at a web page’s contents and tweak them on the spot. There are tons of features, but you only need to learn 3 first.

Three ways to open it

  • Right-click → “Inspect” on the page (do it over the spot you want to examine, and it opens with that spot selected)
  • The F12 key
  • Mac: ⌘+option+I / Windows: Ctrl+Shift+I

To close it, press the ”×” at the top right or the same key once more.

No. 1: The Elements panel — peek at HTML and CSS

What you see right after opening is the Elements panel. The contents of the HTML of the page you’re viewing appear like a tree, and clicking a line makes the corresponding spot on the page light up.

The Elements panel of Chrome developer tools. On the left is Shima’s page, and on the right the HTML tree and the CSS in the Styles panel sit side by side
Top right is the HTML tree; the Styles at the bottom right is the CSS taking effect on that spot. The element selected in the tree is highlighted on the page side.

The Styles in the lower half lists all the CSS taking effect on the selected spot. Here’s the amazing part —

  • Click a number and rewrite it, and the page changes on the spot (trial and error with margins and font sizes takes an instant)
  • Uncheck it to temporarily turn that setting off (you learn “what job does this CSS do?”)
  • A setting with a strikethrough is a sign that it’s being overridden by other CSS and isn’t taking effect
  • Click the square color swatch next to a color setting, and you can switch the notation between #rrggbb, rgb(), and hsl(), or change the color itself with the color picker

No matter how much you tinker, reloading restores it. It’s a sandbox with no fear of breaking anything, so tinker away. Once you find a number you like, copy it into your own style.css and it’s done.

No. 2: The Console panel — read errors and messages

The Console is the page’s “notification window.” JavaScript errors, messages you wrote with console.log, files that failed to load — they all arrive here.

The Console of Chrome developer tools. As a result of entering console.log, the message “Hello, Shima!” is output
You can also call up the Console in the lower section (the Escape key). You can also try typing JavaScript on the spot.

“The button doesn’t work when I press it,” “the image won’t show up” — this is the first place to look when you’re stuck. If red text appears, that’s a hint to the cause.

TipsDon't panic when an error appearsHow to read red errors is covered in detail in this articleJavaScriptCheck things with the consoleHow to output messages to the Console from your own program is over here

No. 3: The Device Toolbar — check how it looks on a smartphone

Press the overlapping smartphone-and-tablet icon at the top left (Mac: ⌘+shift+M), and the page displays at smartphone screen width. You can choose a model or freely drag the width, so checking “does it look broken on a phone?” can be done without pulling out your phone.

CSSMake it look good on phones too: media queriesHow to switch the look by screen width (media queries) is over here

One more worth knowing: the Network panel

“The image won’t display” and “the CSS won’t apply”—the two most common beginner stumbles—are usually caused by the file never arriving in the first place. The Network panel settles that question.

  1. Open the Network tab
  2. Reload the page while it’s open (traffic from before you opened it isn’t recorded, so this order matters)
  3. Every file that loaded appears in a list

The only column you need is Status.

StatusMeaningWhat to do
200Arrived fineThe file is there; the cause is in how the CSS is written
304Unchanged, so the previous copy was usedNormal. The cache is working
404Not foundA wrong path or file name. Check the spelling and the letter case
403Not allowedA permissions setting on the server. Check your host’s settings
(red / failed)The request itself failedCheck for spaces or unusual characters in the file name

If style.css is a 404, no amount of reviewing your CSS will fix it. Confirm it arrived first—that’s the trick to not going the long way round.

TipsHow to read and write pathsA 404 is almost always the path. How to write relative paths, sorted out here

Look up the panel by symptom

A table for when you’re not sure which panel to open.

SymptomPanelWhat to look at
CSS won’t applyElements → StylesWhether it’s struck through, or listed at all
Not sure which CSS is winningElements → ComputedOnly the values that finally applied
The button does nothingConsoleThe first line of the red error
The image won’t showNetworkWhether Status is 404
Can’t tell where the spacing comes fromThe box diagram below StylesThe measured margin, border and padding
It breaks on a phoneDevice ToolbarDrag the width to find where it breaks
The font won’t changeElements → ComputedThe name actually used for font-family

Shortcuts worth knowing

ActionMacWindows
Open / close DevTools⌘ + ⌥ + IF12
Element picker⌘ + ⇧ + CCtrl + Shift + C
Overlay the ConsoleEscEsc
Device Toolbar⌘ + ⇧ + MCtrl + Shift + M
Reload ignoring the cache⌘ + ⇧ + RCtrl + Shift + R

The fastest way to improve

It’s to break apart a site you like with “Inspect.” Right-click → Inspect on a button you thought was pretty. What color? How many px of margin? The corner radius? — a pro’s technique is all right there in numbers. Look, tinker, imitate. Developer tools are a “textbook of the web” you can read for free, infinitely.

TipsChrome extensions that make research fasterOnce you’re used to developer tools, extensions that let you look up colors and fonts in one shot are worth a try too

Summary

  1. Open it with right-click → “Inspect.” A safe sandbox that reloading restores no matter how you tinker
  2. Peek at HTML and CSS in Elements, and rewrite the numbers in Styles on the spot for trial and error
  3. When stuck, the Console. A red error is a hint to the cause
  4. When images or CSS don’t show up, check Status in Network. A 404 means a wrong path
  5. When your fix changes nothing, reload ignoring the cache with ⌘/Ctrl + ⇧ + R

From the day you stop being afraid of “Inspect,” your progress at web building accelerates all at once.

FAQ

Are the changes I make in developer tools saved?
They aren't. Changes in developer tools are temporary, on the browser, and revert when you reload the page. Copy any changes you like into your own CSS file.
Can I change the display language?
You can. In the developer tools settings (the gear icon), you can pick another language under Language. That said, most tutorial articles assume the English display, so keeping it in English is also an option.
How do I check how it looks on a smartphone?
Press the smartphone-and-tablet icon at the top left of the developer tools (the device toolbar), and you can switch the screen width to smartphone size to check the display.
When I rewrite numbers in the Styles panel, it's hard to tell which one is taking effect
Look at the "Computed" tab at the top right, and you get a list of only the CSS values finally applied to that spot. When multiple CSS rules are clashing, checking the answer in Computed is faster than tracing the strikethroughs in Styles.