Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

string(): named text for generated page content

Distinguish the draft named-string function from ordinary quoted CSS text and verify actual engine support.

Version: CSS Modules

Syntax

@page { @top-center { content: string(chapter, first); } }

The function string() retrieves a named string previously assigned through string-set. It belongs to generated-content and paged-media work, commonly for a running chapter heading in a page-margin box. It is not the ordinary <string> type, not JavaScript conversion, and not custom-property lookup. The name is an identifier; the retrieved value is inserted through the content property.

The optional page-value selector defaults to first: the first assignment on the page, or its entry value when none occurs. start uses the first assignment if its element starts the page, otherwise the entry value. last selects the exit value. first-except behaves like the first choice but emits an empty string on a page where the value is assigned. These choices concern the paginated document and cannot be demonstrated by simply reading a normal screen heading.

The linked CSS Generated Content draft and the related GCPM work describe this mechanism; their presence is not evidence of browser implementation. In the tested Chromium 157, a quoted content literal is supported, but the named assignment and both retrieval forms are not. The example retains a preceding literal fallback in a pseudo-element and in the parsed page-margin declaration. It does not render a named running header, create a PDF, or test the selector semantics in a paged-media engine.

Examples

console.log('quoted literal:', CSS.supports('content','"Chapter"'));
console.log('named assignment:', CSS.supports('string-set','chapter "Chapter"'));
console.log('named retrieval:', CSS.supports('content','string(chapter)'));
console.log('page selector argument:', CSS.supports('content','string(chapter,last)'));
const style = document.createElement('style');
style.textContent = '#named-string-probe::before { content:"Fallback"; content:string(chapter); }'
  + '@page { @top-center { content:"Fallback"; content:string(chapter,last); } }';
document.head.append(style);
const box = document.createElement('div');
box.id = 'named-string-probe';
document.body.append(box);
console.log('pseudo fallback:', getComputedStyle(box,'::before').content);
console.log('page margin declaration:', style.sheet.cssRules[1].cssRules[0].style.content);
box.remove();
style.remove();

Result

quoted literal: true
named assignment: false
named retrieval: false
page selector argument: false
pseudo fallback: "Fallback"
page margin declaration: "Fallback"

This is an executed support-and-fallback probe, with false results reported honestly. The ordinary CSS string datatype’s compatibility entry must not be used to claim support for the function. Keep essential headings in document content and test the intended print renderer separately.

Sources