How can I outline the elements of an HTML page in the browser to see the layout of the boxes? Modify the user agent style sheet?

13,450

Solution 1

It turns out I was looking for a browser extension a friend had mentioned a long time ago: the "Web Developer" extension.

http://chrispederick.com/work/web-developer/

Here's what it looks like outlining the block level elements:

enter image description here

It's available for Chrome, Firefox, and Opera. Apparently not for Safari.

Solution 2

I use this way

*:hover { 
   outline:1px blue solid;
 } 

Solution 3

You dont have to edit User agent style sheet as you can do it using developer tools [F12].

You need to add this code

*{border: 1px solid #fff}

Solution 4

If you are using Firefox Quantum:

https://addons.mozilla.org/en-US/firefox/addon/open-pesticide/?src=search

Open Pesticide by MatthewBaa

Outlines each element on the page to help you visualize their dimensions and overcome those annoying CSS layout issues. Requires zero permissions and completely open source.

Share:
13,450
Purplejacket
Author by

Purplejacket

Ruby on Rails and Javascript coder. Also Java and some others. Math background.

Updated on June 11, 2022

Comments

  • Purplejacket
    Purplejacket about 2 years

    In the Chrome devtools, Firefox devtools, Safari, Opera, etc., if I inspect an element I can see its bounding box nicely outlined when I mouse over the code for that element in the source panel. That's great. But what if I'd like to see how all (or most of) the elements on the page are laid out? For instance, maybe I'd like to see something like this:

    enter image description here

    In the Firefox "Style Editor" I've added these styles:

    div { border: 1px dotted pink }
    p   { border: 1px solid green }
    a   { border: 2px solid yellow }
    li  { border: 1px dashed cyan }
    img { border: 1px solid purple}
    

    (Chrome can't do this since it doesn't support the UAAG 2.0 web standard for accessibility). Since the user agent style sheet overrides the styles from the page, I see the kind of outlines I'm looking for.

    Now this is just a hack, and perhaps is sufficient, but are there other tools that do this, or something in the devtools that I didn't find?

    Note: I did find this answer regarding the "Show composited layer borders" under the Rendering menu option in Chrome, but it's not really what I'm looking for:

    https://superuser.com/questions/774424/grid-overlay-showing-up-as-soon-a-i-launch-chrome-developer-tools

  • Purplejacket
    Purplejacket over 7 years
    That looks like what I did, except one style rule instead of the five I had. Where in developer tools do you add this? Under "Style Editor" like I did for Firefox? And can this be done in Chrome as well?
  • Shiyaz
    Shiyaz over 6 years
    One more that does just that and lighter: Pesticide for Chrome
  • Purplejacket
    Purplejacket over 6 years
    There's also a Pesticide CSS that should work with Firefox: github.com/mrmrs/pesticide
  • Purplejacket
    Purplejacket over 6 years
    Ah, there is a Firefox Pesticide addon (though not compatible with Firefox Quantum as of this writing). addons.mozilla.org/en-US/firefox/addon/pesticide
  • jpka
    jpka over 5 years
    Works just fine, thank you! P.S. But unfortunately, not exposes/reveals background images/elements boundaries, is it possible? Mozilla Firefox 52.5.3
  • Purplejacket
    Purplejacket almost 4 years
    Wow! That's cool and super simple! E.g., in chrome I just click the plus icon in the top right corner of the styles panel right here on this very page, add that style rule, and I can move the mouse around to see an outline of every little element. Superb!
  • Purplejacket
    Purplejacket almost 4 years
    Adding style rules with Firefox is almost identical, pressing the plus symbol in the "Rules view" -- developer.mozilla.org/en-US/docs/Tools/Page_Inspector/How_to‌​/…
  • Purplejacket
    Purplejacket over 3 years
    Another one I just learned of: tachyons-x-ray chrome.google.com/webstore/detail/tachyons-x-ray/…
  • Purplejacket
    Purplejacket almost 2 years
    A supplemental idea: It sometimes helps to also add a *:nth-child(2n) selector using a different outline colour. The result is that the outlines alternate between the two colours as you descend down the tree. This can makes it easier to distinguish between different elements, and makes sibling vs parent-child relationships clearer. (Credit Peppertop Comics of YouTube.)