Feature Request: Ability to toggle highlight of an element to see its box model in the viewport

4,317 views
Skip to first unread message

Manjit Karve

unread,
Jul 5, 2017, 4:55:43 PM7/5/17
to Google Chrome Developer Tools
Hi,

The bounding box of an element is sometimes smaller or bigger than what is shown in the viewport, such as if its visibility is hidden, or it is laid out in a container that causes it to stretch (flexbox/cssgrid). In such cases it is difficult to observe the effect of styling changes on the element. I'm able to get around this sometimes by hovering on the DOM tree-node in the DevTools Elements tab, but that leaves the mouse unavailable to do other things.

Another alternative is putting the following code in my CSS:

#foo, #foo>*{background-color: rgba(255,255,255,0.1);}

This allows me to track the element and its children. However, it would be great if something in DevTools could do this.

Regards,
Manjit

P.S. This request started from this support tweet: https://twitter.com/laaltoofan/status/882547858292867076

Bennie Copeland

unread,
Aug 3, 2017, 11:32:26 AM8/3/17
to Google Chrome Developer Tools
I second this. It's the ONE feature that I think the IE developer tools does better.

Luke Hatfield

unread,
Nov 4, 2017, 11:09:33 AM11/4/17
to Google Chrome Developer Tools
+1

Kayce Basques

unread,
Jan 4, 2018, 6:04:51 PM1/4/18
to Google Chrome Developer Tools
Does the Box Model chart in the Styles pane suffice? Or do you need to view in the viewport specifically, for some reason?

Manjit Karve

unread,
Apr 13, 2018, 11:50:13 PM4/13/18
to Chrome DevTools
Hi Kayce,

Apologies for the late reply.

The Box Model chart requires the target element to remain selected in the DOM tree and still requires you to used the mouse pointer hovering over the margin/padding/border etc.. 

I'll give a example to explain my need better. Let's say I'm trying to tweak the :before and :after pseudo-elements for a box in order to give a "raised corner" shadow:
Image result for raised corner shadow css
The pseudo-elements would have been partially obscured (they're shadows, so underneath another element) and their edges indistinct (they're shadows :) ). The only way to see their boundary is to hover over them in the element tree or on the box-model chart. Currently I need to hover the mouse over the element and keep it hovered over there while I tweak the width, height, box-shadow etc. I cannot use my mouse for any other navigation. If it were possible to toggle the highlight state for an element, say right-click > highlight in the DOM tree, the psuedo-element would remain highlighted while I went around using the mouse for other things like tweaking the shadow using the excellent shadow editor, or pick a color etc..

I hope I have explained it better this time around. Let me know if you need more clarification.

Regards,
Manjit

PhistucK

unread,
Apr 14, 2018, 5:11:35 AM4/14/18
to Google Chrome Developer Tools
First, in case that was a problem, you can force the :hover state unconditionally (see the screenshot below).
Then, you can move to another element and back to your element with your keyboard arrows - that will keep the highlight on the page while you change its CSS properties.
It is not perfect, but it is something.




PhistucK

--
You received this message because you are subscribed to the Google Groups "Chrome DevTools" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-chrome-developer-tools+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-chrome-developer-tools/ed3d4fee-3a60-46b3-838b-b8836ee28913%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Kayce Basques

unread,
Apr 18, 2018, 11:26:32 AM4/18/18
to Chrome DevTools
Try PhistucK's suggestion. I think it'll get the job done in this case.

Manjit Karve

unread,
Apr 19, 2018, 1:35:27 AM4/19/18
to google-chrome-...@googlegroups.com
Thank you for your replies, PhistucK and Kayce. I'm afraid I might have been unclear again. I use the "Force hover state" facility all the time. I'll try to explain in another way.

In the following pen https://codepen.io/manjitkarve/pen/OZPVme (just an anchor with padding and margin that turns red on hover) I can use the "Force hover state" functionality that PhistucK has pointed out to keep the link red. What I cannot do is toggle highlight of the entire element itself on the canvas while I use the mouse for other things like in the image below:

The only way to highlight the element on the canvas is by hovering over it in the DOM tree. I can't toggle that highlight. It is only available via hover of the element or by hovering over the margin/padding/border in the bounding box control under computed style:


I believe this kind of toggling (maybe via the computed style bounding box itself) will be useful for visualizing changes to the bounding box as you make them. This is particularly useful when they happen because of transforms, shadows and perspective distortion because it is not immediately apparent whether or not the bounding box has changed at all. For example, in this pen https://codepen.io/manjitkarve/pen/gvwyea (playing cards that can be tilted and flipped) the bounding box of the card is different from the boundary of the card image. The shadow is a descendant of div.card, but is not included in the bounding box. And to see how things change while you tweak rotation angles or something, you have to keep hovering on the element in the DOM tree while trying to tab through values in the styles section:



I hope I have made more sense this time around.

Regards,
Manjit

On Wed, Apr 18, 2018 at 8:56 PM, 'Kayce Basques' via Chrome DevTools <google-chrome-...@googlegroups.com> wrote:
Try PhistucK's suggestion. I think it'll get the job done in this case.

--
You received this message because you are subscribed to a topic in the Google Groups "Chrome DevTools" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-chrome-developer-tools/7vuOpsVQaGs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-chrome-developer-tools+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-chrome-developer-tools/04a6c189-82bc-4da2-8ddf-769f1e57bd15%40googlegroups.com.

Kayce Basques

unread,
Apr 19, 2018, 11:35:58 AM4/19/18
to Chrome DevTools
Are you saying that you want to toggle the hover state on multiple items at once?

If so, have you tried right-clicking each element and selecting Force State > :hover?


Manjit Karve

unread,
Apr 19, 2018, 12:55:26 PM4/19/18
to google-chrome-...@googlegroups.com
Actually, I'm looking for a way to turn this blue highlighting on and off via toggling rather than hovering over its element in the DOM tree with the mouse:

There isn't currently any way to do that in Chrome :(. Hence the feature request.

Thanks for trying, Kayce. Saw your tweet over on Dev-tools twitter, probably triggered by this thread :)

Regards,
Manjit

--
You received this message because you are subscribed to a topic in the Google Groups "Chrome DevTools" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-chrome-developer-tools/7vuOpsVQaGs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-chrome-developer-tools+unsub...@googlegroups.com.

Kayce Basques

unread,
Apr 19, 2018, 1:26:10 PM4/19/18
to Chrome DevTools
Ah, OK. Yeah, I skimmed your last reply so I figured I may have misunderstood.

I got it now, let me see if there's any way around that.

Yes, this thread did indeed inspire that tweet. Thank you for the idea :)


On Wednesday, July 5, 2017 at 1:55:43 PM UTC-7, Manjit Karve wrote:

Manjit Karve

unread,
Apr 19, 2018, 1:50:28 PM4/19/18
to google-chrome-...@googlegroups.com
Thank you, Kayce. Maybe there's a function that I can call from the console. 

Regards,
Manjit

--
You received this message because you are subscribed to a topic in the Google Groups "Chrome DevTools" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-chrome-developer-tools/7vuOpsVQaGs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-chrome-developer-tools+unsub...@googlegroups.com.

Andy Cochrane

unread,
Jun 11, 2018, 8:12:04 AM6/11/18
to Chrome DevTools
Hello all.

I came here to request this feature but did a search first. I'm happy to see that others would find this useful.

There have been many times where I wished this was possible and would like to throw in an emphatic +1.

To be clear, I'm supporting the request for an option to turn on (and lock) the highlighting of an element. One example use case would be so you can see exactly how an element's size and position changes in response to resizing the browser or changing css.

Ideally, the different ways to toggle the element highlight lock would be via a little button or checkbox in the bottom right of the Elements pane, a keyboard shortcut and a context menu option.

Cheers,

Andy

Helder S Ribeiro

unread,
Aug 2, 2018, 5:29:38 AM8/2/18
to Chrome DevTools
I'd like to add my vote for this. It would be really useful make the node highlighting sticky when inspecting elements.

There's some "instant connection" Bret Victor argument to be made here vs using the computed layout box.

This is a follow up to a conversation with @ChromeDevTools on Twitter. Thanks for the attention!


Cheers,
Helder

Richard Honey

unread,
Dec 29, 2018, 5:16:47 AM12/29/18
to Chrome DevTools

This is such an important feature request.
 
I need to see the element's size, border, padding and margin continuously highlighted while I drag the window to the left and right, in order to have a clear visual of my changes as the css changes with the viewport.
 
A feature like this will be an insane time-saver!!! +1

Tiago Parreira

unread,
Feb 6, 2019, 8:53:59 AM2/6/19
to Chrome DevTools
I have longed for this since I started doing web development.
Invaluable and a huge time saver.

+1. Very needed.


On Wednesday, July 5, 2017 at 10:55:43 PM UTC+2, Manjit Karve wrote:

Andrew Lewis

unread,
Apr 6, 2020, 2:03:03 AM4/6/20
to Chrome DevTools
+1
I was looking for this today. I knew it existed, didn't realise it was only in IE though. I was sure it would be in Chrome but I guess not...

Christian Toffolo

unread,
May 14, 2020, 5:41:57 AM5/14/20
to Chrome DevTools
+1
I second this too... could be really useful to continuously see the box model of the selected element while changing its properties.
Reply all
Reply to author
Forward
0 new messages