iTranslated by AI
Step-by-Step Guide to Implementing Syntax Highlighting in Gatsby
This is quite old, so it might not be very helpful.
Honestly, you're better off asking ChatGPT to help you make it.
2026-02-08 Sotono
Enabling Syntax Highlighting on Gatsby
If you are using gatsby-starter-blog,
it is available for use without any extra configuration.
You might want to at least read sections 4. and 5..
1. Install the following modules
prismjsgatsby-remark-prismjsgatsby-remark-prismjs-title
npm install -S prismjs gatsby-remark-prismjs gatsby-remark-prismjs-title
2. Rewriting gatsby-config.js
*Note: This step can be skipped if you are using gatsby-starter-blog.
resolve: `gatsby-transformer-remark`,
options: {
plugins: [
`gatsby-remark-prismjs-title`,
`gatsby-remark-prismjs`,
]
},
3. Rewriting gatsby-browser.js
Configure it with your preferred theme by referring to Prism.
For example, if you want the default theme:
// Highlighting for code blocks
import "prismjs/themes/prism.css"
If you want to apply Tomorrownight, for instance:
// Highlighting for code blocks
import "prismjs/themes/prism-tomorrow.css"
It would look something like that.
4. Adding a Title to the Highlight
If you have configured everything correctly so far,
this
python:title=aiueo
will become like this when you run gatsby develop.
<div class="gatsby-code-title">
<span>aiueo</span>
</div>
Now, let's set up the style sheet for this.
You can modify any CSS file you are importing.
In this case, everything is put into style.css, so I will write it here.
Feel free to modify this to match your theme.
.gatsby-code-title {
background: #F5F2F0;
color: #000;
font-family: Consolas, Monaco, "Andale Mono", "Ubuntu Mono", monospace;
margin: 20px 0px -24px;
padding: 8px 1rem 20px;
font: size 1em;
line-height: 1;
display: table;
}
5. Tips for When the Article is... Not Highlighted
Q. I should have set everything correctly, but the syntax highlighting isn't working...
A. It's possible that your Markdown syntax is incorrect.
For example,
python :aiueo
In this case, neither the title nor the syntax highlighting will appear.
python:title=aiueo
Use this instead.
The trick is to not insert a space after the language you want to highlight.
Completion

References
Applying Syntax Highlighting to a Blog Made with GatsbyJS - Kikunantoka.com
Adding Titles and Line Highlighting to Code Blocks in a GatsbyJS Blog - Nofunofurogu
Discussion