THE GITHTML FIELD GUIDE

Keep warning labels out of CSS-generated content

Put meaningful warning labels in the HTML rather than generating them only with CSS before or after content. Generated text can behave differently across reading, copying, and assistive-technology contexts. Use pseudo-elements for decoration while keeping the substantive label and instruction available as ordinary document text.

Understand the access barrier

A paragraph may look labeled Warning because a class inserts that word through content. The source sentence then lacks the label, and copying or restyling can strip the distinction. This is especially risky when the label changes how urgently the instruction should be interpreted.

Use a deliberate document pattern

Write the label directly beside the message and style that text. If an icon is also present, make it redundant rather than the sole signal. Avoid generated punctuation that changes the meaning of a value.

  1. Move substantive labels and qualifiers into ordinary HTML text.
  2. Reserve generated content for decoration that does not change interpretation.
  3. Check copied text and nonvisual reading after the change.
html
<p class="warning"><strong>Warning:</strong> this snapshot excludes failed imports.</p>

Check the actual reading experience

Read and copy the message with author CSS removed. Its urgency, condition, and required response should remain explicit.

Keep copied evidence semantically complete

Imagine a quality report where CSS inserts Estimated before provisional figures and Final before approved figures. The visible page appears clear, but copied table cells may contain only the numbers. A reviewer pasting those values into an email can lose the qualification that determines whether they are suitable for a decision. Put Estimated and Final into the actual document content, then style them as labels.

The same principle applies to warning prefixes, units, required-field indicators, and signs that change a number’s meaning. A decorative quotation mark can be optional, while a minus sign or percent symbol is substantive. Classify generated content by what would happen if it disappeared. If removing it changes the claim, action, or interpretation, it should have a dependable textual representation in the authored document rather than relying solely on a pseudo-element.

Do not assume every browser or screen reader ignores generated text; support varies, and some combinations expose it. The stronger design is to avoid making essential meaning depend on that variability. After moving the label into HTML, check that it is not also inserted by the old CSS, which would create visual or spoken duplication. Copy the complete message into a plain-text editor and verify that its condition, urgency, and response remain clear. For a warning about excluded failed imports, the report should still state what was excluded and why that limits the conclusion. A colored border or icon can reinforce the warning, but neither should become the only surviving signal.

Sources and further reading

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

All accessible documentation guides →

Read as MarkdownAll guides

Keep warning labels out of CSS-generated content · gitHtml