CSS for Embedded Widgets

Updated on Fri, 2014-02-07 12:25

When embedding a Twitter for Websites widget, a placeholder is pasted into your page. This takes the form of either a link to the equivalent page on Twitter (a profile, timeline, or Web Intent), or an HTML <blockquote> of the Tweet being embedded.

These shallow versions of the widgets are progressively enhanced by our widgets.js script to become complex, interactive components. But by being present in your page, we ensure that if the reader of your page is on a bad connection, if Twitter suffers technical difficulties, or if a Tweet you've embedded is deleted by its author, the content of your page will always make sense.

By default, embed codes will adopt whatever styling you provide, such as a regular link — Tweet — or a quote:

Trying to pick just one track from OK Computer for @ThisIsMyJam. Send help.

— Ben Ward (@benward) October 22, 2013

CSS to match rendered widgets

Following is some code that you can add to your stylesheet to style the widgets in a way that more resembles their fully rendered form. You can include this code as is, or use it as a starting point to modify to your preferences. The code will style embed codes to look more like these:

Buttons

Links appear styled as buttons.

Embedded Tweets

Blockquotes have the same dimensions and text size as an embedded Tweet.

Embedded Timelines

Timeline links are styled to be distinct, rather than blend into other links on the page.

  1. /** Buttons */
  2.  
  3. a.twitter-share-button,
  4. a.twitter-mention-button,
  5. a.twitter-hashtag-button {
  6.   display: inline-block;
  7.   padding: 1px 3px 0 19px;
  8.  
  9.   border: #ccc solid 1px;
  10.   border-radius: 3px;
  11.   background: #f8f8f8 url(//platform.twitter.com/images/bird.png) 2px 3px no-repeat;
  12.   background: url(//platform.twitter.com/images/bird.png) 2px 3px no-repeat,
  13.               -webkit-linear-gradient(#fff, #dedede);
  14.   background: url(//platform.twitter.com/images/bird.png) 2px 3px no-repeat,
  15.               linear-gradient(#fff, #dedede);
  16.   background-size: 16px 13px, auto auto;
  17.  
  18.   /* Text */
  19.   font: bold 11px/17px Helvetica, Arial, sans-serif;
  20.   text-decoration: none;
  21.   color: #333;
  22.   text-shadow: 0 1px 0 rgba(255, 255, 255, .5);
  23.  
  24.   white-space: nowrap;
  25. }
  26.  
  27. /* Colour Highlight for keyboard navigation */
  28. a.twitter-share-button:focus,
  29. a.twitter-mention-button:focus,
  30. a.twitter-hashtag-button:focus {
  31.   outline: none;
  32.   border-color: #0089cb;
  33. }
  34.  
  35. /** Embedded Tweets */
  36.  
  37. blockquote.twitter-tweet {
  38.   display: inline-block;
  39.   padding: 16px;
  40.   margin: 10px 0;
  41.   max-width: 468px;
  42.  
  43.   border: #ddd 1px solid;
  44.   border-top-color: #eee;
  45.   border-bottom-color: #bbb;
  46.   border-radius: 5px;
  47.   box-shadow: 0 1px 3px rgba(0,0,0,0.15);
  48.  
  49.   font: bold 14px/18px Helvetica, Arial, sans-serif;
  50.   color: #000;
  51. }
  52.  
  53. blockquote.twitter-tweet p {
  54.   font: normal 18px/24px Georgia, "Times New Roman", Palatino, serif;
  55.   margin: 0 5px 10px 0;
  56. }
  57.  
  58. blockquote.twitter-tweet a[href^="https://twitter.com"] {
  59.   font-weight: normal;
  60.   color: #666;
  61.   font-size: 12px;
  62. }
  63.  
  64. /** Timeline */
  65.  
  66. a.twitter-timeline {
  67.  
  68.   /* Buttonish */
  69.   display: inline-block;
  70.   padding: 6px 12px 6px 30px;
  71.   margin: 10px 0;
  72.  
  73.   border: #ccc solid 1px;
  74.   border-radius: 3px;
  75.   background: #f8f8f8 url(//platform.twitter.com/images/bird.png) 8px 8px no-repeat;
  76.  
  77.   /* Text */
  78.   font: normal 12px/18px Helvetica, Arial, sans-serif;
  79.   color: #333;
  80.  
  81.   white-space: nowrap;
  82. }
  83.  
  84. a.twitter-timeline:hover,
  85. a.twitter-timeline:focus {
  86.   background-color: #dedede;
  87. }
  88.  
  89. /* Colour Highlight for keyboard navigation */
  90. a.twitter-timeline:focus {
  91.   outline: none;
  92.   border-color: #0089cb;
  93. }


These styles provide a starting point for use in your site. If you have your own versions, or enhancements, please share them in the Twitter for Websites discussion forum.