Skip to main content
This guide covers design principles, common patterns, and testing strategies for UI Resource templates. For template syntax and configuration, see the UI Resources reference.

When to Use UI Resources

UI Resources turn plain text responses into visual components. Use them when: Skip UI Resources for simple text answers, speed-critical conversations, or plain-text contexts (terminal interfaces).

Design Principles

1. Mobile-First

Templates display in chat widgets that are often mobile-sized. Start with small screens:

2. Clear Hierarchy

Guide users’ eyes to the most important information first:

3. Consistent Branding

Use CSS custom properties for your design system:

4. Graceful Degradation

Always handle missing data:

Common Patterns

Product Card

Status Card

Action Buttons

Data Table


Accessibility

Semantic HTML

Use proper HTML elements — headings, paragraphs, lists, and <article> instead of generic divs:

Images

Always provide meaningful alt text:

Color Contrast

Ensure readable text and provide non-color indicators:

Focus States

Make interactive elements keyboard-accessible:

Screen Readers

Add ARIA labels where visual meaning is not conveyed by text:

Testing Templates

Create Test Scenarios

Test with different data in the template preview: All data provided:
Minimal data (only required fields):
Edge cases:

Checklist

  • Renders with all data provided
  • Renders with only required fields
  • Long text does not break the layout
  • Missing images show a placeholder
  • Looks correct on mobile widths
  • Buttons and links are clickable
  • Colors have sufficient contrast
  • No external dependencies that might break

Performance Tips

  • Keep templates light — avoid loading external frameworks via CDN
  • Specify image dimensions to prevent layout shift: <img width="300" height="200" ...>
  • Use loading="lazy" for images below the fold
  • Include only necessary CSS — skip unused utility classes
  • Prefer CSS over JavaScript for interactions (hover effects, accordions via <details>)