CSS Debugging & DevTools
Browser DevTools are your most powerful CSS debugging tool. Learn to inspect elements, understand computed styles, debug layout issues, test responsive designs, and identify performance bottlenecks — all from the browser.
DevTools Techniques
- Inspect element — Right-click → Inspect. View and edit CSS live in the Styles panel
- Computed tab — Shows the FINAL value after all cascade rules. Answers 'why is it this color?'
- Box model diagram — Visual representation of margin, border, padding, and content size in DevTools
- Force states — :hov button in DevTools forces :hover, :focus, :active states for debugging
- Layout panel — Visualize Grid and Flexbox layouts with overlay guides
- Coverage tab — Shows how much CSS is actually used on the page (unused CSS highlighted in red)
- Performance tab — Record page load or interactions to find layout thrashing and long tasks
Debugging Tips
/* Quick debug: see all element boundaries */
* { outline: 1px solid red !important; }
/* Debug layout: find overflowing element */
* { background: rgba(255, 0, 0, 0.1) !important; }
/* In DevTools Console: find elements causing horizontal scroll */
/* document.querySelectorAll('*').forEach(el => {
if (el.scrollWidth > document.documentElement.clientWidth) {
console.log('Overflow:', el);
}
}); */
/* Common debugging approaches: */
/* 1. "Why isn't my style applying?" */
/* → Check DevTools: is the rule crossed out? (overridden by higher specificity) */
/* → Check computed tab for the final value */
/* → Check for typos in selector or property name */
/* 2. "Why is there unexpected space?" */
/* → Check for margin collapse (two vertical margins merge) */
/* → Check for default browser margins (use reset) */
/* → Check box model diagram in DevTools */
/* 3. "Why is my layout broken?" */
/* → Use DevTools Layout panel to visualize Grid/Flex */
/* → Check for overflow issues (overflow: hidden might be clipping) */
/* → Check for position: absolute without a positioned parent */Tip
The * { outline: 1px solid red !important } debug trick is the fastest way to visualize all element boundaries. Add it temporarily to find spacing issues, overflows, and layout problems. Remove it when done debugging.
Every element follows the box model — content + padding + border + margin
Common Mistake
Debugging CSS by randomly changing properties until it works. Instead, use DevTools systematically: (1) Inspect the element, (2) Check if your rule is crossed out (overridden), (3) Check the Computed tab for the final value, (4) Fix the root cause.
Practice Task
Practice DevTools debugging: (1) Open DevTools and force :hover state on a button, (2) Use the Coverage tab to find unused CSS percentage, (3) Add * { outline: 1px solid red } to find a layout issue, (4) Use the box model diagram to find unexpected margin/padding.
Quick Quiz
Key Takeaways
- Browser DevTools are your most powerful CSS debugging tool.
- Inspect element — Right-click → Inspect. View and edit CSS live in the Styles panel
- Computed tab — Shows the FINAL value after all cascade rules. Answers 'why is it this color?'
- Box model diagram — Visual representation of margin, border, padding, and content size in DevTools