SharePoint Online Code Snippet Web Part

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.

Code Snippet Web Part in SharePoint Online

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.
Code Snippet Web Part in SharePoint
  • In the Edit mode, click the + icon to add a new web part in column one.
SharePoint Code Snippet Web Part
  • Select a Code Snippet web part under Advanced.
Add SharePoint Code Snippet Web Part
  • The screenshot below shows that the code snippet web part has been added.
How to add code snippet web part in SharePoint

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.
Add Code Snippet Web Part in SharePoint
  • For Example, I have written a code in Java for How to add two integers.
Customization of Code Snippet Web Part in SharePoint Online

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.

  1. 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).
Code Snippet Web Part in SharePoint Online Page
Code Snippet Web Part in SharePoint Online Page

2. Unnumbered lines:

  • Expand and select Unnumbered lines -> the code will start directly without listing the number before the code.
Code Snippet Web Part Customization in SharePoint

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.
How to customize 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.
Code Snippet Web Part Customization in SharePoint

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.
Customize SharePoint Online Code Snippet Web Part
Customize SharePoint Online Code Snippet Web Part
  • 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.
Code Snippet Web Part Customize in SharePoint
Code Snippet Web Part Customize in SharePoint
  • Slide the toggle toward Off, under Line wrap -> Click on Republish.
SharePoint Online Code Snippet Web Part
SharePoint Online Code Snippet Web Part
  • Once we Off the Line wrap, it does not change the line to make each line fits into the viewable window.
How SharePoint Online Code Snippet Web Part Customize
How SharePoint Online Code Snippet Web Part Customize

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: