One of the newest additions to our template language is the @style declaration. Before now, automatically-applied styles in the campaign text editor’s style menu were limited to three things: title, subtitle, and default text:

That method didn’t offer much choice at all, and if you wanted to apply any styling selectively you’d have to delve into the editor’s source view and deal with span tags, style attributes, and inline CSS.
That’s certainly a serviceable way to do things, but a it’s little messy and it’s a little slow. I really, really don’t like slow. That was before the @style declaration, which takes a CSS rule set you’ve created and pulls it into the campaign text editor’s drop-down menu:

This allows you to apply styles to your text in a quick and selective way. How does it work? It’s a simple, one-line deal. When you set up your template language CSS declarations…
/**
* @tab Body
* @section superfunky text
*/
.superfunky{
/*@editable*/ color:#FF00FF;
/*@editable*/ font-family:"Comic Sans";
/*@editable*/ font-size:34px;
/*@editable*/ text-decoration:underline overline;
}
…you include the @style declaration, along with a name for that style…
/**
* @tab Body
* @section superfunky text
* @style superfunky
*/
.superfunky{
/*@editable*/ color:#FF00FF;
/*@editable*/ font-family:"Comic Sans";
/*@editable*/ font-size:34px;
/*@editable*/ text-decoration:underline overline;
}
…and voila! The style appears in the drop-down menu in the campaign’s text editor:

If you look at the case above, you’ll see that this “superfunky” text is set up to get pulled into the campaign’s editor tabs as well, meaning that you can change the parameters of the style and have it show up the way you want in the template content:

This is the optimal use, because you don’t have to go back into the code to change anything, but it’s not the required use. You can also set up the declaration so that the style isn’t editable within the app, but still gets pulled into the styling drop-down menu:
/**
* @style superfunky
*/
.superfunky{
color:#FF00FF;
font-family:"Comic Sans";
font-size:34px;
}
Because the @tab and @section declarations are gone, the style isn’t accessible for change outside of the native HTML template document. This is useful if you’re an agency or freelancer and you’re setting up a template where the styles adhere to brand guidelines and don’t change, but you still want to give the client the option of applying some brand-consistent styling to their text (certain background colors on the text, for instance). It’s also handy for text styles you may use a lot in templates where you don’t make use of the app’s template editor tabs at all.
There are two important rules you have to follow that determine whether @style works for you or not: The style to be applied must be a class and not an ID (multiple IDs in HTML is a no-no anyway), and the CSS ruleset must contain at least one font-xxx declaration (like font-family or font-weight). If either of these two rules are overlooked, the drop-down menu won’t be populated with that style.
There’s one special circumstance in using @style, too: you can set it up to automatically wrap your selected text in a heading tag (h1 through h6). In the past, we created false headings by applying the title or subtitle style onto a <span> tag that wrapped your selected text. Now, when @style is applied to the CSS ruleset of an tag, the app knows to take that rule and apply it as HTML markup rather than wrap the text in a <span> and apply a class. There’s nothing different that you have to do. Just set the declaration in the same way:
/**
* @tab Page
* @section heading 1
* @tip Set the styling for all first-level headings in your emails.
* @style heading 1
*/
h1{
/*@editable*/ color:#202020;
...
In this case, you don’t have to give the h1 ruleset a class, and the app pulls them in automatically:

Other than a couple of rules to live by the new @style declaration is pretty robust, and it allows you to do quite a bit with text CSS styling. Just remember that the @style declarations that you set up in the “My Templates” area can only be applied when your actually creating your campaigns, since they are content-specific rules. Experiment away!
Your original link that was posted to this story is incorrect (http://blog.mailchimp.com/using-style-to-rock-some-socks/)
Needs the @ symbol in there (http://blog.mailchimp.com/using-@style-to-rock-some-socks/)
Peace.
D
Fabio,
I really like this addition. Many of my clients have asked for this capbility and I’ve had to teach them some html to use it. No longer!
In your writeup, I still don’t understand why you would tag an attribute as editable but not expose it in the style editor?
/**
* @style superfunky
*/
.superfunky{
/*@editable*/ color:#FF00FF;
/*@editable*/ font-family:”Comic Sans”;
/*@editable*/ font-size:34px;
}
When you say”the style isn’t accessible for change outside of the native HTML template document” – does this mean the only way these attributes can be changed is by editing the template?
Give me another example of how I would use this?
Jack,
Those /*@editable*/ statements are my mistake. They shouldn’t be in there. Doesn’t hurt anything if they are, but I can see how it can cause confusion. I’ll correct the example in the post.
For that example, yes, the only way to edit the CSS would be in the template code itself. You wouldn’t be able to change the style in the app’s style editor.
Another example, if you wanted to set up a specific text style to apply to quotes:
/**
* @style quotes
*/
.quotes{
color: #808080;
font-family: Georgia;
font-size: 12px;
font-style: italic;
}
In this instance, the drop-down menu in the app’s WYSIWYG text editor window would display “quotes” as an applicable style. You’d be able to highlight a section of text and apply the quotes style to it.
Hope this helps, and sorry for the confusion.
Thanks. It makes sense now.
Your “quote” example was a good one – and one I hadn’t thought of. So now I’m curious. What other styles are you anticipating using this for?
I was planning on putting in a “byline” class for article credit.
I’d be interested in hearing what others are doing with this new-found ability (or if you have any ideas?)
Fabio,you’re so handsome : )
Ha. Thanks? I guess?
Fabio great post,
Do you know why I can’t see anything from the style drop down menu nothing except default text. I even was using provided templates, and when I go and edit the text and want to add heading 1 style there is nothing in that menu?
Anton, the bit of testing I’ve just done hasn’t shown any problems. Try clearing your browser cache and cookies and see if that solves it.
If the problem persists after that, contact our support folks – they’ll be able to better diagnose hiccups like that.
great! really glad to see this, have been wishing for predefined selectable styles since we started with MailChimp. thank you!
As with Anton, I too cannot see the style in my editor. It only shows “default” text. I used the exact code in the post as well and cleared cache and cookies.
same here. styles do not appear in wysiwyg editor drop down.
Hi there.
The styles that I’ve added (I even copied the .quotes one from above) are also not showing up in the drop down at all. I have cleared browser cache, tried it in Firefox and Safari, and still, it’s not working.
Is someone there at MailChimp looking into this? Many people seem to have the same issue, but no response here.
Thanks!
Kristin
Hi again,
The solution is that the styles don’t show up in the template editor, but should show up in the campaign editor.
:)
Kristin
Hey Kristin :)
thanks a lot for your reply, have been trying for more than 2 hours to make it work.
could you please add this in the main article to avoid spinning around for new users.
Thanks
Mo
I’m having the same problem with the styles not showing in the drop down. The only options are “Title”, “Subtitle”, “Default Text”. I also copied the .quotes example exactly and nothing.
Where am I going wrong?
Thanks,
Jozz
This is great and all, but where do I put it? Everywhere that I’ve tried placing it, it just shows up as the text in the Preview.
Does it go in the header? I would assume not, but I tried it anyway and it broke it.
Does it go right before where you want the style to be? That broke it, too.
Please please please give me an example of WHERE this goes!
You have to put it in between the tags for example in the section of the HTML document.
Great article. Just one thing, I get TOC Heading1 and TOC Heading2 in the Styles in Campaign editor too. How can I gain more control over what is going to appear in the Styles drop down menu?
I’m having a similar problem…..In my template I put the following code
/*
@style compHead
*/
.compHead{
color:#ffffff;
display:block;
font-family:Times New Roman;
font-size: 25px;
font-weight: bold;
line-height:100%;
margin-top:10px;
margin-right:0;
margin-bottom:10px;
margin-left:0;
text-align:left!important;
}
and then in the related campaign, I click on a section to edit, place the cursor on a new line after my last piece of text and I get a half rendered Block Styles -> heading 1 style to choose from.
The custom style compHead does NOT!.
If i highlight the text that the style is applied to, compHead is displayed in the style dropdown.
How can I ensure that the compHead style is ALWAYS available to me when I am in Edit Your Content mode ?
thanks
alan