npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

return-top-level-elements-in-html

v1.2.0

Published

An npx tool that extracts and displays top-level DOM elements in a beautifully styled web page with Bootstrap and collapsible accordion navigation

Readme

Return Top Level Elements in HTML

An npx tool that extracts and displays the top-level DOM structure of HTML documents in a beautifully styled web page. Supports both local HTML files and remote URLs.

🚀 Usage

Run the tool in any directory that contains an HTML file, or provide a URL:

# Using npx (recommended - no installation needed)
npx return-top-level-elements-in-html [depth] [url]

# Or install globally and run
npm install -g return-top-level-elements-in-html
return-top-level-elements-in-html [depth] [url]

Parameters

  • depth (optional): Number of DOM levels to extract
    • Range: 1-20 levels
    • Default: 3 levels
  • url (optional): URL to fetch HTML from
    • If not provided, looks for local HTML files
    • Supports both http:// and https:// URLs

Examples

# Extract 3 levels from local file (default)
npx return-top-level-elements-in-html

# Extract 5 levels from local file
npx return-top-level-elements-in-html 5

# Extract 3 levels from a URL
npx return-top-level-elements-in-html 3 https://example.com

# Extract from URL with default depth (3 levels)
npx return-top-level-elements-in-html https://github.com

# Extract 1 level from a complex website
npx return-top-level-elements-in-html 1 https://stackoverflow.com

# Extract only 2 levels
npx return-top-level-elements-in-html 2

📋 Prerequisites

For local files: The tool looks for HTML files in the current directory in this order:

  • index.html
  • index.htm
  • main.html
  • home.html

For URLs: No prerequisites needed - just provide a valid HTTP or HTTPS URL.

✨ Features

  • Dual Input Support: Analyze local HTML files or fetch from remote URLs
  • Beautiful Bootstrap UI: Uses Bootstrap 5 via CDN for modern styling
  • Collapsible Accordion Interface: Each DOM level can be expanded/collapsed for easy navigation
  • Color-coded levels: Each DOM level has a different color for easy visualization
  • Interactive hover effects: Smooth animations when hovering over elements
  • Source Display: Shows whether analyzing a local file or URL source
  • Expand/Collapse Controls: Buttons to expand or collapse all levels at once
  • Keyboard Shortcuts: Ctrl/Cmd + E to expand all, Ctrl/Cmd + C to collapse all
  • Responsive design: Works on all screen sizes
  • Automatic browser opening: Opens the result page automatically
  • Detailed information: Shows element attributes and child counts
  • Scrollable tree view: Large DOM structures are easily navigable
  • Error handling: Proper error messages for network issues or invalid URLs

🎨 Output Features

The generated web page includes:

  • Collapsible Accordion Structure: Click any element to expand/collapse its children
  • Expand/Collapse All Buttons: Quick controls to expand or collapse the entire tree
  • Keyboard Shortcuts: Ctrl/Cmd + E (expand all), Ctrl/Cmd + C (collapse all)
  • Gradient background design
  • Color-coded DOM levels (6 different colors)
  • Element attributes display
  • Child element count badges
  • Legend for level colors
  • Statistics about the analysis
  • Smooth hover animations
  • Professional typography

🛠️ Technical Details

  • Built with Node.js
  • Uses JSDOM for HTML parsing
  • Automatically opens results in default browser
  • Generates self-contained HTML with inline CSS
  • Uses Bootstrap 5 CDN for styling

📄 License

MIT