Skip to content

AI Styling

When the Pattern Library can’t handle your styling request (confidence <70%), WyvernPress seamlessly falls back to AI-powered CSS generation. This guide covers everything you need to know about AI styling.

  1. You describe styling → “Glassmorphism card with animated gradient border”
  2. Pattern Library check → No pattern matches with sufficient confidence
  3. AI generation triggered → Request sent to configured AI provider
  4. CSS generated → AI analyzes your description and block context
  5. Result cached → Future identical requests return instantly

AI generation is triggered when:

  • Pattern Library confidence score is below 70%
  • Request includes complex or creative styling terms
  • Multiple styling concepts combined (e.g., “gradient + animation + hover”)
  • Request uses specific brand colors or custom values

WyvernPress uses OpenRouter to access AI models. OpenRouter provides a single API for multiple AI providers.

Steps to configure:

  1. Create account at openrouter.ai
  2. Generate an API key
  3. In WordPress: WyvernPress → Settings → AI Configuration
  4. Enter your OpenRouter API key
  5. Select your preferred model
  6. Save changes
ModelBest ForSpeedCost
Claude 3 HaikuFast, simple requestsFast$
Claude 3 SonnetBalanced quality/speedMedium$$
GPT-4 TurboComplex creative requestsMedium$$$
Llama 3 70BOpen-source alternativeMedium$

Without an API key, WyvernPress operates in Pattern Library-only mode:

  • Pattern Library works normally (60% of requests)
  • Complex requests show a suggestion to configure AI or rephrase
  • Zero cost, but limited to pre-built patterns

The AI understands CSS concepts. Be explicit:

Good prompts:

Background gradient from #007cba to #6366f1, white text,
24px border-radius, 24px padding, subtle box-shadow
Glassmorphism effect: semi-transparent white background,
backdrop-filter blur, thin white border, soft shadow

Avoid vague prompts:

Make it look modern ← Too vague
Make it pretty ← No styling information
Style it nicely ← AI can't interpret this

For animations and effects, describe the behavior:

On hover: lift up 4px, increase shadow depth,
smooth 0.2s transition
Animated gradient border that shifts colors continuously,
using blue, purple, and pink
Pulse animation on the button that subtly scales it
up and down to draw attention

AI understands common design terms:

TermWhat AI Generates
GlassmorphismFrosted glass effect with backdrop-blur
NeumorphismSoft UI with inset/outset shadows
BrutalistBold, raw, high-contrast design
MinimalClean, lots of whitespace
Gradient meshComplex multi-color gradients
Neon glowBright colors with glow effects

Example:

Neumorphism button with soft shadows,
subtle pressed state on click

Include responsive requirements:

Card that stacks vertically on mobile,
horizontal on desktop, with appropriate
padding adjustments

The Pattern Library handles 60% of requests at zero cost. To maximize pattern usage:

  1. Use common terms: “blue”, “shadow”, “rounded” match patterns well
  2. Simple requests first: Build complex styles incrementally
  3. Check the pattern reference: Know what patterns exist

AI results are cached:

  • Cache duration: 24 hours (configurable)
  • Cache key: Prompt + block context hash
  • Cache storage: Redis (if available) or WordPress transients

What this means:

  • Identical requests are instant and free
  • Slight prompt variations create new cache entries
  • Cache clears when plugin updates

Style similar blocks together to maximize cache hits:

  1. Style one button with AI
  2. Copy that button to other locations
  3. All copies use the same cached CSS

Choose cost-effective models:

ScenarioRecommended ModelWhy
Simple stylingClaude 3 HaikuCheapest, fast
Complex layoutsClaude 3 SonnetBetter understanding
Creative/artisticGPT-4 TurboMost creative
High volumeLlama 3 70BVery affordable

Request all states at once:

Button with three states:
- Default: Blue background, white text, subtle shadow
- Hover: Darker blue, lifted 2px, larger shadow
- Active: Even darker, pressed down 1px, minimal shadow
All with 0.2s smooth transitions

AI can generate ::before and ::after styles:

Card with decorative corner accents using
::before and ::after pseudo-elements,
small triangles in the top-left and bottom-right

Describe keyframe animations:

Loading spinner animation: circular element
that rotates 360 degrees continuously with
a gradient stroke that also animates

Request variable-based CSS for easy theming:

Button using CSS variables for colors:
--button-bg, --button-text, --button-hover
so I can easily change themes later

AI responses include:

{
"css": {
"background": "linear-gradient(135deg, #007cba, #6366f1)",
"color": "#ffffff",
"padding": "24px",
"border-radius": "12px"
},
"source": "ai",
"model": "claude-3-haiku",
"confidence": 95,
"tokens_used": 150,
"cached": false
}
FieldDescription
cssGenerated CSS properties
source”ai” or “pattern”
modelWhich AI model was used
confidenceHow confident AI is in the result
tokens_usedAPI tokens consumed
cachedWhether result came from cache

AI-generated CSS is validated for:

  1. Color contrast: Meets WCAG 2.1 AA (4.5:1 for text)
  2. Focus visibility: Interactive elements have visible focus states
  3. Motion preferences: Animations respect prefers-reduced-motion
  4. Touch targets: Buttons/links meet minimum 44x44px

If AI generates potentially inaccessible CSS:

⚠️ Accessibility Warning
The generated colors have a contrast ratio of 3.2:1.
WCAG AA requires 4.5:1 for normal text.
Suggestions:
- Darken the text color to #1a1a1a
- Or lighten the background to #f5f5f5

Include accessibility in your prompts:

Blue button with high contrast white text,
visible focus ring, and respects reduced-motion
preferences for hover animation

Causes:

  • Invalid or expired API key
  • API rate limit exceeded
  • Network connectivity issues
  • Model temporarily unavailable

Solutions:

  1. Verify API key in Settings
  2. Check OpenRouter dashboard for usage limits
  3. Try a different model
  4. Wait a few minutes and retry

Causes:

  • Complex prompts
  • High demand on AI service
  • Network latency

Solutions:

  1. Simplify your prompt
  2. Try Claude 3 Haiku (fastest)
  3. Check if result is in cache
  4. Build complex styles incrementally

Causes:

  • Vague or ambiguous prompt
  • Context misunderstanding
  • Model limitations

Solutions:

  1. Be more specific in your description
  2. Include exact values (colors, sizes)
  3. Review and edit the generated CSS
  4. Try a different model

Causes:

  • Using expensive models
  • Not utilizing Pattern Library
  • Cache misses

Solutions:

  1. Switch to Claude 3 Haiku
  2. Use Pattern Library terms when possible
  3. Reuse styled blocks via copy/paste
  4. Set usage alerts in OpenRouter

WyvernPress → Settings → Usage:

  • Total AI requests this month
  • Pattern Library hit rate
  • Cache hit rate
  • Estimated costs

Monitor detailed usage at openrouter.ai/activity:

  • Per-model usage
  • Token consumption
  • Cost breakdown
  • Rate limit status
  1. Pattern Library first: Use common CSS terms for instant, free results
  2. Be specific: Include colors, sizes, and exact values
  3. Use design terms: AI understands “glassmorphism”, “neumorphism”, etc.
  4. Request all states: Include hover, focus, and active states together
  5. Build incrementally: Complex styles in steps, not all at once
  6. Monitor usage: Track costs in OpenRouter dashboard
  7. Use caching: Reuse styled blocks to maximize cache hits
  8. Check accessibility: Verify contrast and focus states