Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

View Web Page Source on iPhone & iPad

· 6 min read · Home Tech

In this article
  1. Why You Might Want to See the Source
  2. How to View Source in Safari with a Bookmarklet
  3. Using a Dedicated App: View Source
  4. Other Methods: Safari Extensions and Web Inspector
  5. What You See vs. What the Server Sends
  6. Common Problems and Troubleshooting
  7. Frequently Asked Questions

Yes, you can view a web page's source code on an iPhone or iPad, but Safari doesn't offer a built-in "View Source" button. The easiest methods are using a bookmarklet in Safari or a dedicated app like View Source, which give you the raw HTML, CSS, and JavaScript that make up the page.

Why You Might Want to See the Source

Viewing source code is a fundamental tool for web developers, designers, and curious users. It lets you see the underlying structure of a page: the HTML that defines content, the CSS that styles it, and the JavaScript that adds interactivity. Common reasons include:

  • Learning: Seeing how a site is built is one of the best ways to learn web development.
  • Debugging: If you're building your own site, you can compare your code with a working example.
  • Extracting content: Copying a specific image URL, a video embed code, or a piece of text that isn't easily selectable.
  • Checking SEO tags: Verifying that a page has the right meta descriptions, title tags, or structured data.
  • Curiosity: Just understanding what's behind what you see.

How to View Source in Safari with a Bookmarklet

Safari on iOS doesn't have a native "View Source" option, but a bookmarklet—a small piece of JavaScript saved as a bookmark—does the job perfectly. Here's how to set it up:

  1. Create a bookmark: In Safari, bookmark any page (e.g., this one). You'll edit it in the next step.
  2. Edit the bookmark: Go to your bookmarks list, find the one you just created, and tap "Edit." Replace the URL with the following JavaScript code:
    javascript:var a=window.open('about:blank').document; a.write('
    '+document.documentElement.innerHTML.replace(/&/g,'&').replace(//g,'>')+'
    '); a.close();
  3. Name it clearly: Rename the bookmark to something like "View Source."
  4. Use it: Open any web page, tap the bookmarks icon, and select "View Source." A new tab will open showing the HTML source.

This method works because the JavaScript grabs the current page's HTML and displays it in a new window. It's a bit technical to set up, but it's free and doesn't require installing any apps.

Using a Dedicated App: View Source

If you'd rather not fiddle with bookmarklets, the App Store has several apps that make viewing source a one-tap task. One popular option is simply called View Source. These apps typically work by sharing a page to them:

  1. Install the app from the App Store.
  2. In Safari, open the page you want to inspect.
  3. Tap the Share button (the square with an arrow).
  4. Scroll down and tap View Source in the share sheet.
  5. The app will open and display the page's HTML, often with syntax highlighting and line numbers.

These apps often include extra features like a built-in browser, the ability to view external CSS and JavaScript files, and even an element inspector that lets you tap an element on the page to see its code.

Other Methods: Safari Extensions and Web Inspector

There are a few other routes you can take:

  • Safari Web Extensions: Starting with iOS 15, Safari supports extensions. Some extensions, like "View Source" or "Inspector," add a toolbar button that shows the source directly. You can find them in the App Store under the Safari Extensions category.
  • Web Inspector via Mac: If you have a Mac, you can use Safari's Web Inspector to inspect a page on your iPhone. Connect your iPhone to your Mac via USB, enable "Web Inspector" in Safari's Developer menu on the Mac, and then on the iPhone, open the page and select it from the Develop menu. This is the most powerful method, giving you full debugging tools, but it requires a Mac.
  • Third-party browsers: Browsers like Brave and Firefox have built-in "View Source" options in their share menus. If you already use one of those, it might be the simplest path.

What You See vs. What the Server Sends

A common misconception is that viewing source shows you exactly what the server sent. That's true for the initial HTML, but it often doesn't reflect the final state of the page. Many sites use JavaScript to dynamically add or modify content after the page loads. For example, a news site might load articles via JavaScript, so the source you see might just be a shell with empty containers. To see the final, rendered HTML, you'd need a tool like Web Inspector (on a Mac) that shows the live DOM (Document Object Model).

Also, the source you see is what the server sent to your device. If you're logged in, you might see personalized content. If you're on a mobile device, you might see a mobile-specific version of the page.

Common Problems and Troubleshooting

Here are a few issues you might run into:

  • Bookmarklet doesn't work: Make sure you've copied the JavaScript correctly and that the bookmark URL starts with javascript:. Also, some sites use Content Security Policy (CSP) that can block bookmarklets. In that case, a dedicated app is more reliable.
  • Source is unreadable: The source is often minified—meaning all the code is on one line. You can use a beautifier tool (like a website that formats code) or an app that has a "pretty print" feature.
  • Can't find the bookmarklet: In Safari, tap the bookmarks icon (the open book), then the tabs icon at the bottom, and you'll see your bookmarks. You can edit them from there.

Frequently Asked Questions

Can I view source code on an iPhone without an app?

Yes, you can use a bookmarklet in Safari. It's a small piece of JavaScript that you save as a bookmark, and it displays the source in a new tab. No app installation is required.

Is viewing source code legal?

Yes, viewing the source code of a website is perfectly legal. The code is sent to your browser, so you're just looking at what you've already received. However, using that code in your own projects may be subject to copyright, so it's best to use it for learning and inspiration.

Why does the source look different from what I see on screen?

That's because the page you see is the result of HTML, CSS, and JavaScript all working together. The source is the raw HTML, which is just the structure. The CSS (often in a separate file) styles it, and JavaScript can change it dynamically. To see the final rendered version, you'd need a DOM inspector.

Can I edit the source code on my iPhone?

You can't edit a live website's source code from your phone. But you can copy the source into a text editor or a code editor app, make changes, and save it as a local file. To see the changes, you'd open that file in a browser.

What's the difference between "View Source" and "Inspect Element"?

View Source shows the raw HTML that the server sent. Inspect Element (available in desktop browsers and via Web Inspector on a Mac) shows the live DOM, which is the page after JavaScript has run. Inspect Element also lets you see CSS styles applied to specific elements and even edit them temporarily.