HTML fields to a document: content blocks written in HTML with inline CSS, for branded headers, styled sections, and layouts that a TEXT field can’t express. sajn sanitizes the HTML on the server, and the sealed PDF renders it as written.
HTML fields are an API feature. Use them for content your code generates. For content that people edit in the sajn app, use TEXT fields or a template.
Before you begin
- Store your API key in the
SAJN_API_KEYenvironment variable. To create a key, go to workspace settings in the sajn app, then Utvecklare (Developer) > API-nycklar (API keys). - Have a
DRAFTdocument. For more information, see Create a document. - To send a full HTML file, escape it as a JSON string first. For more information, see Format HTML for JSON.
Add HTML content
1
Create the HTML field
Send a Replace Compare the stored content with what you sent. sajn removes tags, attributes, and CSS values that aren’t in the allowlists that follow, without an error.
POST request to /api/v1/documents/DOCUMENT_ID/fields with the field in a fields array. Both type and fieldMeta.type are HTML, and fieldMeta.content holds the HTML:DOCUMENT_ID with the document ID. The response has the created field in data, and fieldMeta.content holds the sanitized HTML:2
Add several fields in order
To add a header and a footer around other content, send several fields in the The response has the created fields in
fields array. position is each field’s 0-based place among the document’s content blocks:data, in request order.3
Update the content
To replace the HTML of a field, send a Replace
PATCH request with the field’s id and the full fieldMeta:FIELD_ID with the field’s id. The response is the updated field. The page’s look, such as orientation, page size, and background, is set on the document in documentStyle. For its properties, see Create a new document.Allowed HTML tags
HTML fields support a safe subset of HTML tags for formatting and layout. All HTML content is automatically sanitized server-side.Text formatting
<p>,<span>,<div>- Basic containers<b>,<strong>- Bold text<i>,<em>- Italic text<u>- Underlined text<s>- Strikethrough text<mark>- Highlighted text<small>,<sub>,<sup>- Size and position
Headings
<h1>,<h2>,<h3>,<h4>,<h5>,<h6>- All heading levels
Lists
<ul>- Unordered lists<ol>- Ordered lists<li>- List items
Tables
<table>,<thead>,<tbody>,<tfoot>- Table structure<tr>,<td>,<th>- Table rows and cells<caption>- Table caption
Images
<img>- Images withsrc,alt,width,height,titleattributes
Links
<a>- Links withhref,target,rel,title(allowed schemes: http, https, mailto, tel only; dangerous schemes like javascript:, data:, vbscript: are stripped; all links forced totarget="_blank"andrel="noopener noreferrer"for security)
Other
<br>,<hr>- Line breaks and horizontal rules<label>,<input>- Checkbox lists;<input>keeps onlytype,checked, anddisabled<blockquote>- Quoted text<pre>,<code>- Code blocks
Allowed attributes
All elements:style- Inline CSS stylesclass- CSS class names
<img>):
src- Image source (HTTP/HTTPS URLs or data URIs)alt- Alternative textwidth,height- Dimensionstitle- Image title
<table>:border,cellpadding,cellspacing,width<td>,<th>:colspan,rowspan,align,valign
<p>,<div>,<h1>through<h6>:align
<a>):
href- URL (http, https, mailto, tel only)target- Forced to_blankfor securityrel- Forced tonoopener noreferrerfor securitytitle- Link title
Removed tags
The following tags are automatically removed for security:<script>- JavaScript (XSS protection)<iframe>- Embedded content<form>- Forms<style>- Style tags (use inline styles instead)
Allowed CSS properties
CSS works only in inlinestyle attributes. The following properties are supported:
Colors
color- Text color (hex, rgb, rgba)background-color- Background colorbackground- Background shorthand
Typography
font-size- Font size (px, rem, %, pt)font-weight- Font weight (normal, bold, 100-900)font-style- Font style (normal, italic)font-family- Font familyline-height- Line heightletter-spacing- Letter spacingtext-align- Text alignment (left, right, center, justify)text-decoration- Text decoration (underline, line-through)text-transform- Text transform (uppercase, lowercase, capitalize)
Spacing
margin,margin-top/right/bottom/left- Outer spacingpadding,padding-top/right/bottom/left- Inner spacing
Borders
border- Border shorthand (format:widthpx style #color, e.g.,2px solid #003366)border-top/right/bottom/left- Individual borders (same format as border shorthand)border-color- Border color (hex format)border-width- Border width (px values)border-style- Border style (solid, dashed, dotted, none)border-radius- Rounded corners (px, em, rem, %)
Layout
width,height- Element dimensionsmax-width,max-height- Maximum dimensionsmin-width,min-height- Minimum dimensionsdisplay- Display type (block, inline, inline-block, flex, grid, none)vertical-align- Vertical alignment (top, middle, bottom, baseline)box-sizing- Box model (border-box, content-box)
Flexbox
flex-direction- Direction of flex items (row, row-reverse, column, column-reverse)flex-wrap- Wrapping behavior (nowrap, wrap, wrap-reverse)align-items- Cross-axis alignment (flex-start, flex-end, center, baseline, stretch, start, end)align-content- Multi-line alignment (flex-start, flex-end, center, space-between, space-around, stretch, start, end)justify-content- Main-axis alignment (flex-start, flex-end, center, space-between, space-around, space-evenly, start, end)gap- Gap between flex items (px, em, rem, %)
Grid
grid-template-columns- Column track sizes (e.g.,1fr 1fr 1fr,repeat(3, 1fr),200px auto 1fr)grid-template-rows- Row track sizesgrid-column- Column placement for grid itemsgrid-row- Row placement for grid itemsgrid-area- Shorthand for grid placementgrid-gap- Gap between grid items (legacy, usegapinstead)row-gap- Gap between rowscolumn-gap- Gap between columnsgap- Gap between grid items (px, em, rem, %, fr)
List markers
list-style-type- List marker style (disc, circle, square, decimal, lower-alpha, upper-alpha, lower-roman, upper-roman, none)
Image hosting
HTML fields support both hosted image URLs and inline base64 data URIs. Use hosted URLs.Host images instead of inlining them
To host an image, upload it once with the presigned file-upload flow or any public URL you control, and reference the resultinghttps:// URL.
The same URL can be reused across every document and template — no per-document copies.
Use a hosted HTTPS URL
Avoid inline base64 data URIs
Accepted today for backwards compatibility, but avoid it — prefer a hosted URL:HTML field content can be up to 100 MB, so existing integrations keep working.
We recommend keeping content small, with text and hosted image URLs, because
the limit can be lowered in a future API version.
Sanitization
HTML fields are automatically sanitized server-side for security:Kept
- Formatting tags (
<p>,<div>,<span>, headings) - Links (
<a>) with http, https, mailto, tel URLs (forcedtarget="_blank"andrel="noopener noreferrer") - Inline CSS styles (colors, fonts, spacing)
- Images from HTTP/HTTPS/data URIs
- Tables, lists, and basic structure
Removed
<script>tags - JavaScript removed<iframe>tags - No embedded content<style>tags - No global stylesonclick,onerror- No event handlersjavascript:,data:,vbscript:- Dangerous URL schemes stripped from links
Example
Input:javascript: link is stripped; the safe https link is preserved with target="_blank" and rel="noopener noreferrer" added.
Handle errors
Validation errors are400 VALIDATION_FAILED, and issues lists every problem with its path. The most common one is a type that doesn’t match fieldMeta.type:
DRAFT returns 409 INVALID_STATE. Disallowed HTML isn’t an error: sajn removes it. For the error shape and every code, see Errors.
Next steps
Format HTML for JSON
Turn an HTML file into a valid request body.
Upload files
Host images and attach PDF files.
Send for signing
Send the document to its parties.
Create document fields
See every field type in the API reference.

