Before going to explain about these card, we should know about all the properties of card which will be used with Twitter card meta tags.
- twitter:card
Description: It shows the type of card we are using. It's required for all types of cards.
IsRequired: Yes
- twitter:title
Description: We can put any title which we want to show as Tweet Title
IsRequired: Yes, it is required for all cards except App Card.
Max Length: 70 characters
- twitter:description
Description: It's for the description of the tweet.
IsRequired: No, it is required for all cards except App Card.
Max Length: 200 chars
- twitter:image
Description: URL of image to use in the card. Images must be less than 5MB in size. JPG, PNG, WEBP and GIF formats are supported. Only the first frame of an animated GIF will be used. SVG is not supported.
IsRequired: Yes, it is required for all cards except App Card.
- twitter:player
Description: Url of player iframe
IsRequired: It's required for player card
- twitter:player:stream
Description: It contains the url of video or audio. Its url must be a secure site
IsRequired: It's required for player card
- twitter:player:height
Description: It shows the player iframe height in pixels
IsRequired: Yes
- twitter:player:width
Description: It show the player iframe width in pixels
IsRequired: Yes
For more properties about twitter card markup
click here
Summary Card
Summary card is a kind of twitter card which allows us to show an image with our tweets. Basically, it is designed to give the reader a preview of the content before clicking through to your website.
Following are the code snippet which is used to implement twitter summary card.
- <meta name="twitter:card" content="summary" />
- <meta name="twitter:site" content="@ProgramCafe" />
- <meta name="twitter:title" content="Twitter Summary Card Example" />
- <meta name="twitter:description" content="This describes about Twitter Summary Card" />
- <meta name="twitter:image" content="https://www.programcafe.in/card-image.png" />
- <meta name="twitter:image:alt" content="Summary Card" />
In the above code snippet content="summary" indecates the type of card used on this page.
Note
Card properties twitter:card and twitter:title are mandatory while twitter:description is not required. According to twitter guidelines we should not re-use the title of content as description or use this field to describe the general services provided by the websites.
Card property twitter:image is not a mandatory attribute but if we want we can use it. Following are the guidelines for this properties,
- We should not use a generic image such as your website logo, author photo, or other image that spans multiple pages.
- Images for this Card support an aspect ratio of 1:1 with minimum dimensions of 144x144 or maximum of 4096x4096 pixels.
- Image size must be less than 5 MB.
- JPG, PNG, WEBP and GIF formats are supported.
Here is the complete html code for a Twitter "Summary Card"
SummaryCard.html
- <!DOCTYPE html>
- <html>
- <head>
- <title>Twitter Summary Card</title>
- <meta charset="utf-8" />
- <meta name="twitter:card" content="summary" />
- <meta name="twitter:title" content="Summary Card Implementation" />
- <meta name="twitter:description" content="This describes about Twitter Summary Card" />
- <meta name="twitter:site" content="@KumarPraveen179" />
- <meta name="twitter:image" content="http://www.programcafe.in/card-image.png" />
-
- <style>
- body{background: #148c6b;color: #fff;font-family: calibri;font-size: 16px;}
- a.tweet{color:#fff; padding:6px 20px; background:#ff6600;margin-top:40px;text-decoration:none; border-radius:5px;}
- </style>
-
- </head>
-
- <body>
- <h1>Twitter Summary Card</h1>
- <p>Summary Card Implementaion on Web Page</p>
- <div>
- <a class="twitter-share-button"
- href="https://twitter.com/intent/tweet?via=ProgramCafe">
- Tweet
- </a>
-
- <a class="tweet"
- href="https://twitter.com/intent/tweet?via=ProgramCafe">
- Tweet
- </a>
- </div>
-
- <script>
- //Twitter widget script to render tweet button
- window.twttr = (function (d, s, id) {
- var js, fjs = d.getElementsByTagName(s)[0],
- t = window.twttr || {};
- if (d.getElementById(id)) return t;
- js = d.createElement(s);
- js.id = id;
- js.src = "https://platform.twitter.com/widgets.js";
- fjs.parentNode.insertBefore(js, fjs);
-
- t._e = [];
- t.ready = function (f) {
- t._e.push(f);
- };
-
- return t;
- }(document, "script", "twitter-wjs"));</script>
- </body>
- </html>
In the above code snippet, I am using Twitter widgets script to render the twitter button which is showing in the below snapshot.
Tweet Window
Now click on the Tweet button to share this information on Twitter and check your tweet on your timeline. It will look like the following snapshot which was taken from my timeline.
Summary Card With Large Image
The Summary Card with Large Image features a large, full-width prominent image alongside a tweet. It is designed to give the reader a rich photo experience and clicking on the image brings the user to your website.
Following is the code snippet which is used to implement twitter summary card with large image.
- <meta name="twitter:card" content="summary_large_image" />
- <meta name="twitter:title" content="Twitter Summary Card With Large Image Example" />
- <meta name="twitter:site" content="@ProgramCafe" />
- <meta name="twitter:creator" content="@ProgramCafe" />
- <meta name="twitter:description" content="It is designed to give the reader a preview of the content before clicking through to your website." />
- <meta name="twitter:image" content="https://www.programcafe.in/card-large-image.png" />
In the above code snippet content="summary_large_image" indecates the type of card used on this page. As with "Summary Card" card properties, twitter:card and twitter:title properties are required.
If the has no twitter:title attribute then card validator will show some error message. I will explore about it at the end of the page where I will explain about Twitter Card Validator onlline feature.
Following are my complete html for Summary Card With Large Image.
SummaryCardWithLargeImage.html
- <!DOCTYPE html>
- <html>
- <head>
- <title>Summary Card With Large Image Example</title>
- <meta charset="utf-8" />
- <meta name="twitter:card" content="summary_large_image" />
- <meta name="twitter:title" content="Summary Card With Large Example" />
- <meta name="twitter:description" content="This describes about Twitter Summary Card With Large Image" />
- <meta name="twitter:site" content="@KumarPraveen179" />
- <meta name="twitter:image" content="http://www.programcafe.in/card-large-image.png" />
-
- <style>
- body {
- background: #148c6b;
- color: #fff;
- font-family: calibri;
- font-size: 16px;
- }
- </style>
-
- </head>
- <body>
- <h1>Summary Card With Large Image</h1>
- <p>Summary Card with Large Image Implementaion on Web Page</p>
- <div>
- <a class="twitter-share-button"
- href="https://twitter.com/intent/tweet?via=ProgramCafe">
- Tweet
- </a>
- </div>
-
- <script>
- window.twttr = (function (d, s, id) {
- var js, fjs = d.getElementsByTagName(s)[0],
- t = window.twttr || {};
- if (d.getElementById(id)) return t;
- js = d.createElement(s);
- js.id = id;
- js.src = "https://platform.twitter.com/widgets.js";
- fjs.parentNode.insertBefore(js, fjs);
-
- t._e = [];
- t.ready = function (f) {
- t._e.push(f);
- };
-
- return t;
- }(document, "script", "twitter-wjs"));</script>
- </body>
- </html>
Now run this page and copy the url of this page paste in
Card Validator text box to check how it will look after posting on your Twitter timeline.
As with card validator preview, it will look the same as our Twitter timeline after tweeting this page by following the same step as the Twitter Summary Card.
On the Twitter timeline, it looks like the following snapshot.
Player Card
By using Twitter Player Card we can post an video or audio stream along with our tweets as like Summary Card With Large Image where we can post a large image with tweet.
Twitter Policy
But it's not simply like Summary Card or Summary Card With Large Image. There are some twitter developer policies. We can only post this card if it is approved by the Twitter team.
So, before getting to know more aout rules and policy, let us see a code snippet which is used for Player Card implementation.
- <meta content='text/html; charset=UTF-8' http-equiv='Content-Type' />
- <meta name="twitter:card" content="player" />
- <meta name="twitter:site" content="@KumarPraveen179" />
- <meta name="twitter:title" content="Twitter Player Card Implementation" />
- <meta name="twitter:description" content="This is a sample video to test player card." />
- <meta name="twitter:image" content="https://example.in/file/d/clipImage.png" />
- <meta name="twitter:player" content="https://programcafe.in/player.html" />
- <meta name="twitter:player:width" content="480" />
- <meta name="twitter:player:height" content="480" />
- <meta name="twitter:player:stream" content="https://example.com/file/d/myclip.mp4" />
- <meta name="twitter:player:stream:content_type" content="video/mp4" />
In the above code html,
content="player" denotes the type of card used on this page.
The image mentioned in twitter:image property is used to display the image at the place of player where iframe or inline player is not supported, and this property is required for Player Card.
The card property twitter:player is required and it must have an https url for IFrame player.
The card property twitter:player:stream contains the url of the video or audio file.
Height and Width properties twitter:player:height and twitter:player:width are mandatory properties for player card. It specifies the height and width of player iframe in pixcels.
http://programcafe.in/PlayerCard.html is the url of my PlayerCard page. Let's paste this url into twitter card validator.
While validating this player card, it shows a message *programcafe.in is not whitelisted for player card. And the button is for Request Approval.
When we click on the button Request Approval, a form will be opened where we need to fill all required information. It may take 1 to 3 business days for approval.
After submitting the approval request we can check the status from card validator, it will show approval is pending for player card. Twitter says - you will get an email regarding player card approval which is mentioned at the time of request for player card approval.
Let's try
Once the card is approved, then our tweets for player card look like the following snapshot which is taken by twitter
Click here.
App Card
The App Card is a great way to represent mobile applications on Twitter and to drive installs. We designed the App Card to allow for a name, description and icon, and also to highlight attributes such as the rating and the price.
In this article I will not explain about it, to know more about app card click on the following link.
https://developer.twitter.com/en/docs/tweets/optimize-with-cards/overview/app-card
Fallback