Open View Source with Ctrl+U
Every website is made of HTML, the code that says “this is a heading, this is a paragraph, this is a link”. Your browser downloads that code and turns it into the page you see. View Source shows you the code itself. It’s built into every desktop browser and you don’t need to install anything. (If HTML is new to you, what HTML is explains it from the start.)
- Open the website you’re curious about.
- Press Ctrl+U (Windows, Linux, Chromebook) or the Mac shortcut from the table below.
- A new tab opens with the code. Press Ctrl+F (Cmd+F on a Mac) to search it for a word you can see on the page.
For a tiny cafe website, the code you’d see could look like this:
<!doctype html>
<html lang="en">
<head>
<title>Corner Cafe</title>
<link rel="stylesheet" href="/css/site.css">
</head>
<body>
<h1>Corner Cafe</h1>
<p>Open every day from 8 to 4.</p>
</body>
</html>
The <title> is the text on the browser tab, the <link> loads the site’s
CSS, and the <h1> and <p> are what you read on the page. Real sites are
much longer, often thousands of lines, but they’re built from the same pieces.
Shortcuts for every browser
These are the keys for the four big desktop browsers. Say you’re in Firefox on a Mac: open a page, press Cmd+U, and the source opens in a new tab.
| Browser | Windows and Linux | Mac | Right-click menu |
|---|---|---|---|
| Chrome | Ctrl+U | Cmd+Option+U | View page source |
| Edge | Ctrl+U | Cmd+Option+U | View page source |
| Firefox | Ctrl+U | Cmd+U | View Page Source |
| Safari | Not on Windows | Cmd+Option+U (after the step below) | Show Page Source |
The developer tools are the other way in. They open in a panel next to the page, with the live HTML, the CSS of whatever you click, and a Console for errors:
| Browser | Windows and Linux | Mac | Right-click menu |
|---|---|---|---|
| Chrome | F12 or Ctrl+Shift+I | Cmd+Option+I | Inspect |
| Edge | F12 or Ctrl+Shift+I | Cmd+Option+I | Inspect |
| Firefox | F12 or Ctrl+Shift+I | Cmd+Option+I | Inspect |
| Safari | Not on Windows | Cmd+Option+I (after the step below) | Inspect Element |
- On many laptops the top row of keys controls volume and brightness, so F12 does nothing. Hold Fn and press F12, or use Ctrl+Shift+I.
- Right-click on an empty part of the page. On a link or an image you get that item’s own menu, which may not have View page source in it. Inspect is there in all of them.
- Without the keyboard: in Chrome and Edge, the three-dot menu has More tools, then Developer tools. Chrome on a Mac also has View > Developer > View Source in the menu bar.
Safari: turn on the developer features first
Safari on a Mac hides its View Source and Inspect options until you switch them on. It takes a few seconds and you only do it once:
- In Safari, open the Safari menu and choose Settings (Cmd+,).
- Click the Advanced tab.
- Tick Show features for web developers. In older Safari versions (16 and before) the box is called Show Develop menu in menu bar.
A new Develop menu now sits in the menu bar. Open any page and press Cmd+Option+U, or choose Develop > Show Page Source. The right-click menu also gains Show Page Source and Inspect Element.
The view-source: address
In Chrome, Edge and Firefox you can also type view-source: in front of any address in the address bar
and press Enter:
view-source:https://example.com
That opens the source of the example.com home page. It works for other files too. If you see
href="/css/site.css" in the code, this shows you that stylesheet:
view-source:https://example.com/css/site.css -
You usually don’t have to type those. Links in the source view are clickable, so clicking
/css/site.cssthere opens the CSS file the same way. - Long lines are hard to read. Chrome and Edge have a Line wrap box at the top of the source tab, and in Firefox you can right-click the source and choose Wrap Long Lines.
- Safari doesn’t understand
view-source:. Use Cmd+Option+U there.
View Source vs Inspect: why they show different code
You see a product name on the page, open View Source, search for it, and it isn’t there. Both tools show HTML, but not the same HTML:
| View Source | Inspect (developer tools) | |
|---|---|---|
| What it shows | The HTML file the website sent, exactly as it arrived | The page as it is right now, as a tree of elements |
| After JavaScript? | No. Anything a script adds later is missing | Yes. It updates live while scripts change the page |
| Broken tags | Shown as written, mistakes and all | Shown the way the browser repaired them |
| Can you edit it? | No, it’s read-only | Yes, for a test. Your changes vanish when you reload |
| Good for | Meta tags, the title, which files a page loads | Finding one element and its CSS, seeing what scripts built |
JavaScript changes the page after it loads
Many sites send a nearly empty page and then fill it in with JavaScript. Here’s a tiny version of that. The server sends this HTML, with an empty box for the menu:
Below it, the page has a script that writes the menu into that box when the page loads:
<script>
const box = document.querySelector('#menu');
box.textContent = 'Today: tomato soup, bread, apple pie.';
</script>
The live box above runs with JavaScript turned off, which happens to be a good picture of what View Source gives
you: the “Turn on JavaScript” note shows, and the menu doesn’t. In a normal tab the script runs straight away and
you’d read “Today: tomato soup, bread, apple pie.” View Source still shows the <div
id="menu"> with only the noscript note in it, though. Inspect shows the div with the menu inside. So when something is missing from View
Source, right-click it on the page and choose Inspect.
The browser fixes broken HTML
Browsers are forgiving. When a closing tag is missing, they guess where it should go and build the page anyway. Inspect shows their guess, not your code. This snippet leaves out several closing tags:
Notice the second line is bold too: the <b> was never closed, so the browser carried it into
the next paragraph. On a computer, right-click inside the box and choose Inspect. Expand the elements and you’ll
find roughly this, with tags the code never had:
<ul>
<li>Tea</li>
<li>Coffee</li>
</ul>
<table>
<tbody>
<tr><td>Mon</td><td>8 to 4</td></tr>
</tbody>
</table>
<p>This has a <b>bold word</b></p>
<p><b>and this line is bold too.</b></p>
There are closing </li> tags, a <tbody> inside the table, and a second
<b> for the last line. If your own page looks odd, the HTML
Validator points at the missing tags, and the HTML Fixer can add them for you.
Copy the HTML of one part of the page
Often you don’t want the whole page, only one button or one table. Inspect is the quickest way to get it:
- Right-click the thing you want, say an “Order a coffee” button, and choose Inspect.
- The developer tools open with that element highlighted. Hover over nearby lines to see which part of the page each one is.
- Right-click the highlighted line. In Chrome and Edge choose Copy > Copy element (or Copy outerHTML). In Firefox choose Copy > Outer HTML.
- Paste it wherever you like.
For that button, what lands on your clipboard looks like this:
<button class="order-btn" type="button">Order a coffee</button> -
“Outer HTML” is the element with its own tags. “Inner HTML” is only what’s inside them, here the words
Order a coffee. -
The copy has the class names but not the CSS behind them, so pasted into a blank page it looks plain. The Styles
panel next to the HTML shows the rules for
.order-btn, and you can copy them from there. -
To copy the whole live page, right-click the
<html>line at the top of the tree and copy it the same way. That gets you the page after JavaScript ran, which View Source can’t.
On a phone: Android and iPhone
Phones don’t have a View Source button, but on Android there’s a way. In Chrome, tap the address bar, put
view-source: in front of the address and go:
view-source:https://example.com The code appears in the tab. It’s small on a phone screen, so zoom in, and use Find in page from the three-dot menu to jump to a word.
On an iPhone or iPad there’s no good built-in way. Safari has no View Source, and the
view-source: trick doesn’t work there. Your options:
- Open the same page on a computer and use the shortcuts above. Honestly, this is the easiest.
- If you have a Mac: in the iPhone’s Settings, find Safari, open Advanced and turn on Web Inspector. Connect the phone by cable (or over Wi-Fi once they’re paired) and open the page in Safari on the phone. Safari on the Mac then lists the phone in its Develop menu, and you can inspect the page from there.
- Some apps in the App Store offer a source viewer. They come and go, so check the reviews and what the app asks for before you install one.
Save a page as an HTML file
Press Ctrl+S (Cmd+S on a Mac) on any page. The save box asks what kind of file you want:
| Browser | Only the HTML file | HTML plus images and styles |
|---|---|---|
| Chrome, Edge | Webpage, HTML Only | Webpage, Complete |
| Firefox | Web Page, HTML only | Web Page, complete |
| Safari | File > Save As, Format: Page Source | Format: Web Archive (one .webarchive file) |
Saving the cafe page with “Complete” in Chrome gives you a file and a folder next to it:
Downloads/
├── Corner Cafe.html
└── Corner Cafe_files/
├── site.css
└── logo.png - With “HTML only”, the images and styles still point at the website. Opened from your disk, the page often looks broken or plain. That’s normal, the code is all there.
-
Keep the
_filesfolder next to the .html file. Move one without the other and the page loses its pictures. - Saved pages open in your browser with a double-click. How to create and open an HTML file covers that, and what to do when it opens in the wrong program.
Make the code easier to read
A lot of websites squash their HTML to make it download faster. Spaces and line breaks are removed, and a menu ends up on one long line like this:
<ul class="menu"><li>Latte</li><li>Mocha</li><li>Flat white</li></ul> Copy the source (Ctrl+A, then Ctrl+C in the source tab) and paste it into the HTML Formatter. You get the same code with one tag per line and indents that show what sits inside what:
<ul class="menu">
<li>Latte</li>
<li>Mocha</li>
<li>Flat white</li>
</ul>
To see the code as a page again, paste it into the HTML Viewer. Images and styles with short paths
like /css/site.css won’t load at first, because they live on the other site. Put a base tag with the
site’s address right after the <head> tag (not above the doctype) and most of them come back:
<!doctype html>
<html lang="en">
<head>
<base href="https://example.com/">
<title>Corner Cafe</title>
... One side effect: with a base tag in the code, links you click in the preview may open the real site inside the preview box.
Two more tools for code you copied from a site:
- List the links and images. The HTML Link Extractor pulls every link, image and email address out of the code into a table you can copy.
- Get only the words. HTML to Text drops the tags and keeps the readable text.
What you can do with the code
Looking is always fine. Your browser downloads this code every time you visit, and reading it is how most web developers learned. Copying is where you need to think a bit:
- Fine: seeing how a site centers its logo, which fonts it loads, or how its menu is built, and writing your own version.
- Fine: reusing a short, common pattern, like
<meta name="viewport" content="width=device-width, initial-scale=1">, which half the web has. - Not okay: copying a whole site, its text, photos, logo or design, and putting it up as yours. Those are usually protected by copyright and by the site’s terms of use.
- Ask first: if you want to reuse something bigger, check whether the site or the code has a license that allows it, or write to the owner.
This is general advice, not legal advice.
One more thing you won’t find in the source: the server side. If a site runs on PHP or another server language,
that code stays on the server. A page called menu.php shows plain HTML in View Source, because the PHP
already ran before the page was sent. To write a page of your own,
how to create an HTML file covers the first steps and
how to link CSS to HTML adds the styles.
Questions people ask
How do I see the HTML code of a website?
Open the page and press Ctrl+U on Windows, Linux or a Chromebook. On a Mac, press Cmd+Option+U in Chrome or Edge, Cmd+U in Firefox, or Cmd+Option+U in Safari (after turning on its developer features). You can also right-click an empty part of the page and choose View page source. A new tab opens with the page’s HTML.
How do I view the HTML code in Chrome?
Press Ctrl+U (Cmd+Option+U on a Mac), or right-click the page and choose View page source. To see the code of one part of the page, right-click it and choose Inspect, which opens the developer tools with that element selected. F12 or Ctrl+Shift+I also opens them.
What is the difference between View Source and Inspect?
View Source shows the HTML the website sent to your browser, before anything ran. Inspect shows the page as it is right now: after JavaScript added or changed things, and after the browser fixed any broken tags. That’s why a part you can see on the page sometimes isn’t in View Source. Look for it with Inspect instead.
Why can’t I find some text in View Source?
It was most likely added by JavaScript after the page loaded, for example a list of products fetched from the server or a whole app built in the browser. View Source only shows the first HTML the server sent. Right-click the text, choose Inspect, and you’ll find it in the live page.
Can I view the source code on my phone?
On Android, Chrome lets you type view-source: in front of the address, like view-source:https://example.com. Safari on an iPhone or iPad has no View Source option. There, the easiest way is to open the same page on a computer. If you have a Mac, Safari on the Mac can also inspect a page open on an iPhone connected by cable (or over Wi-Fi once paired), once Web Inspector is turned on in the iPhone’s Safari settings.
Can I see a website’s PHP or server code?
No. Code that runs on the server, like PHP, Python or database queries, never reaches your browser. You only see what the server sends back: HTML, CSS, JavaScript, images and fonts. A page that ends in .php shows plain HTML in View Source, because the PHP already ran on the server.
Can a website stop people from seeing its HTML?
Not really. The browser needs the HTML to show the page, so it’s always there to read. Some sites turn off the right-click menu or the Ctrl+U key, but the view-source: address and the browser’s own menus still work. Sites can make the code hard to read by squashing it onto one line, and an HTML formatter fixes most of that.
Is it legal to copy HTML code from a website?
Looking at the code is fine, your browser does it every time you visit. Learning from it, or copying a small common pattern like how a menu is built, is normal. Copying a whole site’s design, text, images or logo and passing it off as yours is not okay, those are usually protected by copyright and by the site’s terms. If you want to reuse something bigger, ask the owner or check its license. This isn’t legal advice.
How do I save the HTML of a web page?
Press Ctrl+S (Cmd+S on a Mac). In Chrome and Edge, pick Webpage, HTML Only to get one .html file, or Webpage, Complete to also get a folder with the images and styles. Firefox has Web Page, HTML only and Web Page, complete. In Safari, choose File > Save As and set the format to Page Source.
Keep going
Tools that help
- HTML Formatter Turns one long squashed line of HTML into neat, indented code.
- HTML Viewer Paste the code you copied and see it as a page, safely, with scripts off if you like.
- HTML Link Extractor Lists every link, image and email address in a page’s HTML.
- HTML Validator Checks the HTML for broken or missing tags, in plain English.
More tutorials
- How to Center Text, a Div or an Image in HTML & CSS
- How to Add a Line Break in HTML
- How to Add Spaces in HTML
- How to Change Text Color in HTML
- How to Change Background Color in HTML
- How to Add an Image in HTML
- What Is a URL? Meaning, Parts and Examples
- How to Redirect a Page in HTML
- How to Get an Image URL
- Canonical URL
- What Is HTML? What It Stands For and How It Works
- How to Create, Open and Run an HTML File
- How to Link CSS to HTML
- How to Link JavaScript to HTML with the script Tag
- HTML hr Tag
- HTML Comments
- How to Make Text Bold in HTML
- HTML Font and Font Size
- All tutorials