DEV Community

doldoki
doldoki

Posted on

1

Add color to your code block

So you started a blog on dev.to but when you wrote your code in a code block, you noticed this.

let str = 'Hello World';
console.log(str);
Enter fullscreen mode Exit fullscreen mode

Fortunately, dev.to offers an easy way to add colors to your codes for better display and readability.

let str = 'Hello World';
console.log(str);
Enter fullscreen mode Exit fullscreen mode

Simply add the name of your programming language right after the first three back-ticks(or the opening back-ticks) for your code block.

I tried Python, Javascript, and PHP. They all worked fine.

Top comments (5)

Collapse
 
suyashdev profile image
Suyash Vashishtha

Can you please comment the code for the same ...bcz it is not working for mine . raw SS would do fine....

Collapse
 
_moehab profile image
Mahmoud Ehab

alt

Collapse
 
suyashdev profile image
Suyash Vashishtha

Okk so I found out it only takes native language code...anything for frameworks like React js ?

Thread Thread
 
_moehab profile image
Mahmoud Ehab

It should work in ReactJS code (JSX Components) as well. It does in npmjs.com.
If there's no way to make it works in JSX tags as well here, so I guess dev community developers should use another libarary for rendering md files.

Thread Thread
 
suyashdev profile image
Suyash Vashishtha • Edited

Finally I found a way ..

 const [state, setState]= useState(0);
Enter fullscreen mode Exit fullscreen mode

This coloring can be achieved like this... It doesn't work without div tho.

code

The Most Contextual AI Development Assistant

Pieces.app image

Our centralized storage agent works on-device, unifying various developer tools to proactively capture and enrich useful materials, streamline collaboration, and solve complex problems through a contextual understanding of your unique workflow.

👥 Ideal for solo developers, teams, and cross-company projects

Learn more

👋 Kindness is contagious

Engage with a wealth of insights in this thoughtful article, valued within the supportive DEV Community. Coders of every background are welcome to join in and add to our collective wisdom.

A sincere "thank you" often brightens someone’s day. Share your gratitude in the comments below!

On DEV, the act of sharing knowledge eases our journey and fortifies our community ties. Found value in this? A quick thank you to the author can make a significant impact.

Okay