How to Share Code on Twitter and LinkedIn Without Looking Like a Newbie
Professional tips for sharing code snippets on social media: tools, formatting, and etiquette.
On this page
We've all seen it. A tweet that's just raw code pasted as text. No syntax highlighting, no formatting, barely readable.
Don't be that person.
Here's how to share code on social media like a pro.
The Problem
Twitter and LinkedIn don't support code formatting. When you paste code:
- Indentation disappears
- Special characters get mangled
- No syntax highlighting
- Long lines wrap weirdly
The result is ugly and hard to read.
Solution 1: Code Screenshot Tools
The most popular approach. Tools like Carbon and Ray.so render your code as a beautiful image.
Carbon (carbon.now.sh)
- Tons of themes and customization
- Supports most languages
- Export as PNG or SVG
- Free
Ray.so (ray.so)
- Modern, clean design
- Quick and easy
- Great defaults
- Free
How to Use
- Paste your code
- Select language for syntax highlighting
- Choose a theme
- Export and share
Pros
- Looks professional
- Syntax highlighting
- Consistent formatting
Cons
- Not searchable
- Can't copy the code
- Takes extra steps
Solution 2: GitHub Gists
Create a Gist and share the link. Twitter/LinkedIn will show a preview.
Pros
- Code is copyable
- Searchable
- Shows file name and language
- Free
Cons
- Extra step to create
- Preview depends on platform
- Link takes user away
Solution 3: Code + Context as Image
For longer explanations with code, use a Markdown-to-image tool like MDConvrt.
## The Problem
The original code had a bug:
\`\`\`javascript
// Wrong
const data = fetch(url);
\`\`\`
## The Fix
We need to await the promise:
\`\`\`javascript
// Correct
const data = await fetch(url);
\`\`\`
This gives you formatted text AND code in one image.
Platform Tips
Twitter/X
- Images get more engagement
- Alt text is important (describe what the code does)
- Thread format for longer explanations
- Link to full code in replies
- Professional context matters
- Explain why the code is interesting
- Tag relevant people/companies
- Use images, but keep it business-appropriate
Code Sharing Etiquette
- Explain what it does: Not everyone can read code at a glance
- Credit sources: If it's not your code, say so
- Don't share secrets: No API keys, passwords, internal logic
- Provide context: Why is this interesting/useful?
- Be ready to explain: People will have questions
My Workflow
- Write the code explanation in Markdown
- Include the code block
- Convert to image with Ray.so (just code) or MDConvrt (code + explanation)
- Post with context in the caption
- Link to full code if available
It takes 30 seconds longer to make your code look good. Worth it.
Try it with your own content
Open Code to Image, edit the example, and check your preview.