User Agents

Web browsers and everyday web tech, explained

How to View Page Source Code in Chrome

· 5 min read · Browsers

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

Viewing the page source code in Google Chrome allows you to inspect the underlying HTML, CSS, and JavaScript that make up any webpage. This is essential for web developers, designers, students, or curious users who want to understand how a site is built, debug layout issues, or learn from existing code. Fortunately, Chrome provides multiple built-in tools to access this information quickly and efficiently without installing any extensions or third-party software.

What You'll Need

  • A computer or laptop with Google Chrome installed
  • An active internet connection to load webpages
  • A webpage open in Chrome that you want to inspect

Step-by-Step

  1. Open Google Chrome and navigate to the webpage whose source code you want to view. Make sure the page has fully loaded before proceeding.
  2. Right-click anywhere on the webpage. A context menu will appear. The exact wording may vary slightly depending on your Chrome version or operating system, but it will include options like "Inspect," "View Page Source," or similar.
  3. Select "View Page Source" from the context menu. This opens a new tab displaying the raw HTML source code of the entire page as it was delivered from the server.
  4. Alternatively, use a keyboard shortcut: Press Ctrl + U (Windows/Linux) or Cmd + Option + U (Mac). This performs the same action as selecting "View Page Source" from the menu.
  5. To inspect specific elements on the page instead of the full source, right-click directly on the element (such as a button, image, or text) and choose "Inspect" from the menu. This opens Chrome DevTools with the corresponding HTML and CSS highlighted.
  6. In DevTools, you can expand and collapse HTML tags, view applied styles, modify content temporarily, and see how changes affect the layout. This is useful for debugging or testing design adjustments.
  7. To view only the source code without DevTools, stick with "View Page Source" or the keyboard shortcut. The raw HTML will appear in a clean, syntax-highlighted format with line numbers.
  8. Use your browser’s search function (Ctrl + F or Cmd + F) within the source tab to find specific elements, classes, or scripts quickly.
  9. For dynamic content loaded via JavaScript, note that "View Page Source" shows only the initial HTML sent by the server. To see changes made after loading (like content added by scripts), use "Inspect" and examine the Elements panel in DevTools.
  10. Close the source tab or DevTools when finished. No changes you make in these views affect the actual website unless you save modifications manually or through developer workflows.

Common Mistakes

One frequent error is confusing "View Page Source" with "Inspect." The former shows the original HTML from the server, while the latter reflects the current DOM, including JavaScript modifications. Users expecting to see dynamically loaded content (such as comments or images loaded via AJAX) may be misled if they only check the source code tab.

Another mistake is assuming that all page behavior can be understood just by viewing HTML. Modern websites rely heavily on external JavaScript and CSS files. Simply viewing the inline HTML won’t reveal everything—users must explore linked resources in DevTools’ Network or Sources panels.

Some users try to edit the source code directly in the browser and expect changes to persist. However, modifications made in DevTools are temporary and lost upon refresh. Permanent changes require editing the actual files on the server or local development environment.

Tips

Use Ctrl + Shift + I (or Cmd + Option + I on Mac) to open DevTools directly if you plan to inspect elements rather than view static source. This saves time over right-clicking each time.

In the source code tab, look for <!-- --> comments. These often contain developer notes, version info, or clues about the site’s structure or CMS.

If you're learning web development, practice by viewing the source of well-designed sites. Observe how HTML is structured, how classes are named, and how scripts are included. This can improve your own coding practices.

Use the "Pretty Print" feature in DevTools for minified JavaScript or CSS. Click the { } icon at the bottom of the source to format compressed code into a readable layout.

Troubleshooting

If right-clicking does nothing, check if the site has disabled the context menu via JavaScript. In such cases, use keyboard shortcuts instead: Ctrl + U to view source or Ctrl + Shift + I to open DevTools.

If DevTools doesn’t open, ensure Chrome is updated. Older versions may have bugs or missing features. Go to Menu > Help > About Google Chrome to check for updates.

When the source code appears blank or incomplete, verify that the page loaded correctly. Reload the page and try again. Some single-page applications (SPAs) load minimal HTML initially, with most content injected later via JavaScript.

If search within source (Ctrl + F) doesn’t find expected text, remember that dynamically inserted content won’t appear in "View Page Source." Switch to the "Inspect" tool and search in the Elements panel instead.

Frequently Asked Questions

Can I edit the source code in Chrome?

You can make temporary edits in DevTools, but they vanish when you refresh. Real changes require access to the original files.

Why doesn’t "View Page Source" show images loaded by JavaScript?

Because it only displays the initial HTML. Use "Inspect" to see the current DOM, which includes dynamically added elements.

Is viewing source code legal?

Yes. Viewing source is allowed and built into every browser. However, copying and republishing code may violate copyright.

Does "View Page Source" show CSS and JavaScript?

It shows references to CSS and JS files in the HTML, but not the full content unless they are inline. Use DevTools to explore external resources.

Can mobile Chrome view page source?

Not directly. Mobile Chrome lacks right-click. Use desktop mode via remote debugging or third-party tools, but avoid untrusted apps.

What’s the difference between source code and DOM?

Source code is the raw HTML from the server. DOM is the live version, modified by scripts and user interactions.