Skip to content

Entire button as link #359

Description

@jaypeedevlin

Hi Guys,

Firstly - thanks for the great work in building mjml, it makes my life so much easier!

I'm not sure if this is possible or if it's already planned.

Currently, using <mj-button> with href results in the text on the button being linked, but not the button itself. For a large button with small text, this results in a large area that's not clickable.

Is it possible to change how the button links work so that the entire button is a link, rather than just the text?

Activity

  1. iRyusa commented on Aug 23, 2016

    @iRyusa
    Member

    Hi there,

    I believe this is not implemented because of how older outlook behave. It could be done with some Outlook conditionnals but it will add so much overhead.

  2. joshuabaker commented on Oct 24, 2016

    @joshuabaker

    Really great to hear this is considered. This is arguably quite an important feature. Buttons will almost exclusively be used as call to actions. Missed presses could be quite impactful to the success of emails.

  3. websirnik commented on Nov 24, 2016

    @websirnik

    +1. The current button markup does not work for large call to actions.

  4. sbefort commented on Feb 15, 2017

    @sbefort

    This would definitely be a nice feature. I will have to use clickable images as a workaround.

  5. added this to the 3.3.1 milestone on Feb 17, 2017
  6. removed this from the 3.3.3 milestone on May 26, 2017
  7. ngarnier commented on May 26, 2017

    @ngarnier
    Member

    Hey guys, we have an update on this. While we were hopeful we'd be able to release this in v3.3.3 and despite the great help of the community, we couldn't find a solution that would work everywhere (Outlook, webmails, mobile email clients...) and for all kinds of buttons (single-lined, multi-lined...).

    You can see the discussion here: #668

    We'll leave this issue open as we'd love as much as you all have a fully clickable button that works! Contributions welcome, as always.

  8. added 2 commits that reference this issue on Sep 5, 2017
    5ba09c3
    912a8b2
  9. kalfooza commented on Sep 14, 2017

    @kalfooza

    My workaround is to set the <a> inside as display:block. This then fills the entire <td> as long as the padding on sides isn't too big. Even though it doesn't fill the entire button it does create a bigger clickable area and it doesn't seem to cause problems.

  10. hugopeek commented on Oct 25, 2017

    @hugopeek

    Yeah this would definitely be nice! But just checked a couple of emails, and it seems that many other systems are struggling with this as well..

    FWIW: mails from Facebook and Zapier have fully clickable button inside. And something tells me they'll work in every client. So all we have to do is reverse engineer how they did it, right? 😝

  11. dalefish commented on Oct 25, 2017

    @dalefish
  12. 44 remaining items

  13. f0rmat1k commented on Jul 23, 2019

    @f0rmat1k

    @kmcb777 it has a bug. If you set width="100%" to button, it won't be clickable fully. <a> doesn't inherit width.

  14. kmcb777 commented on Jul 23, 2019

    @kmcb777
    Collaborator

    @f0rmat1k Hi, as said in the changelog : Fully clickable when width is in px, when width is in % only the inner-padding is clickable. It's still much better than before.
    Unfortunately we can't do better until box-sizing: border-box is supported on all email clients.

  15. thebeard commented on Sep 26, 2019

    @thebeard

    Hi everyone, just checking, as far as I can track from the conversation, it should be possible to have the whole button clickable when only using inner-padding.

    However, this is what's compiled on my side:

    <td align="center" bgcolor="#cc2128" role="presentation" style="border:none;border-radius:25px;cursor:auto;mso-padding-alt:15px 30px;background:#cc2128;" valign="middle">
      <p style="display:inline-block;background:#cc2128;color:#ffffff;font-family:'Roboto', sans-serif;font-size:15px;font-weight:normal;line-height:120%;margin:0;text-decoration:none;text-transform:none;padding:15px 30px;mso-padding-alt:0px;border-radius:25px;"> Login to your account </p>
    </td>
    

    It gets rendered in a p tag and the p tag's style has a rule:
    mso-padding-alt:0px

    I have this in my head:

    <mj-attributes>
        <mj-button border-radius="25px" background-color="#cc2128" inner-padding="15px 30px" font-size="15px"></mj-button>
    </mj-attributes>
    

    And this is the button implementation:
    <mj-button href="https://example.com">Login to your account</mj-button>

  16. ProdigyMaster commented on Apr 23, 2020

    @ProdigyMaster

    Hey, if I change button width in CSS, it becomes not fully clickable :
    Take look at mobile version here: https://mjml.io/try-it-live/HyM1F1JY8

    @iRyusa Is there any way around?

  17. miketromba commented on Jun 7, 2022

    @miketromba

    Still an issue in 2022
    Environment = the VS Code extension
    See gif: https://i.gyazo.com/4b9f106eab4e4fe0dd770ea5119dd04f.gif

    Any plans to fix this?

  18. iRyusa commented on Jun 7, 2022

    @iRyusa
    Member
  19. Leffla48 commented on Jun 9, 2022

    @Leffla48

    @miketromba This is a code snippet of a button that I have had a lot of success with inside MJML. You can reorganize and use as an mjml html component. This one falls back on Outlook/Windows to square corners which I find is a lot lighter when certain ESPs ignore VML for click tracking.

    <td align="right" valign="top" style="padding-top: 64px; padding-right: 24px; padding-bottom: 16px;" class="m-padding-right-16px">
    <a href="URL GOES HERE" style="background-color: #ffffff; border-radius: 20px; border: 2px solid #4D64F8; font-size: 14px; font-family: 'Nunito', Helvetica, Arial, sans-serif; font-weight: bold; text-decoration: none; padding: 8px 20px; color: #4D64F8; display: inline-block; mso-padding-alt: 0;">
    <!--[if mso]>
    <i style="letter-spacing: 15px; mso-font-width: -100%; mso-text-raise: 30pt;">&nbsp;</i>
    <![endif]-->
    <span style="mso-text-raise: 15pt;">Find jobs</span>
    <!--[if mso]>
    <i style="letter-spacing: 15px; mso-font-width: -100%;">&nbsp;</i>
    <![endif]-->
    </a>
    </td>
    
  20. miketromba commented on Jun 9, 2022

    @miketromba

    @Leffla48 Thanks! For some reason, unable to see it

  21. Leffla48 commented on Jun 9, 2022

    @Leffla48

    @Leffla48 Thanks! For some reason, unable to see it

    THanks for the heads up, updated it.

  22. fernamp commented on Oct 21, 2022

    @fernamp

    You just need to add border: 1px #color solid; to the ahref.
    The thing is that you have to keep track of the background color and the border colour so they mirror each other.
    This can be done via a variable or manually.
    MSO PC desktop is going to love it.

  23. fernamp commented on Oct 28, 2022

    @fernamp

    This is the code that MJML produces when using
    MJML
    <mj-button href="www.google.com" border="1px solid red">Unmodified button</mj-button>

    HTML

    <table border="0" cellpadding="0" cellspacing="0" role="presentation" style="border-collapse:separate;line-height:100%;">
        <tr>
            <td align="center" bgcolor="#414141" role="presentation" style="border:1px solid red; border-radius:3px; cursor:auto; background:#414141; mso-padding-alt:10px 25px;" valign="middle">
                <a href="www.google.com" style="display:inline-block; background:#414141; color:#ffffff; font-family:Ubuntu, Helvetica, Arial, sans-serif; font-size:13px; font-weight:normal; line-height:120%; margin:0; text-decoration:none; text-transform:none; padding:10px 25px; mso-padding-alt:0px; border-radius:3px;" target="_blank"> Unmodified button </a>
            </td>
        </tr>
    </table>
    

    What should happen is this:

    HTML

    <table border="0" cellpadding="0" cellspacing="0" role="presentation" style="border-collapse:separate; line-height:100%;">
        <tr>
            <td align="center" bgcolor="#414141" role="presentation" style="border:1px solid red; border-radius:3px; cursor:auto; background:#414141;" valign="middle">
                <a href="www.google.com" style="display:inline-block; background:#414141; color:#ffffff; font-family:Ubuntu, Helvetica, Arial, sans-serif; font-size:13px; font-weight:normal; line-height:120%; margin:0; text-decoration:none; text-transform:none; padding:10px 25px; border-radius:3px; border: 1px solid #414141;" target="_blank"> Modified button </a>
            </td>
        </tr>
    </table>
    

    In MSO, <a> is an inline but UNMODIFIABLE element (it can't become a block, nor an inline-block), unless you trick MSO into think that the <a> is "something" cause it has a border, triggering the use of the display declaration and therefore, the use of the padding (so removing the tool that provides the inner spacing of the button using mso-padding-alt: 0px; is kind of weird (taking into account that adding padding to the <a> in MSO has no real effect).

    This make the whole button clickable in MSO.
    Results MJML button:
    image

    Results MJML modified button:
    image

    Is this something MJML team can take? Or should I make a branch?

  24. added a commit that references this issue on Sep 18, 2023
  25. added a commit that references this issue on Nov 22, 2023
  26. hayden-t commented on Apr 8, 2025

    @hayden-t

    do we still need this ?

    Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions