Skip to content
Code & terminal

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

  1. Paste your code
  2. Select language for syntax highlighting
  3. Choose a theme
  4. 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.

markdown
## 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

LinkedIn

  • Professional context matters
  • Explain why the code is interesting
  • Tag relevant people/companies
  • Use images, but keep it business-appropriate

Code Sharing Etiquette

  1. Explain what it does: Not everyone can read code at a glance
  2. Credit sources: If it's not your code, say so
  3. Don't share secrets: No API keys, passwords, internal logic
  4. Provide context: Why is this interesting/useful?
  5. Be ready to explain: People will have questions

My Workflow

  1. Write the code explanation in Markdown
  2. Include the code block
  3. Convert to image with Ray.so (just code) or MDConvrt (code + explanation)
  4. Post with context in the caption
  5. 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.

Open Code to Image
Best Carbon.now.sh Alternatives for Developers in 2026How to Turn Terminal Output into Beautiful Shareable ImagesHow to Convert Mermaid Diagrams to Images (The Developer-Friendly Way)