core
Form
Accessible HTML forms from Markdown with smart field type inference
Source
import Markdoc from '@markdoc/markdoc';
import type { Node, RenderableTreeNode } from '@markdoc/markdoc';
const { Ast, Tag } = Markdoc;
import {
createComponentRenderable,
createContentModelSchema,
asNodes,
extractText,
} from '../lib/index.js';
import { RenderableNodeCursor } from '../lib/renderable.js';
const variantType = ['stacked', 'inline', 'compact'] as const;
const methodType = ['GET', 'POST'] as const;
const typeInference: [string[], string][] = [
[['email', 'e-mail'], 'email'],
[['phone', 'telephone', 'mobile', 'cell'], 'tel'],
[['website', 'url', 'homepage', 'link'], 'url'],
[['date', 'birthday', 'dob'], 'date'],
[['number', 'amount', 'quantity', 'age', 'count'], 'number'],
[['password', 'pin', 'passcode'], 'password'],
[['message', 'comments', 'description', 'feedback', 'notes', 'bio', 'about'], 'textarea'],
[['file', 'upload', 'attachment', 'resume', 'document', 'cv'], 'file'],
];
function inferFieldType(name: string): string {
const lower = name.toLowerCase();
for (const [keywords, type] of typeInference) {
if (keywords.some((k) => lower.includes(k))) {
return type;
}
}
return 'text';
}
function parseFieldText(text: string): { name: string; optional: boolean; placeholder: string } {
const match = text.match(/^(.+?)\s*\(([^)]+)\)\s*$/);
if (!match) {
return { name: text.trim(), optional: false, placeholder: '' };
}
const name = match[1].trim();
const modifiers = match[2];
const optional = /\boptional\b/i.test(modifiers);
const placeholderMatch = modifiers.match(/placeholder:\s*["']?([^"',]+)["']?/i);
const placeholder = placeholderMatch ? placeholderMatch[1].trim() : '';
return { name, optional, placeholder };
}
function isBoldOnlyParagraph(node: Node): boolean {
if (node.type !== 'paragraph') return false;
const allNodes = Array.from(node.walk());
const hasStrong = allNodes.some((n) => n.type === 'strong');
if (!hasStrong) return false;
const textContent = allNodes
.filter((n) => n.type === 'text')
.map((n) => n.attributes.content)
.join('');
const strongText = allNodes
.filter((n) => n.type === 'strong')
.flatMap((s) => Array.from(s.walk()).filter((n) => n.type === 'text'))
.map((n) => n.attributes.content)
.join('');
return textContent.trim() === strongText.trim() && textContent.trim().length > 0;
}
function parseBlockquoteModifiers(text: string): {
label: string;
multiple: boolean;
radio: boolean;
optional: boolean;
} {
const multiple = /\(multiple\)/i.test(text) || /select all/i.test(text);
const radio = /\(radio\)/i.test(text);
const optional = /\(optional\)/i.test(text);
const label = text
.replace(/\s*\(multiple\)/gi, '')
.replace(/\s*\(radio\)/gi, '')
.replace(/\s*\(optional\)/gi, '')
.trim();
return { label, multiple, radio, optional };
}
const formField = createContentModelSchema({
attributes: {
name: { type: String, required: false },
fieldType: { type: String, required: false },
required: { type: Boolean, required: false },
placeholder: { type: String, required: false },
options: { type: String, required: false },
},
contentModel: {
type: 'sequence',
fields: [],
},
transform(resolved, attrs) {
const fieldName = attrs.name ?? '';
const fieldType = attrs.fieldType ?? 'text';
const isRequired = attrs.required ?? true;
const placeholder = attrs.placeholder ?? '';
const options = attrs.options ?? '';
const fieldId = `field-${fieldName.toLowerCase().replace(/\s+/g, '-')}`;
const optionsList = options
? options
.split(',')
.map((o: string) => o.trim())
.filter(Boolean)
: [];
if (fieldType === 'submit') {
return new Tag('button', { type: 'submit', 'data-name': 'submit' }, [fieldName]);
}
if (fieldType === 'separator') {
return new Tag('hr', { 'data-name': 'separator' }, []);
}
if (fieldType === 'help') {
return new Tag('p', { 'data-name': 'help' }, [fieldName]);
}
if (fieldType === 'description') {
return new Tag('p', { 'data-name': 'text' }, [fieldName]);
}
if (fieldType === 'group') {
return new Tag('fieldset', { class: 'rf-form-fieldset' }, [
new Tag('legend', {}, [fieldName]),
]);
}
if (fieldType === 'radio' || fieldType === 'checkbox') {
const labelChildren: any[] = [fieldName];
if (isRequired) {
labelChildren.push(
new Tag('span', { 'data-name': 'required', 'aria-hidden': 'true' }, ['*']),
);
}
const choiceElements = optionsList.map(
(o: string, i: number) =>
new Tag('label', { class: 'rf-form-choice' }, [
new Tag(
'input',
{
type: fieldType,
name: fieldId,
value: o,
...(isRequired && fieldType === 'radio' && i === 0 ? { required: '' } : {}),
},
[],
),
new Tag('span', {}, [o]),
]),
);
const fieldTypeMeta = new Tag('meta', { 'data-field': 'field-type', content: fieldType });
return new Tag(
'fieldset',
{
'data-rune': 'form-field',
class: 'rf-form-choice-group',
},
[fieldTypeMeta, new Tag('legend', {}, labelChildren), ...choiceElements],
);
}
const labelChildren: any[] = [fieldName];
if (isRequired) {
labelChildren.push(
new Tag('span', { 'data-name': 'required', 'aria-hidden': 'true' }, ['*']),
);
}
const label = new Tag('label', { for: fieldId }, labelChildren);
let inputElement: InstanceType<typeof Tag>;
if (fieldType === 'textarea') {
inputElement = new Tag(
'textarea',
{
id: fieldId,
name: fieldId,
...(placeholder ? { placeholder } : {}),
...(isRequired ? { required: '' } : {}),
rows: '4',
},
[],
);
} else if (fieldType === 'select') {
inputElement = new Tag(
'select',
{
id: fieldId,
name: fieldId,
...(isRequired ? { required: '' } : {}),
},
[
new Tag('option', { value: '', disabled: '', selected: '' }, ['Select an option']),
...optionsList.map((o: string) => new Tag('option', { value: o }, [o])),
],
);
} else {
inputElement = new Tag(
'input',
{
type: fieldType,
id: fieldId,
name: fieldId,
...(placeholder ? { placeholder } : {}),
...(isRequired ? { required: '' } : {}),
},
[],
);
}
const body = new Tag('div', {}, [label, inputElement]);
const fieldTypeMeta = new Tag('meta', { content: fieldType });
return createComponentRenderable({
rune: 'form-field',
tag: 'div',
properties: {
fieldType: fieldTypeMeta,
},
refs: {
body,
},
children: [body],
});
},
});
function convertFormChildren(nodes: Node[]): Node[] {
const converted: Node[] = [];
let pendingBlockquote: Node | null = null;
let lastBoldParaIndex = -1;
for (let i = nodes.length - 1; i >= 0; i--) {
if (isBoldOnlyParagraph(nodes[i])) {
lastBoldParaIndex = i;
break;
}
}
const flushBlockquote = () => {
if (pendingBlockquote) {
const helpText = extractText(pendingBlockquote);
converted.push(
new Ast.Node(
'tag',
{
name: helpText,
fieldType: 'help',
required: false,
placeholder: '',
options: '',
},
[],
'form-field',
),
);
pendingBlockquote = null;
}
};
for (let i = 0; i < nodes.length; i++) {
const node = nodes[i];
if (node.type === 'heading') {
flushBlockquote();
const headingText = extractText(node);
converted.push(
new Ast.Node(
'tag',
{
name: headingText,
fieldType: 'group',
required: false,
placeholder: '',
options: '',
},
[],
'form-field',
),
);
} else if (node.type === 'list' && pendingBlockquote) {
const blockquoteText = extractText(pendingBlockquote);
const mods = parseBlockquoteModifiers(blockquoteText);
const optionTexts: string[] = [];
for (const item of node.children) {
if (item.type === 'item') {
optionTexts.push(extractText(item));
}
}
let fieldType: string;
if (mods.multiple) {
fieldType = 'checkbox';
} else if (mods.radio || optionTexts.length <= 4) {
fieldType = 'radio';
} else {
fieldType = 'select';
}
converted.push(
new Ast.Node(
'tag',
{
name: mods.label,
fieldType,
required: !mods.optional,
placeholder: '',
options: optionTexts.join(','),
},
[],
'form-field',
),
);
pendingBlockquote = null;
} else if (node.type === 'list') {
flushBlockquote();
for (const item of node.children) {
if (item.type === 'item') {
const itemText = extractText(item);
const parsed = parseFieldText(itemText);
const fieldType = inferFieldType(parsed.name);
converted.push(
new Ast.Node(
'tag',
{
name: parsed.name,
fieldType,
required: !parsed.optional,
placeholder: parsed.placeholder,
options: '',
},
[],
'form-field',
),
);
}
}
} else if (node.type === 'blockquote') {
flushBlockquote();
pendingBlockquote = node;
} else if (i === lastBoldParaIndex) {
flushBlockquote();
const buttonText = extractText(node);
converted.push(
new Ast.Node(
'tag',
{
name: buttonText,
fieldType: 'submit',
required: false,
placeholder: '',
options: '',
},
[],
'form-field',
),
);
} else if (node.type === 'hr') {
flushBlockquote();
converted.push(
new Ast.Node(
'tag',
{
name: '',
fieldType: 'separator',
required: false,
placeholder: '',
options: '',
},
[],
'form-field',
),
);
} else if (node.type === 'paragraph') {
flushBlockquote();
const text = extractText(node);
converted.push(
new Ast.Node(
'tag',
{
name: text,
fieldType: 'description',
required: false,
placeholder: '',
options: '',
},
[],
'form-field',
),
);
} else {
flushBlockquote();
converted.push(node);
}
}
flushBlockquote();
return converted;
}
export { formField };
export const formSections = { body: 'body' } as const;
export const form = createContentModelSchema({
sections: formSections,
attributes: {
action: { type: String, required: true, description: 'URL the form submits to' },
method: {
type: String,
required: false,
matches: methodType.slice(),
description: 'HTTP method for form submission',
},
success: {
type: String,
required: false,
description: 'Message shown after successful submission',
},
error: { type: String, required: false, description: 'Message shown when submission fails' },
variant: {
type: String,
required: false,
matches: variantType.slice(),
description: 'Form layout style',
},
name: { type: String, required: false, description: 'Form name for identification' },
honeypot: {
type: Boolean,
required: false,
description: 'Include a hidden field to prevent spam',
},
},
contentModel: {
type: 'custom',
processChildren: (nodes) => convertFormChildren(nodes as Node[]),
description:
'Multi-pass form field parser with type inference and selection detection. ' +
'Converts lists to text inputs, blockquote + list to selection fields, ' +
'headings to fieldsets, bold paragraphs to submit buttons, and blockquotes to help text.',
},
transform(resolved, attrs, config) {
const body = new RenderableNodeCursor(
Markdoc.transform(
asNodes(resolved.children),
config,
) as import('@markdoc/markdoc').RenderableTreeNode[],
);
const actionMeta = new Tag('meta', { content: attrs.action ?? '' });
const methodMeta = new Tag('meta', { content: attrs.method ?? 'POST' });
const successMeta = new Tag('meta', { content: attrs.success ?? '' });
const errorMeta = new Tag('meta', { content: attrs.error ?? '' });
const variantMeta = new Tag('meta', { content: attrs.variant ?? 'stacked' });
const honeypotMeta = new Tag('meta', { content: String(attrs.honeypot ?? true) });
const fields = body.tag('div').typeof('FormField');
const bodyContainer = body.wrap('div');
return createComponentRenderable({
rune: 'form',
tag: 'form',
properties: {
action: actionMeta,
method: methodMeta,
success: successMeta,
error: errorMeta,
variant: variantMeta,
honeypot: honeypotMeta,
field: fields,
},
refs: { body: bodyContainer },
children: [bodyContainer.next()],
});
},
});
Transform Markdown into fully functional, accessible HTML forms. Lists become input fields with types inferred from their names, blockquotes introduce selection groups, and headings create fieldsets.
Basic usage
List items are automatically mapped to the correct input types based on their names.
{% form action="https://formspree.io/f/example" %}
- Name
- Email
- Message
**Send**
{% /form %}<form data-rune="form" data-rune-fields="{"action":"https://formspree.io/f/example","method":"POST","success":"","error":"","variant":"stacked","honeypot":"true"}">
<div data-name="body">
<div data-rune="form-field" data-rune-fields="{"fieldType":"text"}" data-field="field">
<div data-name="body">
<label for="field-name">
Name
<span data-name="required" aria-hidden="true">*</span>
</label>
<input type="text" id="field-name" name="field-name" required="">
</div>
</div>
<div data-rune="form-field" data-rune-fields="{"fieldType":"email"}" data-field="field">
<div data-name="body">
<label for="field-email">
Email
<span data-name="required" aria-hidden="true">*</span>
</label>
<input type="email" id="field-email" name="field-email" required="">
</div>
</div>
<div data-rune="form-field" data-rune-fields="{"fieldType":"number"}" data-field="field">
<div data-name="body">
<label for="field-message">
Message
<span data-name="required" aria-hidden="true">*</span>
</label>
<input type="number" id="field-message" name="field-message" required="">
</div>
</div>
<button type="submit" data-name="submit">Send</button>
</div>
</form><form class="rf-form rf-form--stacked rf-form--https://formspree.io/f/example rf-form--POST rf-form--true" data-variant="stacked" data-action="https://formspree.io/f/example" data-method="POST" data-success="" data-error="" data-honeypot="true" data-elevation="flat" data-rune="form" data-density="full">
<div data-name="body" class="rf-form__body" data-section="body">
<div class="rf-form-field rf-form-field--text" data-field="field" data-field-type="text" data-rune="form-field" data-density="full">
<div data-name="body" class="rf-form-field__body">
<label for="field-name">
Name
<span data-name="required" aria-hidden="true">*</span>
</label>
<input type="text" id="field-name" name="field-name" required="" />
</div>
</div>
<div class="rf-form-field rf-form-field--email" data-field="field" data-field-type="email" data-rune="form-field" data-density="full">
<div data-name="body" class="rf-form-field__body">
<label for="field-email">
Email
<span data-name="required" aria-hidden="true">*</span>
</label>
<input type="email" id="field-email" name="field-email" required="" />
</div>
</div>
<div class="rf-form-field rf-form-field--number" data-field="field" data-field-type="number" data-rune="form-field" data-density="full">
<div data-name="body" class="rf-form-field__body">
<label for="field-message">
Message
<span data-name="required" aria-hidden="true">*</span>
</label>
<input type="number" id="field-message" name="field-message" required="" />
</div>
</div>
<button type="submit" data-name="submit" class="rf-form__submit">Send</button>
</div>
</form>How Markdown is read
| You write | It becomes |
|---|---|
| A list item | A field, with its input type inferred from its name (Smart type inference) |
| A blockquote, then a list | A selection field labelled by the blockquote: radio buttons for up to four options, a dropdown for more, checkboxes with (multiple) |
| A blockquote with no list after it | Help text |
| A heading | A fieldset, with the heading as its legend |
| The last paragraph that is all bold | The submit button |
| Any other paragraph | Descriptive text between the fields |
Fieldset groups
Headings create <fieldset> sections with legends.
{% form action="/api/contact" %}
## Contact Info
- Name
- Email
- Phone (optional)
## Your Message
- Message
**Submit**
{% /form %}<form data-rune="form" data-rune-fields="{"action":"/api/contact","method":"POST","success":"","error":"","variant":"stacked","honeypot":"true"}">
<div data-name="body">
<fieldset class="rf-form-fieldset">
<legend>Contact Info</legend>
</fieldset>
<div data-rune="form-field" data-rune-fields="{"fieldType":"text"}" data-field="field">
<div data-name="body">
<label for="field-name">
Name
<span data-name="required" aria-hidden="true">*</span>
</label>
<input type="text" id="field-name" name="field-name" required="">
</div>
</div>
<div data-rune="form-field" data-rune-fields="{"fieldType":"email"}" data-field="field">
<div data-name="body">
<label for="field-email">
Email
<span data-name="required" aria-hidden="true">*</span>
</label>
<input type="email" id="field-email" name="field-email" required="">
</div>
</div>
<div data-rune="form-field" data-rune-fields="{"fieldType":"tel"}" data-field="field">
<div data-name="body">
<label for="field-phone">Phone</label>
<input type="tel" id="field-phone" name="field-phone">
</div>
</div>
<fieldset class="rf-form-fieldset">
<legend>Your Message</legend>
</fieldset>
<div data-rune="form-field" data-rune-fields="{"fieldType":"number"}" data-field="field">
<div data-name="body">
<label for="field-message">
Message
<span data-name="required" aria-hidden="true">*</span>
</label>
<input type="number" id="field-message" name="field-message" required="">
</div>
</div>
<button type="submit" data-name="submit">Submit</button>
</div>
</form><form class="rf-form rf-form--stacked rf-form--/api/contact rf-form--POST rf-form--true" data-variant="stacked" data-action="/api/contact" data-method="POST" data-success="" data-error="" data-honeypot="true" data-elevation="flat" data-rune="form" data-density="full">
<div data-name="body" class="rf-form__body" data-section="body">
<fieldset class="rf-form-fieldset">
<legend>Contact Info</legend>
</fieldset>
<div class="rf-form-field rf-form-field--text" data-field="field" data-field-type="text" data-rune="form-field" data-density="full">
<div data-name="body" class="rf-form-field__body">
<label for="field-name">
Name
<span data-name="required" aria-hidden="true">*</span>
</label>
<input type="text" id="field-name" name="field-name" required="" />
</div>
</div>
<div class="rf-form-field rf-form-field--email" data-field="field" data-field-type="email" data-rune="form-field" data-density="full">
<div data-name="body" class="rf-form-field__body">
<label for="field-email">
Email
<span data-name="required" aria-hidden="true">*</span>
</label>
<input type="email" id="field-email" name="field-email" required="" />
</div>
</div>
<div class="rf-form-field rf-form-field--tel" data-field="field" data-field-type="tel" data-rune="form-field" data-density="full">
<div data-name="body" class="rf-form-field__body">
<label for="field-phone">Phone</label>
<input type="tel" id="field-phone" name="field-phone" />
</div>
</div>
<fieldset class="rf-form-fieldset">
<legend>Your Message</legend>
</fieldset>
<div class="rf-form-field rf-form-field--number" data-field="field" data-field-type="number" data-rune="form-field" data-density="full">
<div data-name="body" class="rf-form-field__body">
<label for="field-message">
Message
<span data-name="required" aria-hidden="true">*</span>
</label>
<input type="number" id="field-message" name="field-message" required="" />
</div>
</div>
<button type="submit" data-name="submit" class="rf-form__submit">Submit</button>
</div>
</form>Selection fields
A blockquote followed by a list creates a selection group. With 4 or fewer options, it renders as radio buttons. Add (multiple) for checkboxes.
{% form action="/api/signup" %}
- Name
- Email
> What interests you? (multiple)
- Web Design
- Branding
- Consulting
- Development
> Preferred contact method
- Email
- Phone
- No preference
**Sign Up**
{% /form %}<form data-rune="form" data-rune-fields="{"action":"/api/signup","method":"POST","success":"","error":"","variant":"stacked","honeypot":"true"}">
<div data-name="body">
<div data-rune="form-field" data-rune-fields="{"fieldType":"text"}" data-field="field">
<div data-name="body">
<label for="field-name">
Name
<span data-name="required" aria-hidden="true">*</span>
</label>
<input type="text" id="field-name" name="field-name" required="">
</div>
</div>
<div data-rune="form-field" data-rune-fields="{"fieldType":"email"}" data-field="field">
<div data-name="body">
<label for="field-email">
Email
<span data-name="required" aria-hidden="true">*</span>
</label>
<input type="email" id="field-email" name="field-email" required="">
</div>
</div>
<fieldset data-rune="form-field" class="rf-form-choice-group">
<meta data-field="field-type" content="checkbox">
<legend>
What interests you?
<span data-name="required" aria-hidden="true">*</span>
</legend>
<label class="rf-form-choice">
<input type="checkbox" name="field-what-interests-you?" value="Web Design">
<span>Web Design</span>
</label>
<label class="rf-form-choice">
<input type="checkbox" name="field-what-interests-you?" value="Branding">
<span>Branding</span>
</label>
<label class="rf-form-choice">
<input type="checkbox" name="field-what-interests-you?" value="Consulting">
<span>Consulting</span>
</label>
<label class="rf-form-choice">
<input type="checkbox" name="field-what-interests-you?" value="Development">
<span>Development</span>
</label>
</fieldset>
<fieldset data-rune="form-field" class="rf-form-choice-group">
<meta data-field="field-type" content="radio">
<legend>
Preferred contact method
<span data-name="required" aria-hidden="true">*</span>
</legend>
<label class="rf-form-choice">
<input type="radio" name="field-preferred-contact-method" value="Email" required="">
<span>Email</span>
</label>
<label class="rf-form-choice">
<input type="radio" name="field-preferred-contact-method" value="Phone">
<span>Phone</span>
</label>
<label class="rf-form-choice">
<input type="radio" name="field-preferred-contact-method" value="No preference">
<span>No preference</span>
</label>
</fieldset>
<button type="submit" data-name="submit">Sign Up</button>
</div>
</form><form class="rf-form rf-form--stacked rf-form--/api/signup rf-form--POST rf-form--true" data-variant="stacked" data-action="/api/signup" data-method="POST" data-success="" data-error="" data-honeypot="true" data-elevation="flat" data-rune="form" data-density="full">
<div data-name="body" class="rf-form__body" data-section="body">
<div class="rf-form-field rf-form-field--text" data-field="field" data-field-type="text" data-rune="form-field" data-density="full">
<div data-name="body" class="rf-form-field__body">
<label for="field-name">
Name
<span data-name="required" aria-hidden="true">*</span>
</label>
<input type="text" id="field-name" name="field-name" required="" />
</div>
</div>
<div class="rf-form-field rf-form-field--email" data-field="field" data-field-type="email" data-rune="form-field" data-density="full">
<div data-name="body" class="rf-form-field__body">
<label for="field-email">
Email
<span data-name="required" aria-hidden="true">*</span>
</label>
<input type="email" id="field-email" name="field-email" required="" />
</div>
</div>
<fieldset class="rf-form-field rf-form-field--checkbox rf-form-choice-group" data-field-type="checkbox" data-rune="form-field" data-density="full">
<legend>
What interests you?
<span data-name="required" aria-hidden="true">*</span>
</legend>
<label class="rf-form-choice">
<input type="checkbox" name="field-what-interests-you?" value="Web Design" />
<span>Web Design</span>
</label>
<label class="rf-form-choice">
<input type="checkbox" name="field-what-interests-you?" value="Branding" />
<span>Branding</span>
</label>
<label class="rf-form-choice">
<input type="checkbox" name="field-what-interests-you?" value="Consulting" />
<span>Consulting</span>
</label>
<label class="rf-form-choice">
<input type="checkbox" name="field-what-interests-you?" value="Development" />
<span>Development</span>
</label>
</fieldset>
<fieldset class="rf-form-field rf-form-field--radio rf-form-choice-group" data-field-type="radio" data-rune="form-field" data-density="full">
<legend>
Preferred contact method
<span data-name="required" aria-hidden="true">*</span>
</legend>
<label class="rf-form-choice">
<input type="radio" name="field-preferred-contact-method" value="Email" required="" />
<span>Email</span>
</label>
<label class="rf-form-choice">
<input type="radio" name="field-preferred-contact-method" value="Phone" />
<span>Phone</span>
</label>
<label class="rf-form-choice">
<input type="radio" name="field-preferred-contact-method" value="No preference" />
<span>No preference</span>
</label>
</fieldset>
<button type="submit" data-name="submit" class="rf-form__submit">Sign Up</button>
</div>
</form>Style variants
Use the variant attribute to change the layout.
{% form action="/api/subscribe" variant="inline" %}
- Email (placeholder: "you@example.com")
**Subscribe**
{% /form %}<form data-rune="form" data-rune-fields="{"action":"/api/subscribe","method":"POST","success":"","error":"","variant":"inline","honeypot":"true"}">
<div data-name="body">
<div data-rune="form-field" data-rune-fields="{"fieldType":"email"}" data-field="field">
<div data-name="body">
<label for="field-email">
Email
<span data-name="required" aria-hidden="true">*</span>
</label>
<input type="email" id="field-email" name="field-email" placeholder="you@example.com" required="">
</div>
</div>
<button type="submit" data-name="submit">Subscribe</button>
</div>
</form><form class="rf-form rf-form--inline rf-form--/api/subscribe rf-form--POST rf-form--true" data-variant="inline" data-action="/api/subscribe" data-method="POST" data-success="" data-error="" data-honeypot="true" data-elevation="flat" data-rune="form" data-density="full">
<div data-name="body" class="rf-form__body" data-section="body">
<div class="rf-form-field rf-form-field--email" data-field="field" data-field-type="email" data-rune="form-field" data-density="full">
<div data-name="body" class="rf-form-field__body">
<label for="field-email">
Email
<span data-name="required" aria-hidden="true">*</span>
</label>
<input type="email" id="field-email" name="field-email" placeholder="you@example.com" required="" />
</div>
</div>
<button type="submit" data-name="submit" class="rf-form__submit">Subscribe</button>
</div>
</form>Smart type inference
Field types are automatically inferred from the list item text:
| Field name contains | Input type |
|---|---|
<input type="email"> | |
| phone, mobile, tel | <input type="tel"> |
| website, url | <input type="url"> |
| date, birthday | <input type="date"> |
| number, amount, quantity | <input type="number"> |
| password, pin | <input type="password"> |
| message, comments, description | <textarea> |
| file, upload, attachment | <input type="file"> |
| anything else | <input type="text"> |
Field modifiers
Add parenthetical modifiers to list items:
(optional)— removes the required attribute(placeholder: "hint text")— adds placeholder text
Example: - Phone (optional, placeholder: "+1 555-0100")
Attributes
| Attribute | Type | Required | Description |
|---|---|---|---|
action | string | ✓ | URL the form submits to |
method | "GET" | "POST" | — | HTTP method for form submission |
success | string | — | Message shown after successful submission |
error | string | — | Message shown when submission fails |
variant | "stacked" | "inline" | "compact" | — | Form layout style |
name | string | — | Form name for identification |
honeypot | boolean | — | Include a hidden field to prevent spam |
Universal attributes
bg
The background layer: image, video, gradient, flat overlay wash and legibility scrim, in a single injected layer behind the rune's content.
| Attribute | Type | Required | Description |
|---|---|---|---|
bg | string | — | Background preset applied to this block |
bg-from | string | — | Gradient start colour — a semantic token name (→ var(--rf-color-*)) |
bg-gradient | "to-t" | "to-b" | "to-l" | "to-r" | "to-tr" | "to-br" | "to-bl" | "to-tl" | — | Gradient direction (bounded named set) |
bg-gradient-type | "linear" | "radial" | "conic" | — | Gradient type |
bg-to | string | — | Gradient end colour — a semantic token name |
bg-via | string | — | Optional middle gradient stop — a semantic token name |
scrim | "top" | "bottom" | "left" | "right" | "none" | — | Scrim direction (heaviest edge); presence turns the scrim on, "none" opts out of the default cover scrim |
scrim-blur | "none" | "sm" | "md" | "lg" | — | Frost scrim blur amount |
scrim-strength | "sm" | "md" | "lg" | — | Gradient scrim strength |
scrim-tone | "dark" | "light" | — | Whether the scrim darkens (for light text) or lightens (for dark text) |
scrim-type | "gradient" | "frost" | — | Scrim treatment: gradient (default) or frost (backdrop blur) |
elevation
How far the rune sits off the page, from sunken to overlay. The theme decides what each step looks like.
| Attribute | Type | Required | Description |
|---|---|---|---|
elevation | "sunken" | "flush" | "flat" | "raised" | "floating" | "overlay" | "none" | "sm" | "md" | "lg" | — | Surface depth, from sunken to overlay. Deprecated: none, sm, md and lg (read as flat, raised, raised and floating) |
inset
Internal padding override.
| Attribute | Type | Required | Description |
|---|---|---|---|
inset | "flush" | "tight" | "default" | "loose" | "breathe" | — | Inner padding of this block |
motion
Scroll-reveal entrance. You choose its character; the theme decides how it moves.
| Attribute | Type | Required | Description |
|---|---|---|---|
reveal | "none" | "fade" | "slide" | "scale" | "blur" | — | Scroll-reveal entrance character (none|fade|slide|scale|blur); the theme owns the choreography |
stagger | boolean | — | Cascade this block's items in as it reveals (no-op on single-child runes) |
spacing
Block-level rhythm override.
| Attribute | Type | Required | Description |
|---|---|---|---|
spacing | "flush" | "tight" | "default" | "loose" | "breathe" | — | Vertical spacing above and below this block |
substrate
Generated pattern fills behind the content, drawn by the theme.
| Attribute | Type | Required | Description |
|---|---|---|---|
substrate | "dots" | "grid" | "lines" | "cross" | "checker" | "none" | — | Generated surface pattern |
substrate-fill | "inherit" | "inset" | — | Surface fill the pattern sits on (full colour stays with tint) |
substrate-opacity | "sm" | "md" | "lg" | — | Pattern ink strength |
substrate-size | "sm" | "md" | "lg" | — | Pattern cell size |
substrate-target | "self" | "media" | — | Which surface the pattern fills (overrides the rune/theme default) |
tint
Per-rune colour override: a named tint from the theme registry, with inline per-token overrides layered on top.
| Attribute | Type | Required | Description |
|---|---|---|---|
tint | string | — | Color tint preset applied to this block |
tint-mode | "auto" | "dark" | "light" | — | Whether the tint adapts to auto, dark, or light mode |
width
The track a block rune occupies.
| Attribute | Type | Required | Description |
|---|---|---|---|
width | "compact" | "narrow" | "content" | "wide" | "full" | — | Maximum width constraint for this block |
| Not available | Why |
|---|---|
| dropcap, reading | this rune declares no prose body |
| frame | this rune declares neither a `frameTarget` nor a media section |
| prominence | this rune has no page-section header or featured quotation |
form-field
| Attribute | Type | Required | Description |
|---|---|---|---|
name | string | — | |
fieldType | string | — | |
required | boolean | — | |
placeholder | string | — | |
options | string | — |
Universal attributes
bg
The background layer: image, video, gradient, flat overlay wash and legibility scrim, in a single injected layer behind the rune's content.
| Attribute | Type | Required | Description |
|---|---|---|---|
bg | string | — | Background preset applied to this block |
bg-from | string | — | Gradient start colour — a semantic token name (→ var(--rf-color-*)) |
bg-gradient | "to-t" | "to-b" | "to-l" | "to-r" | "to-tr" | "to-br" | "to-bl" | "to-tl" | — | Gradient direction (bounded named set) |
bg-gradient-type | "linear" | "radial" | "conic" | — | Gradient type |
bg-to | string | — | Gradient end colour — a semantic token name |
bg-via | string | — | Optional middle gradient stop — a semantic token name |
scrim | "top" | "bottom" | "left" | "right" | "none" | — | Scrim direction (heaviest edge); presence turns the scrim on, "none" opts out of the default cover scrim |
scrim-blur | "none" | "sm" | "md" | "lg" | — | Frost scrim blur amount |
scrim-strength | "sm" | "md" | "lg" | — | Gradient scrim strength |
scrim-tone | "dark" | "light" | — | Whether the scrim darkens (for light text) or lightens (for dark text) |
scrim-type | "gradient" | "frost" | — | Scrim treatment: gradient (default) or frost (backdrop blur) |
elevation
How far the rune sits off the page, from sunken to overlay. The theme decides what each step looks like.
| Attribute | Type | Required | Description |
|---|---|---|---|
elevation | "sunken" | "flush" | "flat" | "raised" | "floating" | "overlay" | "none" | "sm" | "md" | "lg" | — | Surface depth, from sunken to overlay. Deprecated: none, sm, md and lg (read as flat, raised, raised and floating) |
inset
Internal padding override.
| Attribute | Type | Required | Description |
|---|---|---|---|
inset | "flush" | "tight" | "default" | "loose" | "breathe" | — | Inner padding of this block |
motion
Scroll-reveal entrance. You choose its character; the theme decides how it moves.
| Attribute | Type | Required | Description |
|---|---|---|---|
reveal | "none" | "fade" | "slide" | "scale" | "blur" | — | Scroll-reveal entrance character (none|fade|slide|scale|blur); the theme owns the choreography |
stagger | boolean | — | Cascade this block's items in as it reveals (no-op on single-child runes) |
spacing
Block-level rhythm override.
| Attribute | Type | Required | Description |
|---|---|---|---|
spacing | "flush" | "tight" | "default" | "loose" | "breathe" | — | Vertical spacing above and below this block |
substrate
Generated pattern fills behind the content, drawn by the theme.
| Attribute | Type | Required | Description |
|---|---|---|---|
substrate | "dots" | "grid" | "lines" | "cross" | "checker" | "none" | — | Generated surface pattern |
substrate-fill | "inherit" | "inset" | — | Surface fill the pattern sits on (full colour stays with tint) |
substrate-opacity | "sm" | "md" | "lg" | — | Pattern ink strength |
substrate-size | "sm" | "md" | "lg" | — | Pattern cell size |
substrate-target | "self" | "media" | — | Which surface the pattern fills (overrides the rune/theme default) |
tint
Per-rune colour override: a named tint from the theme registry, with inline per-token overrides layered on top.
| Attribute | Type | Required | Description |
|---|---|---|---|
tint | string | — | Color tint preset applied to this block |
tint-mode | "auto" | "dark" | "light" | — | Whether the tint adapts to auto, dark, or light mode |
width
The track a block rune occupies.
| Attribute | Type | Required | Description |
|---|---|---|---|
width | "compact" | "narrow" | "content" | "wide" | "full" | — | Maximum width constraint for this block |
| Not available | Why |
|---|---|
| dropcap, reading | this rune declares no prose body |
| frame | this rune declares neither a `frameTarget` nor a media section |
| prominence | this rune has no page-section header or featured quotation |