2026-07-15

How do I add space between span in html for emails?

Stefan Bogdanescu

Stefan Bogdanescu

Founder & Senior Architect

How do I add space between span in html for emails?

Mastering Spacing in Email HTML: A Developer's Guide

Developing email templates presents a unique set of challenges compared to standard web development. While CSS is the backbone of modern web design, email clients—especially legacy ones like Outlook—are notoriously finicky about how they interpret modern CSS properties, particularly margins and padding applied to inline elements. This often leaves developers wrestling with simple spacing tasks, such as adding space between <span> tags, which seems impossible when standard methods fail.

As a senior developer, I understand this frustration. The core issue is that email rendering relies heavily on older HTML standards and table layouts, making pure CSS solutions unreliable for internal element spacing. However, there are specific, reliable workarounds we can employ to achieve the desired visual separation.

Why Standard CSS Fails in Email

The reason you cannot simply use margin-left or padding-right between your <span> elements is due to how email clients parse HTML. Most major email providers strip out or ignore these modern CSS rules, forcing us back to older layout mechanisms. This limitation is why we often need to adopt a hybrid approach that mixes HTML structure with very specific, limited CSS hacks.

Your example illustrates this perfectly:

<td width="659" height="28" bgcolor="#999999" align="center">
    <span style="color: #ffffff;font-family: Arial, sans-serif;font-size:20px;">CODE:</span>
    <span style="color: #ffffff;font-family: Arial, sans-serif;font-size:20px;font-weight:bold;">BEHAPPY</span>
    <span style="color: #ffffff;font-family: Arial, sans-serif;font-size:20px;">• Ends 6/01</span>
</td>

In this setup, trying to add a margin between the first and second <span> will likely result in no visible space. We need techniques that force separation using elements the email client does respect.

Developer Solutions for Email Spacing

Since margins are out, we must rely on either inserting structural elements or using background tricks. Here are the most effective strategies:

1. The Reliable Hack: Using Non-Breaking Spaces and Line Breaks (<br>)

The simplest, most direct method is to insert explicit line breaks. While this doesn't add true CSS margin, it forces a vertical separation that renders correctly across almost all email clients.

<td width="659" height="28" bgcolor="#999999" align="center">
    <span style="color: #ffffff;font-family: Arial, sans-serif;font-size:20px;">CODE:</span>
    <br> <!-- Added line break for separation -->
    <span style="color: #ffffff;font-family: Arial, sans-serif;font-size:20px;font-weight:bold;">BEHAPPY</span>
    <br> <!-- Added line break for separation -->
    <span style="color: #ffffff;font-family: Arial, sans-serif;font-size:20px;">• Ends 6/01</span>
</td>

This method is robust because <br> is fundamental HTML and is respected by email clients. If you are building complex structures in a framework like Laravel, understanding these rendering limitations is crucial for writing truly portable components.

2. The Advanced Technique: Using Invisible Spacers (Background Trick)

For more controlled, consistent spacing—especially between adjacent text elements where simple line breaks might create unwanted vertical gaps—we can use the technique of creating an invisible spacer element. This usually involves wrapping the text in a container and using a background property to define the space.

A cleaner approach often involves using a small <div> or <span> with a defined height and zero width, setting its background color to transparent. While this adds complexity, it allows for pixel-perfect control over spacing:

<td width="659" height="28" bgcolor="#999999" align="center">
    <span style="color: #ffffff;font-family: Arial, sans-serif;font-size:20px;">CODE:</span>
    <span style="display: inline-block; width: 15px; height: 1px; background-color: #999999; margin-left: 5px;"></span> <!-- Invisible spacer -->
    <span style="color: #ffffff;font-family: Arial, sans-serif;font-size:20px;font-weight:bold;">BEHAPPY</span>
    <span style="display: inline-block; width: 15px; height: 1px; background-color: #999999; margin-left: 5px;"></span> <!-- Invisible spacer -->
    <span style="color: #ffffff;font-family: Arial, sans-serif;font-size:20px;">• Ends 6/01</span>
</td>

Note that even when using the margin-left property on the spacer, we often need to resort back to inline-block display combined with a subtle background color to force the space to render reliably in email clients. This approach requires careful testing against various platforms.

Conclusion: Prioritizing Compatibility

When working within the constraints of email development, developers must shift their mindset from "how can I style this?" to "what structure will reliably render everywhere?" The most practical solution for spacing between inline elements is often the explicit use of <br> tags or employing carefully constructed table structures.

By respecting these inherent limitations and focusing on robust HTML structuring rather than relying solely on modern CSS features, you ensure that your email templates deliver a consistent experience across every inbox. For complex templating logic, leveraging strong backend systems like Laravel can help manage the complexity of generating these highly specific, cross-client compatible HTML strings efficiently.

Tags:

Enhance your marketing setup with your own email marketing platform.

Join the growing number of SaaS platforms using Laravel Mail to offer email marketing solutions to their customers.