The Custom HTML block allows you to add custom HTML code directly to your email templates. Use this block for advanced formatting, custom structures, or HTML that isn’t available through other blocks.
Adding a Custom HTML Block
- While editing your email template, click theย “+”ย button to add a new block
- Search forย “Custom HTML”ย or find it in theย “Widgets”ย category
- Click to insert the block
- Enter your HTML code in the editor
Writing HTML for Email
Email-Safe HTML
Email clients have limited HTML and CSS support. Follow these guidelines:
Supported HTML Elements
- Tables: Use tables for layout (most reliable)
- Inline Styles: Use inline CSS styles
- Basic Elements:ย
div,ยspan,ยp,ยa,ยimg,ยstrong,ยem - Limited CSS: Basic properties likeย
color,ยbackground-color,ยpadding,ยmargin
Avoid
- External Stylesheets: Not supported
- JavaScript: Not supported
- Complex CSS: Advanced CSS features may not work
- CSS Classes: Limited support, use inline styles instead
Best Practices
- Use Tables for Layout: Tables are the most reliable layout method in email
- Inline Styles: Always use inline CSS styles
- Test Thoroughly: Test HTML in multiple email clients
- Keep It Simple: Use simple, straightforward HTML
- Absolute URLs: Use absolute URLs for images and links
- Email-Safe Colors: Use hex color codes
- Width Constraints: Set explicit widths (often 600px max for email)
Common Use Cases
Custom Tables
Create custom table layouts:
<table width="100%" cellpadding="10" cellspacing="0" border="0">
<tr>
<td style="background-color: #f0f0f0; padding: 10px;">Cell 1</td>
<td style="background-color: #ffffff; padding: 10px;">Cell 2</td>
</tr>
</table>
Code language: HTML, XML (xml)Custom Styled Content
Add custom-styled content:
<div style="background-color: #ff0000; color: #ffffff; padding: 20px; text-align: center;">
Custom styled content
</div>
Code language: HTML, XML (xml)Merge Tags in HTML
You can use merge tags within HTML:
<p>Hello, {user:first_name}!</p>
<a href="{order_url}">View Order</a>
Code language: HTML, XML (xml)Styling Guidelines
Inline Styles
Always use inline styles:
<!-- Good -->
<div style="color: #333333; font-size: 16px; padding: 10px;">Content</div>
<!-- Avoid -->
<div class="content">Content</div>
<style>.content { color: #333333; }</style>
Code language: HTML, XML (xml)Colors
Use hex color codes:
<div style="color: #333333; background-color: #f5f5f5;">Content</div>
Code language: HTML, XML (xml)Spacing
Use padding and margin in inline styles:
<div style="padding: 20px; margin: 10px 0;">Content</div>
Code language: HTML, XML (xml)Troubleshooting
HTML Not Rendering
- Verify HTML syntax is correct
- Check that HTML is email-safe
- Test in multiple email clients
- Some email clients strip certain HTML
Styles Not Applying
- Use inline styles only
- Avoid external stylesheets
- Test in multiple email clients
- Some CSS properties may not be supported
Images Not Displaying
- Use absolute URLs for images
- Ensure images are hosted on a reliable server
- Include alt text for images
- Test image URLs in a browser
Links Not Working
- Use absolute URLs for links
- Verify link URLs are correct
- Test links in a browser
- Some email clients may modify links
Layout Issues
- Use tables for layout
- Set explicit widths
- Test in multiple email clients
- Keep layouts simple
Security Considerations
- Sanitization: HTML is sanitized for security
- Scripts: JavaScript is removed for security
- External Resources: Be cautious with external resources
- User Input: Never trust user-provided HTML without sanitization
Best Practices
- Test Extensively: Test custom HTML in multiple email clients
- Keep It Simple: Use simple HTML for better compatibility
- Inline Styles: Always use inline CSS styles
- Tables for Layout: Use tables for reliable layouts
- Absolute URLs: Use absolute URLs for all external resources
- Validate HTML: Ensure HTML is valid and well-formed
- Documentation: Document custom HTML for future reference
Additional resources
Use the links below for more information and guidance on adding blocks. Keep in mind that these articles are general information related to the WordPress Editor and building with blocks. Email Customizer does not utilize all blocks or functionality due to the limited capabilities of emails.
WordPress Editor