A blog & community for non-professional web designers, programmers, webmasters, and other web savvies.

How to Embed a Stylized Twitter Timeline to your Website

June 26, 2010 - 12:00am -- Haily

Twitter offers several widgets for you to embed a timeline of your tweets in your website. But the problem with these widgets is that they are essentially inflexible boxes that can take up more room than needed. On top of that, the style of these widgets will likely clash with your website's design if it uses a different style than the widget.

But before Twitter began offering this widget, Twitter offered a much more flexible script that allowed you to embed your tweets. Though I admit, it's somewhat more confusing and less appealing to the average Twitterer, it's nonetheless the much preferred Twitter embed among web designers. And even though Twitter no longer promotes it, it still works! Here's a comparison with the current widget on the left and the older one on the right using the @IceCaves account as an example:

Twitter's Profile Widget

Previous Embed with Added Styles for IC

twitter.com/IceCaves

    The Code

    The first part of the code is the where the tweets are displayed:

    <div id="twitter_div" style="width:280px;overflow:hidden">
    <ul id="twitter_update_list"></ul>
    </div>

    The tweets will be added via JavaScript each as an individual list item. It's so simple, that you can easily use CSS to manipulate the tweets and the area where they are displayed.

    This part of the code is what calls up and executes the JavaScript that calls up the tweets:

    <script type="text/javascript" src="http://twitter.com/javascripts/blogger.js"></script>
    <script type="text/javascript" src="http://twitter.com/statuses/user_timeline/IceCaves.json?callback=twitterCallback2&amp;count=5"></script>

    You can change "IceCaves" to your account name and "5" to the number of tweets you want to call up. Since this directly loads from Twitter, if Twitter goes down (think fail whale), then this script also goes down. Twitter recommended placing this part of the code just before the </body> end tag so that your site isn't slowed down whenever Twitter is down.

    Stylizing and Adding to the Code

    Now I will go through some things you can do to stylize the code.

    <a href="http://twitter.com/IceCaves" target="_blank"><span style="font-weight:normal">twitter.com/</span>IceCaves</a>

    Add a link back to you main Twitter profile somewhere. The text can read anything. It could just say "follow me" or "Twitter" to name just a couple of ideas.

    <div style="height:130px;overflow:auto">

    </div>

    One of the things you can do is place it in a scrollable area. This will allow you to embed several more tweets and allow your users to scroll through more of your recent tweets. It might just be the thing that will encourage them to follow you.

    CSS:

    #twitter_div {margin:0px}
    #twitter_div ul {list-style-type:none;margin:0px;padding:0px}
    #twitter_div li {margin:1px 0px 3px 0px;padding:0px}

    If you want, you can remove the bullet points as well as the margin and padding for the <ul> list items like I did in the example above.

    <ol id="twitter_update_list"></ol>

    You can also change the list from unordered (<ul>) to ordered (<ol>) to instead of showing bullets next to the tweets, you can display numbers if you want.

    CSS:

    #twitter_div li {border-bottom:2px solid #999999}

    Whether or not you remove the bullet points, it might help to add a border to separate the tweets from each other.

    CSS:

    #twitter_div li a {color:black;display:block;margin-bottom:5px;font-weight:bold}
    #twitter_div li span a {color:#002288;display:inline;margin-bottom:0px;font-weight:bold}

    What the above code will do is stylize the hyperlinks of the list items, but that's not all! The second line of the code above affects only hyperlinks in the tweet, which means that the first line affects everything else, which is the tweet's time and date. What I did with the code above was apply the display:block element to the time so that it could stand alone in its own line, apart from the tweet message. What the second line does is change the color of the links in the tweets to emphasize them and make the tweets more readable. Both links are in bold.

    Take it Further

    The purpose of the codes above aren't for copying but so you know some of the things you can do. Take it further and your own styles and effects. Get creative!

    What other techniques do you use on your Twitter embeds? Please share in the comments!

    Comments

    aashni
    aashni's picture
    Iceberg (?)
    Elite Yeti (?)
    Rank Points: 73 (?)
    Age: 19
    Posts: 1,753
    Status: Offline
    WWW

    Ahh, this tutorial is so helpful! I think I used it on my first layout, and then have just been copying the code I had on my first layout, and applied it to most of my other layouts, formatted to my needs. I think one of my fav examples of this is on http://emnhosting.com :)

    --------------------

    My Sites: 1 | 2 | 3 | 4 | 5 | 6

    Scarlie
    Scarlie's picture
    Glacier (?)
    Elite Yeti (?)
    Rank Points: 104 (?)
    Posts: 440
    Status: Offline

    Aashni I did the exact same. I hate that Twitter stopped giving this code out on the widget options!

    --------------------

    I'm a jack of all trades in training.

    jenny
    jenny's picture
    Iceberg (?)
    Rank Points: 50 (?)
    Age: 17
    Posts: 856
    Status: Offline
    WWW

    @Scarlett Exactly! Do they really think I want to use their blocky, inflexible widget?

    --------------------

    Jenny-Jen-Jen :D
    Bloggity: www.windymill.net
    Web-Design Portfolio: www.jenny-aster.net

    aashni
    aashni's picture
    Iceberg (?)
    Elite Yeti (?)
    Rank Points: 73 (?)
    Age: 19
    Posts: 1,753
    Status: Offline
    WWW

    NO! it's ugly. It doesn't go with my layout. It doesn't look pretty. Did i mention it's UGLY?

    --------------------

    My Sites: 1 | 2 | 3 | 4 | 5 | 6

    Anna
    Anna's picture
    Icicle (?)
    Elite Yeti (?)
    Rank Points: 48 (?)
    Age: 17
    Posts: 827
    Status: Online
    WWW

    I'm trying to incorporate one of these into the new layout that I'm working on for AN. But I want the text to be left-aligned but not so far over to the left. Is there a way to center the whole timeline but not the text inside?

    --------------------

    Yay, Anna!
    AnnaNeo

    aashni
    aashni's picture
    Iceberg (?)
    Elite Yeti (?)
    Rank Points: 73 (?)
    Age: 19
    Posts: 1,753
    Status: Offline
    WWW

    try wrapping the twitter into a center div:

    <style type="text/css">
    .center{margin:0px auto; padding:0px;}
    OTHER CSS CODES
    </style>

    <div class="center">
       TWITTER CODES
    </div>

    you'll need to change the CSS CODES and TWITTER CODES to the actual codes needed :P

    --------------------

    My Sites: 1 | 2 | 3 | 4 | 5 | 6

    Anna
    Anna's picture
    Icicle (?)
    Elite Yeti (?)
    Rank Points: 48 (?)
    Age: 17
    Posts: 827
    Status: Online
    WWW

    Didn't work. :(

    --------------------

    Yay, Anna!
    AnnaNeo

    aashni
    aashni's picture
    Iceberg (?)
    Elite Yeti (?)
    Rank Points: 73 (?)
    Age: 19
    Posts: 1,753
    Status: Offline
    WWW

    It's all centered for me - is that how it is for you?

    Try adding:

    .center{margin:0px auto; padding:0px; text-align:left;}

    That should work

    --------------------

    My Sites: 1 | 2 | 3 | 4 | 5 | 6

    aashni
    aashni's picture
    Iceberg (?)
    Elite Yeti (?)
    Rank Points: 73 (?)
    Age: 19
    Posts: 1,753
    Status: Offline
    WWW

    I checked on your site - it didn't work...
    Try this:

    .center{margin:0px auto;padding:0px;text-align:center;}
    #twitter_div {margin:0px;}
    #twitter_div ul {list-style-type:none;margin:0px;padding:0px;text-align:left;}
    #twitter_div li {margin:1px 0px 3px 0px;padding:0px;border-bottom:1px solid #d2f656;text-align:left;}
    --------------------

    My Sites: 1 | 2 | 3 | 4 | 5 | 6

    Anna
    Anna's picture
    Icicle (?)
    Elite Yeti (?)
    Rank Points: 48 (?)
    Age: 17
    Posts: 827
    Status: Online
    WWW

    It didn't work, but the div was a good idea. I adjusted the padding, and I got it in the right place. :) Thanks!

    --------------------

    Yay, Anna!
    AnnaNeo

    aashni
    aashni's picture
    Iceberg (?)
    Elite Yeti (?)
    Rank Points: 73 (?)
    Age: 19
    Posts: 1,753
    Status: Offline
    WWW

    Haha :) no problem :) I reloaded your page, and figured that's probably what you had done :P

    try adding

    padding-top:0px;

    That will get rid of the big space at the top :)

    --------------------

    My Sites: 1 | 2 | 3 | 4 | 5 | 6

    Anna
    Anna's picture
    Icicle (?)
    Elite Yeti (?)
    Rank Points: 48 (?)
    Age: 17
    Posts: 827
    Status: Online
    WWW

    Oh! Thanks again! :) I wish I could give you +Karma.

    --------------------

    Yay, Anna!
    AnnaNeo

    aashni
    aashni's picture
    Iceberg (?)
    Elite Yeti (?)
    Rank Points: 73 (?)
    Age: 19
    Posts: 1,753
    Status: Offline
    WWW

    Haha :P Remember that post for when the karma system comes back :P

    --------------------

    My Sites: 1 | 2 | 3 | 4 | 5 | 6

    Anna
    Anna's picture
    Icicle (?)
    Elite Yeti (?)
    Rank Points: 48 (?)
    Age: 17
    Posts: 827
    Status: Online
    WWW

    I remembered! :P

    --------------------

    Yay, Anna!
    AnnaNeo

    theannabella
    theannabella's picture
    Snowball (?)
    Rank Points: 8 (?)
    Posts: 86
    Status: Offline
    WWW

    Thanks for posting this! I embedded it on my website; it's truly awesome. ^_^

    @IceCaves on Twitter

      Stay Connected

      Twitter Facebook Tumblr Google+ Glaciallis Google RSS

      *Follow us on Twitter or Facebook to also follow minor site updates that don't make it to the homepage news.