How to View HTML Source in Safari

If you want to see how a webpage was built, try viewing its source code.

What to Know

  • From Safari menu, select Develop > Show Page Source.
  • Or, right-click on page and Show Page Source from drop-down menu.
  • Keyboard shortcut: Option+Command+U.

This article shows how to view HTML source code in Safari.

View Source Code in Safari

Showing source code in Safari is easy:

  1. Open Safari.

  2. Navigate to the web page you would like to examine.

  3. Select the Develop menu in the top menu bar. Select the Show Page Source option to open a text window with the HTML source of the page.

    Alternatively, press Option+Command+U on your keyboard.

    The "Show Page Source" command under Safari's Develop menu
  4. If the Develop menu is not visible, go into Preferences in the Advanced section and select Show Develop menu in menu bar.

On most web pages, you can also view the source by right-clicking on the page (not on an image) and choosing Show Page Source. You must enable the Develop menu in Preferences for the option to appear.

Safari also has a keyboard shortcut for viewing the HTML source: Hold down the command and option keys and hit U (Cmd+Opt+U.)​

Advantages of Viewing Source Code

Viewing the source to see how a web designer achieved a layout will help you learn and improve your work. Over the years, many web designers and developers have learned quite a lot of HTML by merely viewing the source of web pages they see. It's an excellent way for beginners to learn HTML and for seasoned web professionals to see how others used new techniques.

Remember that source files can be very complicated. Along with the HTML markup for a page, there will probably be significant CSS and script files used to create that site's look and functionality, so don't get frustrated if you can't figure out what's going on immediately. Viewing the HTML source is just the first step. After that, you can use tools like Chris Pederick's Web Developer extension to look at the CSS and scripts as well as inspect specific elements of the HTML.

Is Viewing Source Code Legal?

While copying a site's code wholesale and passing it off as your own on a website is certainly not acceptable, using that code as a springboard to learn from is actually how many people make advancements in this industry. You would be hard-pressed to find a working web professional today who has not discovered something by viewing a site's source!

Web professionals learn from each other and often improve upon the work that they see and are inspired by, so don't hesitate to view a site's source code and use it as a learning tool.

  • How do I edit a page's source code in Safari?

    You cannot edit webpage source code in Safari. When viewing the source code in Safari, copy and paste it into an app that can export files as plain text (like TextEdit or Pages).

  • How do I view a website's source code in Safari on my iPhone?

    The iOS version of Safari doesn't directly support webpage source viewing, but you can set up a custom bookmark that will accomplish the same task. Create a new bookmark in Safari and name it "Show Page Source" (or something similar, so long as you can identify it). Then in the address text box, copy and paste a specific javascript code, then Save. Once the bookmark is set up, navigate to a webpage that you want to vide the source of, then open your bookmarks and select the new Show Page Source bookmark to view the webpage's source code.

Was this page helpful?