Back to Mjml

README

packages/mjml-social/README.md

5.1.011.9 KB
Original Source

mj-social

Displays calls-to-action for various social networks with their associated logo. You can add multiple social networks using mj-social-element tags.

<figure> </figure> <div class="alert alert-caution" role="alert"> <p>Caution</p> <p>The <code>mj-social-element</code> <code>name</code> attribute is a shortcut for some common social elements. You should avoid rely too much on this as those icons are hosted by Mailjet for their Email Builder. Use <a href="#custom-social-element">custom element syntax instead.</a></p> </div>
xml
<mjml>
  <mj-body>
    <mj-section>
      <mj-column>
        <mj-social font-size="15px" icon-size="30px" mode="horizontal">
          <mj-social-element name="facebook" href="https://mjml.io/">
            Facebook
          </mj-social-element>
          <mj-social-element name="google" href="https://mjml.io/">
            Google
          </mj-social-element>
          <mj-social-element name="twitter" href="https://mjml.io/">
            Twitter
          </mj-social-element>
          <mj-social-element name="x" href="https://mjml.io/">
            X
          </mj-social-element>
        </mj-social>
      </mj-column>
    </mj-section>
  </mj-body>
</mjml>

Attributes

attributeacceptsdescriptiondefault value
alignleft right centeralign contentcenter
border-radiuspx %border radius3px
colorCSS color formatstext color#333333
css-classstringclass name, added to the root HTML element created
container-background-colorCSS color formatsinner element background color
font-familystringfont nameUbuntu, Helvetica, Arial, sans-serif
font-sizepxfont size13px
font-stylestringfont stylenormal
font-weightstringfont weightnormal
icon-heightpx %icon height, overrides icon-sizeicon-size
icon-paddingpx %padding around the icons
icon-sizepx %icon size (width and height)20px
inner-paddingpx %social network surrounding paddingnull
line-heightpx %space between lines22px
modehorizontal verticaldirection of social elementshorizontal
paddingpx %social padding, supports up to 4 parameters10px 25px
padding-bottompx %bottom padding
padding-leftpx %left padding
padding-rightpx %right padding
padding-toppx %top padding
text-paddingpx %padding around the text
text-decorationstringCSS values, e.g. underline overline nonenone
<p class="cta-container"><a class="cta" href="https://mjml.io/try-it-live/components/social">Try it live</a></p>

mj-social-element

This component enables you to display a given social network inside mj-social. Note that default icons are transparent, which allows background-color to actually be the icon color.

<div class="alert alert-note" role="alert"> <p>Note</p> <p><code>mj-social-element</code> is an "ending tag", which means that it can contain HTML code but it cannot contain other MJML components.</p> <p>More information about ending tags <a href="#ending-tags">in this section</a>.</p> </div>

Attributes

attributeacceptsdescriptiondefault value
alignleft center rightalign contentcenter
altstringimage alt attribute''
background-colorCSS color formatsicon colorEach social name has its own default
border-radiusstringborder radius3px
colorCSS color formatstext color#000
css-classstringclass name, added to the root HTML element created
font-familystringfont nameUbuntu, Helvetica, Arial, sans-serif
font-sizepxfont size13px
font-stylestringfont style
font-weightstringfont weight
hrefstringbutton redirection, in URL format
icon-heightpercent/pxicon height, overrides icon-sizeicon-size
icon-paddingpx %padding around the icon
icon-positionleft rightsets the side of the icon
icon-sizepx %icon size (width and height)
line-heightpx %space between lines1
namestringsocial network name, see supported list below
paddingpx %social element padding, supports up to 4 parameters4px
padding-bottompx %bottom padding
padding-leftpx %left padding
padding-rightpx %right padding
padding-toppx %top padding
relstringspecify the rel attribute for the link
sizesstringset icon width based on query
srcstringimage source, in URL formatEach social name has its own default
srcsetstringenables to set a different image source based on the viewport, using CSS syntax
targetstringlink target_blank
text-decorationstringCSS values, e.g. underline overline nonenone
text-paddingpx %padding around the text4px 4px 4px 0
titlestringimage title attribute
vertical-aligntop middle bottomvertically align elementsmiddle

Supported networks with a share url:

  • facebook
  • twitter
  • x
  • google
  • pinterest
  • linkedin
  • tumblr
  • xing

Without a share url:

  • github
  • instagram
  • web
  • snapchat
  • youtube
  • vimeo
  • medium
  • soundcloud
  • dribbble

When using a network with share url, the href attribute will be inserted in the share url (i.e. https://www.facebook.com/sharer/sharer.php?u=[[URL]]). To keep your href unchanged, add -noshare to the network name. Example :

<mj-social-element name="twitter-noshare" href="my-unchanged-url">Twitter</mj-social-element>

Custom Social Element

You can add any unsupported network like this:

xml
<mj-social-element href="url" background-color="#FF00FF" src="path-to-your-icon">
  Optional label
</mj-social-element>

You can also use mj-social this way with no href attribute to make a simple list of inlined images-texts.