Try It Out
This page has sample layouts below. Press M to activate, then click elements to measure them.
Main Content Area
Feature One
Description of the first feature goes here.
Feature Two
Description of the second feature goes here.
Feature Three
Description of the third feature goes here.
Widget
Aside content
Keyboard Shortcuts
Quick access to all measurement features.
Features
Everything you need to measure and align UI elements.
Select Mode
Click any element to see its dimensions (width × height) and position (x, y coordinates). The element is highlighted with a bounding box overlay.
Guides Mode
Click anywhere to place horizontal or vertical guides. Drag guides to reposition them. Use Delete/Backspace to remove the last guide.
Distance Overlays
Hold Alt (or tap the "Off/On" button in the toolbar on mobile) to see distances from the element to viewport edges.
Persistent Guides
Add the persist attribute to save guides in localStorage.
They'll be restored when you reload the page.
Mobile & Touch Support
Works on touch devices! Tap the floating button to activate, tap elements to measure, drag guides to reposition.
API Reference
Attributes, methods, and events.
Attributes
| Attribute | Type | Default | Description |
|---|---|---|---|
highlight-color | String | #3b82f6 | Color for element selection overlays |
guide-color | String | #f97316 | Color for alignment guides |
persist | Boolean | false | Save guides to localStorage |
position | String | bottom-right | FAB position: bottom-right, bottom-left, top-right, top-left |
hide-fab | Boolean | false | Hide the floating action button (keyboard-only mode) |
disabled | Boolean | false | Disable the component |
Methods
| Method | Description |
|---|---|
toggle() | Toggle measurement mode on/off |
enable() | Enable measurement mode |
disable() | Disable measurement mode |
clearGuides() | Remove all guides |
Events
| Event | Description |
|---|---|
measure-enabled | Fired when measurement mode is activated |
measure-disabled | Fired when measurement mode is deactivated |
Usage
Add the component to any page.
<!-- Basic usage -->
<script type="module" src="./src/page-measure.js"></script>
<page-measure></page-measure>
<!-- With custom colors -->
<page-measure
highlight-color="#8b5cf6"
guide-color="#22c55e">
</page-measure>
<!-- With persistent guides -->
<page-measure persist></page-measure>
<!-- Programmatic control -->
<script>
const measure = document.querySelector('page-measure');
// Enable via JavaScript
measure.enable();
// Listen for events
measure.addEventListener('measure-enabled', () => {
console.log('Measurement mode activated');
});
</script>