Skip to main content

Module serp

Module serp 

Source
Expand description

How wide a title and description render in Google’s results, in pixels, so the explorer can show where a snippet gets cut. Google sets titles in Arial 20 px and descriptions in Arial 14 px; the widths come from Arial’s advance widths (2048 units per em), grouped by width, with a sensible default for characters outside the table.

Constants§

DESCRIPTION_LIMIT_PX
Where Google cuts a description on desktop (about two lines).
TITLE_LIMIT_PX
Where Google cuts a title on desktop.

Functions§

description_px
Width of text set as a result description (Arial 14 px).
title_px
Width of text set as a result title (Arial 20 px).
truncate_to_px
Cuts text so it fits in limit pixels as measured by f, the way Google does: at a word boundary when that keeps most of the text, followed by " …". Returns the text and whether it was cut. The result, ellipsis included, never measures more than limit.