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

react-device-meta-hook

v1.0.4

Published

A lightweight React hook that detects the user's browser, operating system, device type (mobile, tablet, desktop), screen orientation, and resolution. It automatically adds meaningful CSS classes to the `<html>` element, enabling responsive design and con

Downloads

6

Readme

react-detect-device-info

🧠 React hook to detect browser, OS, device type, orientation, resolution, and viewport heights, and apply them as CSS classes to the <html> element. Ideal for responsive design and adaptive UI development.


📦 Installation

npm install react-detect-device-info
# or
yarn add react-detect-device-info

🧩 What It Does

useDeviceDetect is a lightweight utility hook for React applications that:

  • Detects:
    • Browser name and version
    • Operating system (Windows, macOS, iOS, Android, etc.)
    • Device type (mobile, tablet, desktop)
    • Orientation (portrait or landscape)
    • Resolution (width × height)
    • Viewport height metrics: dvh, lvh, svh
  • Adds corresponding CSS classes to the <html> element.
  • Provides all the information via callback for JavaScript-level usage.

🎯 Why Use This?

Responsive design often depends on breakpoints, media queries, or JS-based logic. This hook enables:

  • Device-specific theming
  • OS or browser-specific styling
  • Fine-grained control over orientation/layout
  • Dynamic viewport unit support (for mobile browser UI adjustments)
  • Cleaner CSS without extra wrapper classes

🚀 Quick Start

1. Use the Hook in Your App

import React from "react";
import { useDeviceDetect } from "react-detect-device-info";

function App() {
  useDeviceDetect((info) => {
    console.log("Device Info:", info);
  });

  return <div>Hello world</div>;
}

export default App;

2. Resulting <html> Classes Example

<html class="chrome windows desktop landscape w1440 h900"></html>

You can now write CSS based on these classes:

.desktop .header {
  padding: 20px;
}

.ios .button {
  font-size: 16px;
}

.w375.h812 {
  font-size: 14px;
}

📋 API

useDeviceDetect(callback?)

| Parameter | Type | Description | | ---------- | ---------------------------- | ---------------------------------------------------- | | callback | (info: DeviceInfo) => void | Optional. Receives detailed info object as argument. |


DeviceInfo Object Shape

interface DeviceInfo {
  browser: {
    name: string;
    version: string;
  };
  os: string;
  deviceType: "mobile" | "tablet" | "desktop";
  orientation: "portrait" | "landscape";
  resolution: {
    width: number;
    height: number;
  };
  viewportHeights: {
    dvh: number; // dynamic viewport height
    lvh: number; // largest possible viewport height
    svh: number; // smallest viewport height (when address bar shown)
  };
}

🧠 How It Helps in Development

  • Adaptive CSS Styling: Apply styles conditionally without writing JS logic in every component.
  • Device-Aware Layouts: Easily build experiences optimized for phones, tablets, or desktops.
  • Safe Viewport Handling: Use dvh, lvh, and svh to deal with mobile browser toolbars (keyboard, address bar).
  • Debug-Friendly: With <html> classes like .android, .firefox, .tablet, you can test layouts more easily.
  • Avoid Overengineering: Let HTML and CSS handle device-based decisions without bloated layout logic.

🧪 Example Use Cases

  • Apply extra spacing on iOS Safari where needed:
.ios.safari .footer {
  padding-bottom: 80px;
}
  • Prevent content cutoff under Android address bar:
.android .page {
  height: 100svh; /* Safe height */
}
  • Style headers differently in landscape mode:
.landscape .header {
  flex-direction: row;
}

🔗 GitHub Profile


🙌 Acknowledgements

This hook was inspired by the need for responsive CSS control without bloated JS logic. Special thanks to the growing community focused on adaptive UX/UI.