HomeAbout

Reusable SharePoint CSS classes

By Denis Molodtsov
Published in SharePoint
April 02, 2024
1 min read
Reusable SharePoint CSS classes

Table Of Contents

01
Introduction
02
How do I use these CSS classes?
03
Conclusion

Introduction

Hi, fellow SharePoint developers and power users! 🤓

Are you working with the SharePoint Framework (SPFx), or must you style SharePoint lists with JSON formatting? Then you might want to know that there is a collection of all reusable CSS classes available on a single page: https://zerg00s.github.io/sp-modern-classes

SharePoint

How do I use these CSS classes?

Column formatting, view formatting, form formatting

You can use column and view formatting to customize how fields in SharePoint lists and libraries are displayed. To do this, you construct a JSON object that describes the elements that are displayed when a field is included in a list view, and the styles to be applied to those elements.

Sample JSON formatting for a SharePoint Title field:

  • Format a column

alt text
alt text

  • Advanced mode

alt text
alt text

  • Apply a sample sp-field-dataBars CSS class to the Title field:
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "div",
"txtContent": "@currentField",
"attributes": {
"class": "sp-field-dataBars"
}
}

alt text
alt text

  • Result:

alt text
alt text

Read more on JSON formatting:

SPFx Webparts

In SPFx web parts, you can reuse the classes by using the className attribute. For example, to apply a border to a field, you can use the sp-field-borderAllDashed class:

<div className={`sp-field-dataBars sp-field-borderAllDashed`}>

Conclusion

I hope you find this collection of reusable CSS classes helpful. If you have any questions or suggestions, please leave a comment below. 🙏


Tags

SharePointCSSStylesSPFxJSON formatting

Share

Previous Article
Beautiful Power BI Backgrounds
Denis Molodtsov

Denis Molodtsov

Microsoft 365 Architect

Related Posts

Archive SharePoint Online Sites Using M365 Archive Feature
Archive SharePoint Online Sites Using M365 Archive Feature
April 02, 2024
4 min

Quick Links

About

Social Media