1.2: Browser Developer Tools
Master browser Developer Tools to inspect HTML/CSS, debug JavaScript, and analyze network performance. These essential tools will be your best friend throughout your web development journey.
1. Introduction to Developer Tools
Browser Developer Tools (DevTools) are your best friend as a web developer. They allow you to:
- Inspect and modify HTML/CSS in real-time
- Debug JavaScript code
- Monitor network activity
- Analyze performance
- Test responsive designs
- And much more!
::: tip š” Every Developer Uses DevTools Professional web developers spend significant time in DevTools. Mastering these tools early will make you a more effective developer. :::
Opening DevTools
Method 1: Keyboard Shortcuts
- Windows/Linux:
F12orCtrl + Shift + I - macOS:
Cmd + Option + I
Method 2: Right-Click Menu
- Right-click anywhere on a webpage
- Select "Inspect" or "Inspect Element"
Method 3: Browser Menu
- Chrome: Menu ā More Tools ā Developer Tools
- Firefox: Menu ā More Tools ā Web Developer Tools
- Edge: Menu ā More Tools ā Developer Tools
2. Elements Panel (HTML & CSS)
The Elements (Chrome) or Inspector (Firefox) panel lets you inspect and modify the DOM (Document Object Model).
Inspecting Elements
Try This:
- Open any website (e.g., https://www.wikipedia.org)
- Open DevTools (
F12) - Click the Select Element tool (arrow icon) in top-left
- Hover over different parts of the page
- Click to inspect an element
Understanding the DOM Tree
The DOM is displayed as a tree structure:
<html>
<head>
<title>Page Title</title>
</head>
<body>
<h1>Heading</h1>
<p>Paragraph</p>
</body>
</html>
- Parent: Contains other elements (e.g.,
<body>contains<h1>) - Child: Contained within another element
- Sibling: Elements at the same level
Live HTML Editing
You can edit HTML directly in DevTools:
- Right-click an element in the Elements panel
- Choose "Edit as HTML"
- Modify the HTML
- Press
Ctrl+Enter(orCmd+Enter) to apply
Try This:
- Change a heading text
- Add a new paragraph
- Modify an image src
::: warning ā ļø Changes Are Temporary Modifications in DevTools only affect the current page view. Refresh the page and they're gone. This is perfect for experimenting! :::
CSS Styles Panel
On the right side, you'll see:
- Styles: CSS rules applied to the selected element
- Computed: Final calculated values
- Box Model: Visual representation of margins, borders, padding
Try This:
- Select any element
- In the Styles panel, find a CSS rule
- Click a color value and change it
- Toggle checkboxes to enable/disable properties
- Add a new property (e.g.,
font-size: 24px)
3. Console Panel (JavaScript)
The Console is your JavaScript playground and debugging tool.
Basic Console Usage
Opening the Console:
- Shortcut:
Ctrl+Shift+J(Windows/Linux) orCmd+Option+J(macOS) - Or click the "Console" tab in DevTools
Try These Commands:
// Simple arithmetic
2 + 2
// Display text
console.log("Hello, DevTools!")
// Check current page URL
window.location.href
// Get page title
document.title
// Change page title (temporarily)
document.title = "My New Title"
// Select an element
document.querySelector('h1')
// Change element text
document.querySelector('h1').textContent = "Modified Heading"
Console Methods
// Log messages
console.log("Normal message")
console.warn("Warning message") // Yellow
console.error("Error message") // Red
console.info("Info message") // Blue
// Group related logs
console.group("My Group")
console.log("Message 1")
console.log("Message 2")
console.groupEnd()
// Display object properties
const user = { name: "Alice", age: 25 }
console.table(user)
// Measure time
console.time("MyTimer")
// ... some code ...
console.timeEnd("MyTimer")
Debugging with Console
Common Debugging Tasks:
// Check if element exists
console.log(document.querySelector('.my-class')) // null if doesn't exist
// Inspect object structure
const data = { a: 1, b: { c: 2 } }
console.dir(data)
// Trace function calls
console.trace()
// Clear console
console.clear()
4. Network Panel
The Network panel shows all HTTP requests made by the page.
Monitoring Network Activity
- Open DevTools
- Go to Network tab
- Refresh the page (
Ctrl+RorCmd+R) - Watch requests appear
Understanding Network Requests
Each row shows:
- Name: File name (HTML, CSS, JS, images, etc.)
- Status: HTTP status code (200, 404, 500, etc.)
- Type: MIME type (document, stylesheet, script, image, etc.)
- Initiator: What triggered the request
- Size: File size
- Time: Load duration
Try This:
- Refresh a webpage with Network panel open
- Click on the first request (usually the HTML document)
- Explore the tabs:
- Headers: Request/response headers
- Preview: Formatted preview
- Response: Raw response data
- Timing: Load timeline
Filtering Requests
Use the filter bar to show only:
- XHR: AJAX requests
- JS: JavaScript files
- CSS: Stylesheets
- Img: Images
- Media: Videos/audio
- Doc: HTML documents
Performance Analysis
Look for:
- Large files (slow to download)
- Many requests (can slow page load)
- Failed requests (404 errors)
- Slow server responses
Waterfall Visualization:
- Shows request timing
- Blue: DNS lookup
- Orange: Initial connection
- Green: Waiting (server processing)
- Blue: Content download
5. Application/Storage Panel
The Application (Chrome) or Storage (Firefox) panel shows:
- Cookies
- LocalStorage
- SessionStorage
- IndexedDB
- Cache
Cookies
Viewing Cookies:
- Go to Application ā Cookies
- Select your domain
- See all cookies with their values, expiration, etc.
Try This:
- Find a cookie
- Double-click its value to edit
- Delete a cookie (right-click ā Delete)
LocalStorage & SessionStorage
LocalStorage: Persists even after browser closes SessionStorage: Cleared when tab closes
Try in Console:
// Set items
localStorage.setItem('name', 'Alice')
sessionStorage.setItem('temp', 'value')
// Get items
localStorage.getItem('name') // "Alice"
// Remove items
localStorage.removeItem('name')
// Clear all
localStorage.clear()
View in DevTools:
- Application ā Local Storage ā your domain
- Application ā Session Storage ā your domain
6. Responsive Design Mode
Test how your site looks on different devices.
Device Toolbar
Activate:
- Click the Device Toolbar icon (phone/tablet icon)
- Or press
Ctrl+Shift+M(Windows/Linux) orCmd+Shift+M(macOS)
Features:
- Select device presets (iPhone, iPad, etc.)
- Set custom dimensions
- Rotate device (portrait/landscape)
- Throttle network speed
- Simulate touch events
Try This:
- Enable Device Toolbar
- Select "iPhone 12 Pro"
- See how the page adapts
- Rotate to landscape
- Try "iPad" and compare
7. Performance & Lighthouse
Performance Panel
Record Performance:
- Go to Performance tab
- Click Record button
- Interact with the page
- Click Stop
- Analyze the flame chart
What to Look For:
- Long tasks (>50ms)
- Layout shifts
- Paint operations
- JavaScript execution time
Lighthouse Audit
Run an Audit:
- Go to Lighthouse tab
- Select categories:
- Performance
- Accessibility
- Best Practices
- SEO
- Click Generate Report
- Review scores and suggestions
Lighthouse Scores:
- 90-100: Good (green)
- 50-89: Needs improvement (orange)
- 0-49: Poor (red)
8. Sources/Debugger Panel
The Sources (Chrome) or Debugger (Firefox) panel is for debugging JavaScript.
Breakpoints
Setting Breakpoints:
- Go to Sources panel
- Open a JavaScript file
- Click line number to set breakpoint
- Refresh page - execution pauses at breakpoint
Breakpoint Controls:
- Resume: Continue execution (F8)
- Step Over: Next line (F10)
- Step Into: Enter function (F11)
- Step Out: Exit function (Shift+F11)
Try This:
- Find a website with JavaScript
- Open DevTools ā Sources
- Set a breakpoint
- Trigger the code
- Inspect variables
Watch Expressions
Add variables to watch:
- In Sources panel, find Watch section
- Click + to add expression
- Type variable name
- See its value update as you debug
9. Practical Exercises
Exercise 1.2.1: Inspect and Modify
- Go to https://www.wikipedia.org
- Open DevTools
- Find the Wikipedia logo
- Change its
srcattribute to a different image URL - Modify the page title in the
<title>tag
Exercise 1.2.2: CSS Debugging
- On any webpage, select a paragraph
- In Styles panel, add these CSS properties:
background-color: yellow; padding: 20px; border: 2px solid red; - Observe the box model visualization
- Take a screenshot
Exercise 1.2.3: Network Analysis
- Open https://www.bbc.com (or any news site)
- Open Network panel
- Refresh the page
- Answer:
- How many total requests?
- What's the largest file?
- How long did the page take to load?
- Are there any failed requests (red)?
Exercise 1.2.4: Console Practice
In the console, write JavaScript to:
// 1. Log your name
console.log("My name is [Your Name]")
// 2. Find all links on the page
document.querySelectorAll('a').length
// 3. Get the first heading's text
document.querySelector('h1').textContent
// 4. Store your age in localStorage
localStorage.setItem('age', '25')
// 5. Retrieve and display it
console.log(localStorage.getItem('age'))
Exercise 1.2.5: Responsive Testing
- Enable Device Toolbar
- Test a website on these devices:
- iPhone SE (375Ć667)
- iPad (768Ć1024)
- Desktop (1920Ć1080)
- Note any layout issues or differences
10. DevTools Keyboard Shortcuts
Essential Shortcuts
| Action | Windows/Linux | macOS |
|---|---|---|
| Open DevTools | F12 or Ctrl+Shift+I | Cmd+Option+I |
| Open Console | Ctrl+Shift+J | Cmd+Option+J |
| Inspect Element | Ctrl+Shift+C | Cmd+Option+C |
| Device Toolbar | Ctrl+Shift+M | Cmd+Shift+M |
| Hard Refresh | Ctrl+Shift+R | Cmd+Shift+R |
| Search Files | Ctrl+P | Cmd+P |
| Command Menu | Ctrl+Shift+P | Cmd+Shift+P |
Pro Tips
Command Menu (Ctrl+Shift+P):
- Type "screenshot" to capture page
- Type "theme" to switch dark/light mode
- Type "cache" to clear browser cache
11. Browser Differences
Chrome DevTools
- Most comprehensive
- Excellent performance tools
- Best documentation
Firefox DevTools
- Great CSS Grid inspector
- Excellent font editor
- Privacy-focused
Edge DevTools
- Similar to Chrome (same engine)
- Additional Microsoft integrations
Safari DevTools
- Good for iOS/macOS testing
- Requires enabling in Preferences
::: tip š” Recommendation Learn Chrome DevTools first (most common), then explore Firefox for advanced CSS features. Use Safari for Apple device testing. :::
12. Knowledge Check
Question 1: What keyboard shortcut opens DevTools in most browsers?
Show answer
F12 or Ctrl+Shift+I (Windows/Linux) or Cmd+Option+I (macOS)Question 2: Where do you inspect and modify HTML elements?
Show answer
Elements panel (Chrome) or Inspector panel (Firefox)Question 3: What panel shows all HTTP requests made by a page?
Show answer
Network panelQuestion 4: How do you test responsive design in DevTools?
Show answer
Enable Device Toolbar (Ctrl+Shift+M or Cmd+Shift+M) to simulate different devicesQuestion 5: What's the difference between localStorage and sessionStorage?
Show answer
localStorage persists even after browser closes; sessionStorage is cleared when the tab/window closesQuestion 6: What console method displays objects in a table format?
Show answer
console.table()13. Key Takeaways
ā DevTools are essential for every web developer ā Elements panel lets you inspect and modify HTML/CSS in real-time ā Console is your JavaScript debugging and experimentation tool ā Network panel shows all requests and helps diagnose performance issues ā Application panel displays cookies, localStorage, and other storage ā Device Toolbar tests responsive design across devices ā Lighthouse audits performance, accessibility, and best practices ā Temporary changes in DevTools don't affect actual files
14. Common DevTools Workflows
Debugging CSS Layout
- Inspect element
- Check Computed styles
- Look at Box Model
- Toggle CSS properties
- Add new rules to test
Finding Performance Issues
- Open Network panel
- Refresh page
- Sort by Size (find large files)
- Sort by Time (find slow requests)
- Run Lighthouse audit
Debugging JavaScript Errors
- Open Console
- Read error message
- Click file:line link
- Set breakpoint
- Inspect variables
15. Further Resources
Official Documentation:
Interactive Tutorials:
Next Steps
Congratulations! You now know how to use Browser Developer Tools to inspect, debug, and optimize websites.
In Lesson 1.3: HTTP and Web Communication, you'll learn how the browser and server communicate using the HTTP protocol.