How to change Twitter widgets font size or color?

by Peter Moss 1. March 2010 09:55

Twitter was nice enough to provide us with a Javascript JSON widget to retrieve one's public timeline.

Twitter widget constructor has a bunch of parameters that you can change to customize the look and feel of your widget.

However one critical, in my opinion, element was left out and remains hardcoded. Font definition should have been exposed in the widget construction, or at least the CSS classes should have been properly documented.

Here is how the twitter widget can be invoked:

<script src="http://widgets.twimg.com/j/2/widget.js"></script>
<script>
new TWTR.Widget({
      version: 2,
      type: 'profile',
      rpp: 4,
      interval: 4000,
      width: 'auto',
      height: 150,
      theme: {
         shell: {
         background: '#ffffff',
         color: '#000000'
       },
      tweets: {
         background: '#ffffff',
         color: '#000000',
         links: '#0707eb'
      }
   },
   features: {
      scrollbar: false,
      loop: true,
      live: false,
      hashtags: true,
      timestamp: true,
      avatars: false,
      behavior: 'default'
   }
}).render().setUser('2PeterMoss').start();
</script>


I have looked at their cryptic code in widget.js and pulled out the CSS class that needs to be changed.

To change the font of your tweets you have to change the following CSS class:

   .twtr-tweet-text {
    font size: 105%;
    font-family: Georgia, Serif;
    }


There are other CSS classes that can be modified:

   .twtr-hyperlink
   .twtr-atreply
   .twtr-hashtag
   .twtr-tweet-wrap
   .twtr-avatar
   .twtr-img


The above twitter widget works but there is a cleaner solution on code.google.com site.
At least this one provides you with a nice css and Javascript code that is easier on your eyes :-)

Tags:

AJAX | Javascript

Comments

3/26/2010 3:17:43 PM #

Exactly what I was looking for!  A big thanks to you sir!!!

Patrick | Reply

4/7/2010 5:07:03 PM #

Hello Peter, can you PLEASE tell me how I even get to the place to enter the code?  Every time I type in "how to change Twitter's font size" I get information on changing the font size in Wordpress or downloading wordpress plugins, or changing the .CSS file where is this stuff located?

I am using windows xp/ Firefox browser.

Paula | Reply

4/20/2010 4:17:08 PM #

What I did was grab the widget.js & widget.css files and put them on my server. That way I can manipulate the two files to do whatever I want.

I am in the process of designing a tweet wall using the Twitter search widget js file but can only get one line of column(s) to show at the moment.

LJ Webster | Reply

5/6/2010 8:46:08 AM #

Starting to understand a bit more now... Thanks for keeping it simple!

Barry Hertz | Reply

2/5/2011 12:03:40 PM #

Hello Peter, this is what I tried to do immediately (bring the .js and .css files to my server) so that I could customize them at will.

However, I have run into a little roadblock, maybe you have a quick insight for me:
- I changed the reference to my hosted js file in blogger - OK
- In the .js file I left the widget.css references as is - OK
- But when I change the widget.css reference to my hosted css file - no more widget

Here is the line of js code I changed:
twttr.loadStyleSheet('http://web.me.com/alek.grguric/code/twidget.css', this.widgetEl);

Am I missing something really basic? Thanks!

AlekG | Reply

2/6/2011 3:26:50 AM #

My problem with this was that I was trying to change the font size in the widget when hosted with Google's Blogger. Bringing the .js and .css files to a server I had access to (Apple's me.com) didn't seem to work and the widget was not rendered when the .js file referenced the .css file on my server (it would be OK if the files remained on the default servers).

However, the "99 cent" solution seems too good to be true. I just put this code before the script code (cut-and-pasted directly from Twitter) in the widget:

<style type="text/css">
p {font-size:11px;}
</style>

and now the widget is rendered fine, with smaller text, and all is good.


Alek Grguric | Reply

8/2/2012 1:19:28 PM #

This is a nice, simple fix. I had wrapped the widget in a div and kept trying to style the text but couldn't change the font size. I don't know why they wouldn't have that option customizable under appearance. Now if I can just get it to validate........

Thanks!

Doane | Reply

8/29/2012 8:40:18 AM #

Again, for newbies, just add this to your page where the widget it embedded or you can add the contents of the style below in your sites CSS file.

<style type="text/css">
.twtr-tweet-text {
    font-size: 105%;
    font-family: whatever-your-font-is-you-want-to-use, Arial, Verdana;
    }
</style>

To use "whatever-your-font-is-you-want-to-use" do a search for embedding custom fonts and learn how to embed those on your site, then you can add the font-family name to the list....

Font Squirrel (http://www.fontsquirrel.com/) is the best site for taking a font and converting it to the necessary formats (4 formats for full compatibility) and they provide the CSS you need as well...

Robert | Reply

5/7/2013 7:38:21 AM #

First of all Thanks..!

I tried your script its amazing!

Can I show actual avatar on feed?

Jaison | Reply

Add comment




biuquote
  • Comment
  • Preview
Loading