Every web developer eventually has to answer questions like “why is this element 12 pixels too wide?”, “which rule is overriding my colour?” and “what did the server actually send?”. The answers are all visible in the browser, if you know where to look. This guide explains the difference between the page source and the live DOM, how to read a page’s source quickly, how to inspect and debug CSS with the cascade and specificity in mind, and how to do all of this on a real phone. You can apply it to your own pages and to any site you want to learn from.
It pairs naturally with the Responsive Web Design Testing Checklist, Debugging JavaScript Console Errors on Mobile and CSS Breakpoints and Container Queries.
1. View source versus the live DOM
These are two different things, and confusing them wastes hours.
| View source | DevTools Elements panel | |
|---|---|---|
| What it shows | The raw HTML the server sent | The current DOM after JavaScript has run |
| Updates when JavaScript changes the page | No | Yes |
| Good for | Checking titles, meta tags, canonicals, structured data and what a crawler may see before rendering | Debugging layout, dynamic content, classes added by scripts |
If content appears in the Elements panel but not in the source, it was added by JavaScript. That matters for SEO and for users with slow devices, as explained in the On-Page SEO Checklist for Developers.
2. How to open the source
- Desktop browsers: right-click and choose “View page source”, or use the keyboard shortcut for it in your browser (commonly Ctrl+U or Cmd+Option+U).
- Any browser address bar: type
view-source:before the URL, for exampleview-source:https://example.com/. This works in Chromium-based browsers, including Chrome on Android. - Command line:
curl -s https://example.com/ | lessshows exactly what a simple client receives, with no JavaScript. Add-Ito see only the response headers (status code, caching, redirects).
3. What to look for in the source
- The
<head>: title, meta description, viewport, canonical, robots, Open Graph tags and links to stylesheets. - The viewport meta tag. Without
width=device-width, initial-scale=1, mobile browsers render a desktop-sized page and shrink it. - Heading structure. One
h1and a logical order. - Structured data. Search for
application/ld+json. - Scripts and where they load. Blocking scripts in the head slow the first render.
- Image tags. Check for
width,height,alt,srcsetandloadingattributes. See Responsive Image Optimisation. - Inline critical CSS or large inline blobs that bloat the HTML.
Use the browser’s find (Ctrl+F) inside the source to jump to what you need, such as canonical, noindex or og:image.
4. Inspecting CSS: the essential panels
Right-click an element and choose “Inspect” to open the developer tools with that element selected. The most useful areas are:
- Styles: every rule that matches the element, ordered by priority. Overridden declarations appear with a strike-through. You can edit values live, tick or untick declarations and add new ones. Changes are temporary until you copy them into your code.
- Computed: the final value of every property after the cascade, plus which rule supplied it. Use it to answer “why is this colour this value?”.
- Box model diagram: content, padding, border and margin sizes with their numbers. It explains most unexpected spacing.
- Layout tools: toggles that overlay flexbox and grid lines on the page, making alignment problems visible.
- Force element state: options to simulate
:hover,:focusand:active, so you can inspect styles that usually vanish when you move the mouse.
5. Understanding the cascade and specificity
When several rules set the same property, the browser picks a winner using this order of considerations, simplified: importance (!important), origin, cascade layers, specificity and finally source order, where the later rule wins when everything else is equal.
Specificity can be thought of as a three-part score (ids, classes/attributes/pseudo-classes, elements), compared from left to right:
| Selector | Score (ids, classes, elements) |
|---|---|
a | (0, 0, 1) |
.menu a | (0, 1, 1) |
.menu .item a:hover | (0, 3, 1) |
#nav a | (1, 0, 1) |
inline style="..." | beats all selector scores (without !important) |
So #nav a (1, 0, 1) beats .menu .item a:hover (0, 3, 1), because a single id outranks any number of classes. Remember that a score is compared part by part, not added as a decimal number. Inline styles override stylesheet rules unless the stylesheet uses !important. Avoid !important as a habit, since it makes later overrides harder. If you must override a high-specificity rule, prefer to restructure the CSS or use cascade layers (@layer) where your browser support allows.
Debugging example. You set .button { background: green; } but the button stays blue. In the Styles panel you see .button crossed out, with .card .button (0, 2, 0) or button.primary (0, 1, 1) winning above it. Either increase your selector’s specificity sensibly, change the other rule or reorder them. Check Computed to confirm.
6. Finding what causes horizontal scrolling
A page that scrolls sideways on a phone is almost always caused by one element wider than the viewport. Paste this into the console to find offenders:
const vw = document.documentElement.clientWidth;
[...document.querySelectorAll('body *')]
.filter(el => el.getBoundingClientRect().right > vw)
.forEach(el => console.log(el, Math.round(el.getBoundingClientRect().right)));
A quick visual alternative is to temporarily outline everything, which reveals boxes that extend past their parents:
* { outline: 1px solid rgba(255, 0, 0, 0.4); }
Common culprits are fixed pixel widths, images without max-width: 100%, long unbroken strings, wide tables and elements using 100vw with a vertical scrollbar present. Do not hide the problem with overflow-x: hidden on the body before you understand the cause.
7. Responsive tools in DevTools
- Device toolbar: resize the viewport, pick preset devices, set the device pixel ratio and throttle the network and CPU.
- Media query inspector: shows your breakpoints as coloured bars you can click to jump to a width.
- Rendering tools: emulate print styles, dark mode (
prefers-color-scheme) and reduced motion. - Disable JavaScript temporarily to see what the HTML and CSS alone deliver.
Emulation is a good first check but not a substitute for a real device. Real phones differ in font rendering, scrolling, on-screen keyboards, browser toolbars and performance.
8. Debugging on a real phone
Android with Chrome: enable Developer options and USB debugging on the phone, connect it to a computer with a cable, open chrome://inspect in desktop Chrome, and choose “inspect” next to your open page. You get the full DevTools for the live page on the phone, including the console and network panels. iPhone with Safari: enable Web Inspector in Safari’s advanced settings on the iPhone, and connect it to a Mac running Safari with the Develop menu enabled. Steps and menu names change between versions, so follow the current browser documentation.
For a quick look without setting up a cable, load the page on your phone at different widths with Dev Browser and check how the layout responds at phone, tablet and desktop sizes. It is especially handy when you are away from your computer or want a second opinion on a layout. Get it from Google Play.
9. The Network panel in two minutes
- Reload with the panel open to see every request, its size and its timing.
- Sort by size to find the heaviest assets, and by time to find the slowest.
- Check status codes: 200 is success, 301 and 302 are redirects, 404 is not found and 5xx are server errors.
- Look at the response headers for caching (
Cache-Control) and compression (Content-Encoding). - Filter by “Img”, “JS” or “CSS” to focus on one type. Use these findings with Core Web Vitals on Mobile.
10. Learning from other sites, responsibly
Reading other sites’ HTML and CSS is a great way to learn how layouts, accessibility patterns and performance techniques work. It is fine to study techniques, but do not copy someone’s code, design or content wholesale. Copyright applies to the code and assets you see. Also never put secrets, API keys or private data in front-end code, because anyone can read it in the browser.
A 10-minute inspection routine
- View the source and check title, meta, viewport, canonical and robots.
- Compare with the Elements panel to see what JavaScript changed.
- Open the Console and note any errors or warnings.
- Resize to 360, 768 and 1,280 px and look for overflow or overlaps.
- Inspect any element that looks wrong and read Computed for the actual values.
- Check the Network panel for large or failing requests.
- Repeat on a real phone.
Common mistakes
- Debugging the source when the problem is in the rendered DOM, or the reverse.
- Fixing a style in DevTools and forgetting to copy it into the source files.
- Fighting specificity with
!importantinstead of fixing the selector structure. - Hiding overflow instead of finding the wide element.
- Testing only in desktop emulation.
- Testing with a cached version of the page. Use a hard reload or disable the cache while DevTools is open.
Frequently asked questions
Why doesn’t view-source show my dynamic content?
View source shows what the server sent. Content added by JavaScript appears only in the live DOM.
How do I see which CSS rule is winning?
Select the element, open Styles to see strike-through rules, and use Computed to see which rule supplied each final value.
Can I inspect a page on my phone without a computer?
You can view source with a view-source: address in Chrome on Android, and check layouts at different widths with a tool like Dev Browser. For full DevTools you need remote debugging from a computer.
Is it legal to read another site’s source?
Viewing what your browser receives is normal. Reusing someone’s code or content is a copyright matter, so learn from it but write your own.
Conclusion
Know the difference between source and DOM, read the cascade properly, find overflow with a script instead of guessing, and always confirm on a real phone. Those habits make most front-end bugs quick to diagnose. Check your next page on a phone with Dev Browser and see the other tools on the products page.
Disclaimer: Browser menus, shortcuts and developer-tool features change between versions. Check your browser’s current documentation for exact steps.