A Guide to Using the Web Inspector in Safari

Apple_Safari.png

Ever since Safari 3, Apple has included an excellent feature in Safari called the “Web Inspector.” The Web Inspector is a surprisingly useful and practical debug tool that does not appear in Safari by default.

To launch and make use of the Web Inspector, one must enable Safari’s debug menu by running a simple Terminal command. We’ve discussed it in an earlier post, but here it is again:

defaults write com.apple.Safari IncludeDebugMenu 1

Once the Debug menu is enabled in Safari, you can access the Web Inspector via two methods. One way is to select “Debug” from the menu bar and then select “Show Web Inspector.” The other way is to Control-Click on any part of a web page and select “Inspect Element.”

The Web Inspector launches as a large window with two main boxes, one containing code and the other containing a list of documents, stylesheets, images, and scripts. The Web Inspector will pull as many of these items from the web page you are visiting as it can. For MacTips, it finds the document for the page, the document for our Digg This plug-in, a handful of stylesheets, a bunch of images, and a few scripts that the site utilizes.

Once the Web Inspector is launched, there are a couple of ways to make it appear how you’d like it to. By default, it appears as a separate window and shows the code with indentations and expanding tags. You can set it to appear in-line with your Safari window by pressing the button that is second-furthest form the left along the bottom of the Web Inspector, which is shown at right, webinspector1.pngand you can change the code view to straight-up text by clicking on the non-bullet point icon at the top of the window, which is shown below.
webinspector.png

The main point of the Web Inspector is to allow you to “inspect” snippets of code, and it does it excellently. One great way to utilize this is to highlight any “element” in a web page–some text, an image, or anything at all–then Control-Click on it and select “Inspect Element.” This will bring the Web Inspector straight to that element in the code for the page, and allows you to do exactly what it says, to “inspect” the “element.”

inspector.png

For those of you who aren’t big fans of Safari, a similar tool can be found in Firefox by installing the Firebug add-on.

While the Web Inspector has a couple of bugs itself, most technical users of Safari should find it quite useful. Its features are seemingly endless; each time I use it I discover something new. If you have any interest in web development or debugging, I highly recommend you give Safari’s Web Inspector a look.

Similar Posts:

I Like This Tip!


2 Responses to “A Guide to Using the Web Inspector in Safari”

  1. 4Avatars
    encro
    You can enable the Web Inspector without having the debug menu also:

    defaults write com.apple.Safari WebKitDeveloperExtras -bool true

    ctrl-click (right click to bring it up :)

  2. I had to use sudo to enable it (defaults write com.apple.Safari IncludeDebugMenu 1) - other than that it's pretty cool, but it lacks the most useful feature of Firebug for me: being able to edit code directly and see the results in an instant.

Post a comment to "A Guide to Using the Web Inspector in Safari"



MacTips Newsletter


Twitter MacTips

  • Stay up to date with the latest Mac tips, tricks and news by following us on twitter: MacintoshTips.

AppleGazette Headlines

Most Popular Tips (30 Days)

Most Commented (30 Days)

Good Tips

Recent Discussions

MacTips Poll

What level of tips would you like to see?

View Results

Loading ... Loading ...

Friends of MacTips

Subscribe to MacTips

Site Links