Question
Answer and Explanation
In MJML (Mailjet Markup Language), clickable text refers to text within an email that, when clicked, redirects the user to a specified URL. This is typically achieved using the <mj-text>
component in conjunction with the <mj-button>
or <mj-raw>
tags to create a hyperlink.
Here's a breakdown of how to implement clickable text in MJML:
1. Using <mj-button>
Component:
The <mj-button>
component is designed to create styled buttons that act as clickable links. It automatically handles many of the nuances of email client compatibility.
Example:
<mjml>
<mj-body>
<mj-section>
<mj-column>
<mj-button href="https://www.example.com">
Click Here!
</mj-button>
</mj-column>
</mj-section>
</mj-body>
</mjml>
In this example, "Click Here!" is the clickable text, and it redirects to "https://www.example.com" when clicked.
2. Using <mj-text>
and HTML <a>
Tag (with <mj-raw>
):
You can also use the <mj-text>
component to include raw HTML, which can contain an anchor tag (<a>
) to create a link.
Example:
<mjml>
<mj-body>
<mj-section>
<mj-column>
<mj-text>
<mj-raw>
<a href="https://www.example.com">Visit Example.com</a>
</mj-raw>
</mj-text>
</mj-column>
</mj-section>
</mj-body>
</mjml>
In this case, the text "Visit Example.com" becomes clickable, linking to the specified URL.
3. Considerations:
- Styling: Use MJML's styling attributes within the components to ensure the link is visually appealing and consistent with your email's design.
- Accessibility: Ensure the clickable text is easily identifiable and provides clear information about where it leads.
- URL: Double-check that the URL is correct and functional to avoid broken links.
Clickable text is essential for guiding users to resources, promotions, or additional information outside the email content. By using either the <mj-button>
component or combining <mj-text>
with raw HTML, you can effectively implement clickable text in your MJML emails.