This SharePoint tutorial explains everything about SharePoint Online Code Snippet Web Part. I will show how to use the code snippet web part in SharePoint.
We can add various code snippets to a SharePoint site page using the code snippet web part in SharePoint Online. Like, you can add we can add code using various languages like C, C++, C#, Java, Python, HTML, etc.
Code Snippet Web Part in SharePoint Online
The Code snippet web part in SharePoint is used to display code as text on your page for others to use or learn from the Code snippet web part in SharePoint Online. In this SharePoint Online web part, dark and light themes are available to display the code. And also, the web part even auto-corrects the syntax.
For Example, I have written a code to add two integers and will implement it in SharePoint Online Code Snippet Web Part.

Now, let us see how to add the SharePoint Online code snippet web part to a site page.
- Open a SharePoint Online site page -> Click on Edit.

- In the Edit mode, click the + icon to add a new web part in column one.

- Select a Code Snippet web part under Advanced.

- The screenshot below shows that the code snippet web part has been added.

This is how we can add a SharePoint Online code snippet web part.
SharePoint Online Code Snipped Web Part Customization
In this part, we will learn how to customize SharePoint Online code snippet web parts like the selection of language, change of numbered lines, change of theme, and On/Off line wrap.
Selection of Language
- Select the language to write the code. I have chosen Java. If you want, you can select the language as per the requirement.

- For Example, I have written a code in Java for How to add two integers.

You can select the language as needed and write code for it in the SharePoint Online Code snippet web part.
Change Numbered Lines
In this part, we will learn how to Numbered and Unnumbered lines for the code written in the SharePoint Online code snippet web part.
- Numbered lines:
- Expand and select Numbered lines, then you can see at the start of the code it should be numbered (like 1, 2, 3).

2. Unnumbered lines:
- Expand and select Unnumbered lines -> the code will start directly without listing the number before the code.

This is how we can change the numbered line in SharePoint’s code snippet web part.
Change of theme
In this section, we can select a theme, such as a Light or Dark theme, in the SharePoint Online code snippet web part.
- Expand the theme -> Selected the Light theme -> Now, the background becomes light in color in SharePoint Code Snippet Web Part.

- In the below screenshot, I have selected the dark theme, the background of our code will change to dark in the code snippet web part in SharePoint Online.

This is how we can change the theme of the SharePoint code snippet web part.
On/Off Line Wrap
This section explains what happens when On/Off the line wrap in the SharePoint code snippet web part.
- Slide the toggle toward On, under Line wrap -> Click on Republish.

- Once we On the Line wrap, you will see the line is completed, then it changes the line so that each line fits into the viewable window.

- Slide the toggle toward Off, under Line wrap -> Click on Republish.

- Once we Off the Line wrap, it does not change the line to make each line fits into the viewable window.

This is how On/Off Line wrap works in SharePoint’s code snippet web part.
Conclusion
I hope from this SharePoint Online tutorial, we have explained everything about the SharePoint Online code snippet web part like what is SharePoint online code snippet web part.
Moreover, we have covered how to add a SharePoint code snippet web part. And also, we have learned how to customize the SharePoint Online code snippet web part.
You may like the following tutorials:
- SharePoint Online Page Properties Web Part
- Recent Documents Web Part in SharePoint Online
- Organization Chart Web Part in SharePoint Online
- File and Media Web Part in SharePoint Online

Preeti Sahu is an expert in Power Apps and has more than 6 years of experience working with SharePoint and the Power Platform. As a Power Platform expert for Power BI, Power Apps, Power Automate, Power Virtual Agents, and Power Pages, she is currently employed with TSinfo Technologies. She is the author of the book Microsoft Power Platform A Deep Dive. She also made a big technical contribution to SharePointDotNet.com in the form of articles on the Power Platform. She enjoys traveling and spending time with her family in her spare time.