HTML Syntax Compatibility

Expressions must be compatible with HTML syntax because they are parsed as HTML. Certain characters have special meaning in HTML and can’t be used directly in expressions.

Expressions must be HTML compliant because they are parsed as HTML. The < character in a text node expression would be interpreted as the opening of an HTML tag, causing a parsing error. However, < is allowed in attribute expressions when properly quoted. This applies to all characters that carry a special meaning in HTML. Caution against being too clever, and thorough testing, is recommended.

  • Text nodes: Use {bar > foo} instead of {foo < bar}
  • Text nodes: Use {bar >= foo} instead of {foo <= bar}
  • Attributes: < character works when expressions are quoted in attributes, but doesn’t work in text nodes
  • Both: Avoid expressions that contain < followed by text that could be interpreted as HTML tags

Complex template expressions in attributes must be quoted. This requirement is backward compatible with existing LWC templates — simple property bindings don’t require quotes.

  • Complex expressions: Must be quoted (any expression with operators, function calls, etc.)
  • Simple property bindings: Don't need quotes (just property names like {value})
  • Backward compatibility: Existing simple bindings continue to work without quotes

HTML entities are not decoded in expressions:

Certain expressions can cause HTML parsing issues when they contain characters that have special meaning in HTML:

Avoid expressions that:

  • Contain < followed by text that could be interpreted as an HTML tag
  • Contain </ followed by text that could be interpreted as a closing HTML tag
  • Mix HTML-like syntax within string literals