GetViewport

A lightweight, performant viewport detection library for modern web applications

Live Viewport Demo

Current breakpoint:
Width:
Type:
xs sm md lg xl xxl

Key Features

📱

Responsive Detection

Automatically detects viewport changes and provides current breakpoint information

⚡️

Performance First

Uses CSS variables for efficient viewport tracking without JavaScript polling

🎯

Simple API

Intuitive methods for checking viewport status and device type

Quick Start

// Initialize the viewport detector
const viewport = new GetViewport();

// Get current breakpoint and dimensions
console.log(viewport.getBreakpoint()); // e.g. 'md'
console.log(viewport.getWidth() + 'x' + viewport.getHeight());

// Check device type
if (viewport.isMobile()) {
    // Mobile-specific logic
} else if (viewport.isTablet()) {
    // Tablet-specific logic
} else if (viewport.isDesktop()) {
    // Desktop-specific logic
}

// Use with custom breakpoints
const customViewport = new GetViewport({
    small: 0,
    medium: 768,
    large: 1200
});

Breakpoints

Breakpoint Min Width Category
xs 0px Mobile
sm 576px Mobile
md 768px Tablet
lg 992px Desktop
xl 1200px Desktop
xxl 1400px Desktop