Inspect DOM elements and their styles from Chrome using the Chrome DevTools Protocol.
inspect-dom connects to Chrome's remote debugging interface to inspect DOM elements and their CSS styles. It provides a command-line interface similar to Chrome DevTools for analyzing web page elements, their structure, and styling information.
Chrome must be launched with remote debugging enabled:
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --remote-debugging-port=9222npm installinspect-dom <selector> [options]<selector>- CSS selector for the element to inspect (e.g., '#myId', '.myClass', 'div.container')- Quote selectors that start with
#. In most shells#begins a comment, so use quotes or escape it:inspect-dom '#myId'orinspect-dom \#myId. - Use quotes for complex selectors with spaces or special characters
- Quote selectors that start with
-r, --recursive- Include child elements (default: only show matching element)--styles- Show declared CSS styles for each element--computed-styles- Show computed CSS styles for each element--show-implicit-styles- Include browser-computed and implicit CSS properties (default: explicit styles only)--debug- Show verbose debugging information (for troubleshooting only)-h, --help- Show help message
inspect-dom .bottom-nav-bar -r --styles--- DOM Structure ---
<div class="bottom-nav-bar">
<button class="nav-back-button">
<img src="/assets/nav-back.svg" alt="Back" />
</button>
<div class="nav-center-labels">
<div class="nav-product-name"></div>
<div class="nav-price"></div>
</div>
<button class="nav-add-to-cart-button"></button>
</div>
--- Style Information ---
<div class="bottom-nav-bar">:
Styles:
Stylesheet Styles:
.bottom-nav-bar - styles.css:95:
position: fixed
bottom: 0px
left: 0px
right: 0px
height: 77px
background-color: rgba(255, 255, 255, 0.75)
display: flex
align-items: center
z-index: 1000
Inherited Styles:
From ancestor level 1:
html, body:
margin: 0
margin-top: 0px
margin-right: 0px
margin-bottom: 0px
margin-left: 0px
<button class="nav-back-button">:
Styles:
Inline Styles:
style="transform: scale(1); transform-origin: left center;"
transform: scale(1)
transform-origin: left center
...
inspect-dom '#header'Show only the element with id "header"
inspect-dom .sidebar -rShow element with class "sidebar" and all its children
inspect-dom div.main-content --stylesShow element and its declared styles (no children)
inspect-dom .container -r --computed-stylesShow element and all children with computed styles
inspect-dom .nav -r --styles --computed-stylesShow element and children with both declared and computed styles
inspect-dom .container --styles --show-implicit-stylesShow element styles including browser-computed and implicit properties
inspect-dom .container --styles --debugShow element with verbose debugging information (for troubleshooting connection issues)
inspect-dom "div .container" --stylesShow descendant selector (quotes needed for spaces)
inspect-dom "input[type='text']" --stylesShow attribute selector (quotes needed for special characters)
- DOM Structure Display: Shows hierarchical DOM structure with tag names, IDs, and classes
- Style Analysis: Displays CSS styles in Chrome DevTools format
- Specificity Sorting: Orders CSS rules by specificity (highest first)
- Inheritance Display: Shows inherited styles from parent elements
- Stylesheet Mapping: Maps styles to their source files with line numbers
The tool provides structured output including:
- DOM Structure: Hierarchical display of elements
- Style Information:
- Inline styles (highest priority)
- Stylesheet styles (sorted by specificity)
- Inherited styles from parent elements
- Note: By default, only explicit CSS declarations are shown. Use
--show-implicit-stylesto include browser-computed defaults.
- Node.js
- Chrome browser with remote debugging enabled
- macOS (uses AppleScript for tab detection)
chrome-remote-interface- For connecting to Chrome's debugging protocol