Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

CanvasRenderingContext2D.fillText() draws a line of text; it does not wrap a long title onto new lines. To keep an OG image title inside a 1200px-wide canvas, choose a smaller inner text width, use measureText() to break the title into lines, and draw each line separately. The 1200px figure here is your canvas width, not a universal OG-image size requirement.

Why Canvas lets a title run past the edge

fillText(text, x, y) paints text at the requested coordinates. Without a width limit, the line can extend beyond the canvas. Adding the optional maxWidth argument does not insert line breaks: the browser may condense the text horizontally or use a smaller font to fit it, which can make a prominent title look squeezed or unexpectedly small. See MDN’s fillText() reference.

Canvas provides text drawing and measurement APIs, not automatic paragraph layout. Your code must choose the line breaks, then call fillText() once for each line.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Wrap the title with measureText()

Set the font before measuring so the width calculation matches the style you intend to draw. The following whitespace-based helper keeps whole words together and starts a new line when the next word would exceed the chosen width.

#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
function wrapCanvasText(ctx, text, maxWidth) {
  const words = text.trim().split(/s+/);
  const lines = [];
  let line = "";

  for (const word of words) {
    const candidate = line ? `${line} ${word}` : word;

    if (line && ctx.measureText(candidate).width > maxWidth) {
      lines.push(line);
      line = word;
    } else {
      line = candidate;
    }
  }

  if (line) lines.push(line);
  return lines;
}

ctx.font = "700 64px Inter, sans-serif";
ctx.textAlign = "left";
ctx.textBaseline = "top";

const padding = 72;
const maxWidth = canvas.width - padding * 2;
const lines = wrapCanvasText(ctx, title, maxWidth);
const lineHeight = 76;

lines.forEach((line, i) => {
  ctx.fillText(line, padding, padding + i * lineHeight);
});

Here, 72px of padding and a 76px line height are illustrative design choices, not Canvas requirements. Choose spacing that fits your font and composition. MDN documents measureText() and text baselines in its Canvas text-drawing tutorial.

Choose a safe text area, not the canvas edge

For a 1200px-wide bitmap, the title’s available width should be less than 1200px. Subtract left and right padding, plus any space reserved for logos or other design elements. A centered title also needs a width budget that leaves room on both sides; its x coordinate is an alignment point, not necessarily the left edge of the text.

Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
  • Check the bitmap dimensions with canvas.width and canvas.height. CSS can scale the canvas for display without changing its underlying bitmap dimensions.
  • Set ctx.font before both measurement and drawing. If you use a downloaded font, wait until it has loaded before laying out the title.
  • Use textAlign and textBaseline deliberately. Alignment controls how the x coordinate anchors each line; the baseline setting controls how the y coordinate anchors it.
  • Leave extra edge room for shadows, strokes, alignment, and glyph overhang. A measured text width is not a guaranteed visual clipping boundary: the WHATWG HTML Standard notes that glyphs drawn with fillText() or strokeText() can spill beyond the box implied by font size and measureText().

Handle long words and language-specific line breaks

The helper above splits on whitespace, so it does not divide a single unbroken word. If one word is wider than the safe area, choose a policy explicitly: allow that word to overflow, split it at an appropriate character boundary, or reduce the font size and measure again. Avoid silently shrinking every line with maxWidth if preserving a consistent title size matters.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A whitespace-based algorithm is also not a complete line-breaking system for every language or typographic convention. If your generator supports scripts that require more sophisticated shaping or break rules, use a layout approach designed for those requirements rather than assuming spaces are valid break points.

Rank #3
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.

When maxWidth is useful

Use fillText(text, x, y, maxWidth) when a title must stay on one line and browser-controlled fitting is acceptable. It may condense the line or reduce its font size, and it will not create multiple lines. For a prominent OG title where legibility and deliberate line breaks matter, measure and draw separate lines instead.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Check the rendered result

Test long titles and inspect the actual bitmap, not just the code or a scaled CSS preview. Include wide letters, punctuation, emoji, and the languages your generator accepts. Confirm each line remains inside the safe area and that the last line fits vertically within the canvas height.

Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.