Minimal Social Markup
Published on July 14, 2022 (⻠October 19, 2024), filed under Development (RSS feed for all categories).
Every website and app these days needs so-called âsocial markup,â metadata for a richer and prettier display in social media and messaging tools. This markup is usually based on the Open Graph protocol, but Twitter, most notably, has their own metadata (some of which falls back to Open Graph).
For a frontend developer, and especially a frontend minimalist, it may be interesting to know what the most minimal markup is so as to get a meaningful result. Iâve lately been focusing on this question, reviewing and optimizing my past setup.
If you donât want to read any further, hereâs the absolute minimum you need:
<!-- <head> (and <body>) needed for LinkedIn -->
<head>
<!-- âtwitter:cardâ and title needed for Twitter -->
<meta name=twitter:card content=summary_large_image>
<meta property=og:title content="This is a test title">
<!-- Quotes needed for WhatsApp and Signal -->
<meta property="og:description" name="description" content="This is a test description.">
<meta property="og:image" content="https://hell.meiert.org/core/png/test.png">
If you do want to read further, hereâs how Iâve arrived at this code.
Requirements
First, itâs relevant to know that in my work, I focus on minimal HTML. I prefer to use the least HTML possible, usually omit optional markup for that reason, and I love the idea of ID- and class-less web development. (Not removing all spaces on every page is one exception to this ruleââview-sourceâ is instructive.)
But what are we trying to identify the least amount of markup for? In my mind, whatever is needed to:
- show the title for the page in question;
- display an image;
- provide a description (optional).
Where should this all work? For meâyour mileage may varyâthis social markup should be displayed properly on the following platforms and apps:
I do care about some other networks, too (like XING), and I would care more about other messengers, if I used them (like Telegram), but Iâve been working with kind of a bet here that other networks and apps show a similar behavior as the ones listed. So far, this seems to work. Please let me know about major platforms that show a different behavior (as well as any issues)!
Social Markup
The markup for these requirements is fairly easy to identify.
For the title, the title
element suffices everywhere but on Twitter (why!). To produce âvalidâ Twitter card markup, you must use og:title
:
<meta property=og:title content="This is a test title">
To display an image, Twitter also needs twitter:card
markup, which also controls the size of the image (cf. summary
and summary_large_image
):
<meta name=twitter:card content=summary_large_image>
<meta property=og:image content=https://hell.meiert.org/core/png/test.png>
To show the description, slap property=og:description
on an existing description
element (but, thanks Amier Saleh, mind the order):
<meta property=og:description name=description content="This is a test description.">
That leads to the following most minimal markup (following my preferred source order):
<meta name=twitter:card content=summary_large_image>
<meta property=og:title content="This is a test title">
<meta property=og:description name=description content="This is a test description.">
<meta property=og:image content=https://hell.meiert.org/core/png/test.png>
Problems
But, this alone doesnât do it, even though itâs valid (validate the gist) and matches the big playersâ specs.
One problem relates to the inability of messenger apps (!) to retrieve description and image, if the respective attributes arenât put in quotes. (When I still used WhatsApp, I contacted them three times about the image issue, providing test pages and all, but they dropped it.)
Another problem is social markup not being identified properly, for example by LinkedIn, if itâs not following a <head>
start tag.
Both, to spell it out, are pretty massive, pretty embarrassing bugs, because both deny valid HTML. That is, this code is proper, in conformance with the HTML specifications. (Youâre professionalsâfix this.)
Both, then, leads to the markup shared in the beginning:
<head>
<meta name=twitter:card content=summary_large_image>
<meta property=og:title content="This is a test title">
<meta property="og:description" name="description" content="This is a test description.">
<meta property="og:image" content="https://hell.meiert.org/core/png/test.png">
⧠And this, to the best of my knowledge, isnât just minimal, itâs the most minimal social markup.
What I think about this? I already mentioned how upset (but not surprised) I am that HTML is treated like XHTML and that valid HTMLâwith no <head>
tag, no quotesâisnât fully supported. But I also believe this markup is still too muchâin short, Twitter should make use of page titles (title
element) and follow Open Graph (including dumping twitter:card
), and social markup consumers should generally consider meta descriptions. Then the most minimal markup was to add an og:image
âbecause that wouldnât otherwise be on a page.
Update (November 20, 2022)
The identified markup seems to work well with Mastodon, too. Iâm monitoring and will update this post, if need be. (If you want to connect on Mastodon, you find me at @j9t@mas.to.)
About Me
Iâm Jens (long: Jens Oliver Meiert), and Iâm a web developer, manager, and author. Iâve worked as a technical lead and engineering manager for a few companies, Iâm a contributor to several web standards, and I write and review books for OâReilly and Frontend Dogma.
I love trying things, not only in web development and engineering management, but also in other areas like philosophy. Here on meiert.com I share some of my experiences and views. (I value you being critical, interpreting charitably, and giving feedback.)
Comments (Closed)
-
On July 15, 2022, 2:12 CEST, Kyle Simpson said:
I have certainly way more social markup on my page than you, but I checked that the stuff you show is included correctly in my markup.
Sadly, it seems that Twitter still wonât render a card properly for my site (according to their checker). Linked-In does just fine with it, though, so itâs not all wrong.
Shame that this social markup is so voodooây. It should be very straightforward, but it isnât.
-
On July 15, 2022, 8:28 CEST, Jens Oliver Meiert said:
Kyle đ
There seems to be an issue with the Twitter card validator⊠live, the markup works as expected (cf. the tweet for this post). I added a note pointing out that itâs currently unreliable.
Social markup should indeed be more straightforward. We can share our appetite for more compact codeâmaybe that will create appetite for companies to consolidate this markup.
-
On July 16, 2022, 1:25 CEST, GooDuh said:
i get it now đ
-
On July 20, 2022, 23:48 CEST, Brendan Smith said:
One aspect you have overlooked is the relevance of some of this markup to SMS apps. Iâm not sure of the current state of iOS however Android (Samsung/Pixel) default apps will also show an og:image, title, description and domain when available. If an SMS contains only one link and the message char count is below the single message limit, this preview will be shown.
It really does help lower the phishiness of things like pURLs delivered via SMS when you supply a company logo as your og:image - a branded SMS so to speak.
-
On July 21, 2022, 8:48 CEST, Jens Oliver Meiert said:
Thanks Brendan. Not sure this was overlooked? (I didnât test in SMS apps though, thatâs correct.) This markup is useful, and it makes sense for various apps to use it.
Read More
Maybe of interest to you, too:
- Next: Website Optimization Measures, Part XIV
- Previous: Thoughts on an Accessibility âGet Wellâ Plan
- More under Development
- More from 2022
- Most popular posts
Looking for a way to comment? Comments have been disabled, unfortunately.
Get a good look at web development? Try WebGlossary.infoâand The Web Development Glossary 3K. With explanations and definitions for thousands of terms of web development, web design, and related fields, building on Wikipedia as well as MDN Web Docs. Available at Apple Books, Kobo, Google Play Books, and Leanpub.