THE GITHTML FIELD GUIDE

Check data URL syntax when an embedded image will not render

A data URL embeds bytes, but its media type, encoding marker, separator, and encoded content must be correct. Check the comma separating metadata from data and verify whether the payload is percent-encoded or base64. Embedding removes a network request; it does not guarantee that the image format or document policy permits rendering.

Identify the hidden dependency

An SVG data URL can break when a hash or quote is interpreted as URL or markup syntax. A base64 payload can fail when the encoding marker is missing or the data was truncated during copying.

Begin with a tiny known-good local image and generate its data URL using an approved export tool. This separates a malformed URL from an unsupported or damaged original image. Compare the media type with the actual decoded format rather than the filename alone. A renamed JPEG is not a PNG simply because the source asset ends in .png. Keep the entire generated value intact when placing it in an HTML attribute, and avoid editors or transfer channels that may truncate long lines without an obvious warning.

Prepare the intended reading copy

Generate the representation from the actual asset instead of editing a long payload manually. Keep the original asset available for maintenance. For a large image, evaluate whether embedding makes the document unnecessarily heavy before choosing the single-file tradeoff.

Debug in layers. First check whether the original image opens independently. Next decode the data payload and confirm that the resulting file matches the original bytes or approved transformation. Then test that image in a minimal HTML fixture before returning to the full report. If the minimal fixture works but the report does not, investigate document policy, markup boundaries, or surrounding styles instead of repeatedly re-encoding the asset. For SVG, remember that embedding a drawing and preserving its own referenced resources are separate tasks; an encoded outer file can still contain dependencies that need review.

  1. Verify media type, comma separator, and the selected encoding scheme.
  2. Check for truncation or reserved characters in hand-edited payloads.
  3. Confirm both decoded content and actual rendering before considering the image embedded successfully.
text
data:image/png;base64,ENCODED_IMAGE_BYTES

Verify the offline result

Decode a test payload and compare the resulting asset with the original. Then test the complete HTML in the intended reader.

Keep an unencoded source asset and the generation method in the authoring materials so future editors can replace the image without hand-editing thousands of characters. Measure the resulting document size and decide whether the single-file benefit is worth the added payload. A large embedded screenshot that conveys one short status value may be better replaced with accessible text and a smaller illustrative crop.

Sources and further reading

AI-assisted writing with source-linked guidance and illustrative examples. Read our editorial approach or report a correction.

All offline reading guides →

Read as MarkdownAll guides

Check data URL syntax when an embedded image will not render · gitHtml