Suped

What are the best practices for using comments in publicly viewable email HTML code?

Summary

Best practices for using comments in publicly viewable email HTML code center on their utility as internal developer notes and their distinct role in conditional statements for specific email clients. Most email clients and ESPs strip general HTML comments, rendering them invisible to recipients and typically having no impact on deliverability or rendering. However, conditional comments remain vital for targeting Outlook desktop clients, which utilize an older rendering engine. Experts recommend minimal use of comments in production code, highlighting potential security risks if sensitive information is included and not stripped. There is also a call for email development to adopt more rigorous software engineering practices, such as minification and source control, to manage comments and optimize code efficiently, ensuring comments serve their purpose without unnecessarily contributing to code bloat or visibility issues.

Key findings

  • Internal Utility: HTML comments in email code are primarily valuable for internal documentation, enhancing code readability, organizing complex templates, and assisting with debugging for developers.
  • Client Stripping: Most webmail clients, such as Gmail and Outlook.com, and many Email Service Providers (ESPs) automatically strip general HTML comments from emails before delivery, making them largely invisible to recipients.
  • Conditional Comments' Role: A significant exception to comment stripping is conditional comments, which are crucial for targeting specific versions of Outlook desktop clients to ensure proper rendering and styling.
  • Minimal Deliverability Impact: Since the majority of email clients and ESPs remove HTML comments, they generally do not affect email deliverability or performance.
  • Potential for Exposure: While less common, some desktop email clients like Apple Mail and Thunderbird may preserve comments, meaning any sensitive information included could theoretically be viewed by recipients.

Key considerations

  • Purposeful Use: Distinguish between comments for internal developer notes, debugging, and those with specific rendering purposes like conditional comments for Outlook.
  • Security Implications: Avoid including any sensitive or proprietary information in comments, as they could potentially be exposed in environments where they are not stripped.
  • Code Optimization: While many platforms strip comments, aim for lean, clean HTML. Excessive comments can contribute to code bloat during development and, if not stripped, could minimally impact file size for clients that preserve them.
  • Outlook-Specific Needs: Always account for Outlook desktop clients, which often utilize Internet Explorer's rendering engine. Conditional comments are essential for targeting these specific email environments effectively.
  • Modern Development Workflow: Consider adopting software development practices such as minification, which strips comments and whitespace, and source control. These methods ensure that production code is optimized and comments are managed internally, not publicly exposed.

What email marketers say

12 marketer opinions

For publicly viewable email HTML, the consensus among experts is to minimize or entirely strip comments in production environments. While HTML comments offer significant value for internal developer notes, code organization, and debugging, most email clients and Email Service Providers (ESPs) remove them before delivery, making them generally invisible to recipients and without impact on deliverability. A notable exception involves conditional comments, which remain essential for ensuring proper rendering on specific Outlook desktop clients. Security concerns arise if sensitive data is embedded within comments that are not reliably stripped. The evolving landscape of email development calls for more structured software engineering practices, such as code minification and version control, to manage comments internally and optimize the final code for deployment.

Key opinions

  • Internal Notes & Organization: HTML comments are primarily valuable for developers' internal documentation, enhancing code readability, organizing complex templates, and assisting with debugging efforts.
  • Widespread Stripping by Clients/ESPs: The vast majority of webmail clients, such as Gmail and Outlook.com, and many Email Service Providers (ESPs) automatically strip general HTML comments from emails before delivery.
  • Outlook Conditional Comments: A significant exception to comment stripping is conditional comments, which are crucial for targeting specific versions of Outlook desktop clients to ensure proper rendering and styling.
  • Minimal Deliverability Impact: Since most email clients and ESPs remove HTML comments, they generally do not affect email deliverability or performance.
  • Potential Security Vulnerability: While less common, some desktop email clients may preserve comments, meaning any sensitive information included could theoretically be viewed by recipients if not properly stripped.
  • Call for Software Dev Practices: The email development ecosystem could benefit significantly from adopting more rigorous software engineering principles, such as minification and source control, for managing code and comments.

Key considerations

  • Prioritize Lean Code: Strive for clean, optimized HTML. Even if comments are stripped, a minimalist approach reduces bloat and improves maintainability for email development.
  • Strategic Use for Outlook: Leverage conditional comments specifically for Outlook desktop clients, acknowledging their unique rendering requirements and their necessity for proper display.
  • Avoid Sensitive Data: Never embed confidential or proprietary information in HTML comments, as there's a risk they might not be stripped by all email clients, potentially leading to exposure.
  • Internal Documentation Only: View general HTML comments purely as internal notes for developers, not for critical information that needs to reach the recipient or directly influence email rendering.
  • Embrace Modern Dev Tools: Incorporate practices like code minification, which strips comments and whitespace, and version control to manage comments and optimize the final email code before deployment.

Marketer view

Marketer from Email Geeks explains that publicly viewed code, including email HTML, should contain minimal to no comments in production environments. He emphasizes that comments can pose security risks, such as exposing sensitive information, and that proper coding standards with change control should handle documentation internally, with comments ideally stripped out before deployment to production. He also notes the evolution of email into a specialized ecosystem with more defined roles.

5 Feb 2024 - Email Geeks

Marketer view

Marketer from Email Geeks agrees that comments should generally be absent from public HTML code, especially without a compiler, but suggests an exception for explaining the 'why' behind specific code decisions. He highlights that email development could benefit from adopting software development processes like minification, stripping comments and whitespace, and source control. He attributes the lack of these practices to email developers often not having traditional computer science backgrounds, instead learning on the job. He advocates for more structured tools and processes to manage email code, recognizing the constant changes in email client support and the absence of a W3C-like standard for email, which makes it challenging.

26 Mar 2024 - Email Geeks

What the experts say

0 expert opinions

For optimal email deliverability and recipient experience, the best practice for publicly viewable HTML code is to minimize or entirely remove general comments in the final production version. While valuable for internal developer documentation, code clarity, and debugging, most email clients and Email Service Providers (ESPs) automatically strip these comments, rendering them invisible and without impact on deliverability. A crucial exception applies to conditional comments, which remain essential for precise rendering across various Outlook desktop clients. To prevent the accidental exposure of sensitive data and to ensure lean code, leveraging modern software development practices like minification and version control to manage comments internally is highly recommended.

Key opinions

  • Internal Documentation: HTML comments are primarily beneficial for developers, aiding in internal documentation, enhancing code readability, and streamlining the debugging process for complex email templates.
  • Standard Stripping: The majority of email clients, including popular webmail services like Gmail and Outlook.com, along with many Email Service Providers, automatically strip general HTML comments prior to email delivery.
  • Outlook's Requirement: Conditional comments are a vital exception, specifically used to target and apply styles or content corrections for different versions of Outlook desktop clients, which rely on older rendering engines.
  • No Deliverability Impact: Given that most platforms remove them, general HTML comments typically have no effect on email deliverability, loading speed, or overall performance.
  • Data Security Risk: There is a potential, albeit less common, risk that some desktop email clients may preserve comments, meaning any sensitive or proprietary information included could become visible to recipients.
  • Minification for Production: Implementing practices such as code minification, which removes comments and whitespace, is a best practice for optimizing email HTML for production, ensuring a clean and efficient final product.

Key considerations

  • Purposeful Commenting: Differentiate between comments intended for internal development notes and conditional comments, which serve a specific functional purpose for email client rendering.
  • Safeguard Sensitive Info: Strictly avoid embedding any confidential, proprietary, or personal data within HTML comments, as their visibility cannot be guaranteed across all email environments.
  • Implement Automated Stripping: Utilize build tools or pre-deployment scripts to automatically strip all non-conditional HTML comments from your email code before sending, optimizing file size and minimizing potential exposure.
  • Prioritize Outlook Compatibility: Continue to strategically employ conditional comments to address the unique rendering requirements of Outlook desktop clients, ensuring consistent display.
  • Embrace Modern Dev Workflows: Integrate modern software engineering practices, such as source control and automated minification, to manage comments effectively internally and deploy clean, optimized public-facing email code.

What the documentation says

5 technical articles

HTML comments in email code primarily serve as internal annotations for developers, aiding in documentation, clarity, and debugging. While most email clients and Email Service Providers (ESPs) remove these general comments before delivery, making them effectively invisible to recipients and without impact on deliverability, a critical exception exists. Conditional comments are indispensable for ensuring proper rendering across specific Outlook desktop clients, which rely on older rendering engines like Internet Explorer. Experts emphasize that general comments should be considered safe for internal notes, though a minor risk of visibility exists in some less common desktop environments, especially if sensitive information is included. Therefore, the best practice for production email HTML involves either minimizing general comments or using build processes to strip them, reserving functional comments strictly for conditional logic aimed at specific client compatibility.

Key findings

  • Developer Utility: HTML comments function as valuable internal notes, aiding developers with documentation, code organization, and debugging during email creation.
  • Client Stripping: The majority of webmail clients, like Gmail and Outlook.com, along with many Email Service Providers, automatically remove general HTML comments from the email's final output.
  • Outlook Conditional Comments: Conditional comments are a vital tool for email developers, specifically used to target and ensure correct display in various Outlook desktop clients due to their unique rendering engine.
  • No Deliverability Impact: Because most platforms strip them, general HTML comments typically have no effect on email deliverability, loading performance, or the recipient's overall experience.
  • Potential for Visibility: While uncommon, some desktop email clients, such as Apple Mail and Thunderbird, may preserve general HTML comments, meaning they could theoretically be visible to recipients.
  • Internal Annotations: HTML comments are intended as non-rendering annotations, useful for internal clarity and future reference, emphasizing their role as backend notes rather than frontend content.

Key considerations

  • Purpose-Driven Use: Clearly distinguish between general comments for internal developer notes and functional conditional comments that are essential for specific email client rendering.
  • Avoid Sensitive Data: Never include confidential, proprietary, or private information within HTML comments, as there is a slight possibility they might not be stripped by all recipient email clients.
  • Lean Code Practice: Strive for clean, minimal HTML code. While most platforms strip comments, excessive commenting can add unnecessary bloat during development if not properly managed or stripped in production.
  • Prioritize Outlook Compatibility: Always account for the rendering quirks of Outlook desktop clients by strategically using conditional comments to ensure consistent design and layout.
  • Leverage Build Processes: Incorporate automated tools or build processes that can strip general HTML comments and minify code before deployment, optimizing email size and ensuring comments remain internal.

Technical article

Documentation from learn.microsoft.com explains that conditional comments are a specific type of HTML comment used to target different versions of Internet Explorer, which is relevant for email developers because Outlook desktop clients often use IE's rendering engine, allowing for targeted styling or code for these specific email environments.

23 Feb 2024 - learn.microsoft.com

Technical article

Documentation from Email on Acid explains that HTML comments serve as valuable internal notes for developers and are useful for debugging during the email development process, though most email clients remove them before rendering; however, conditional comments remain crucial for ensuring proper display in Outlook.

30 Aug 2022 - Email on Acid

Start improving your email deliverability today

Sign up