Skip to content

Commit 820c763

Browse files
docs: update Office UI Fabric refs to Fluent UI and refresh library c… (#10735)
* docs: update Office UI Fabric refs to Fluent UI and refresh library component overview * docs: fix formatting, style, and terminology across SPFx articles - remove extra `<br/>` tags and blank lines in css-recommendations.md - promote H4 code example headings to H3 for proper hierarchy - fix "Can I use__?" link text to "Can I use?" - flatten nested folder tree for readability - bold first-column entries in permission-style tables - fix "typescript" casing to "TypeScript" - update "Azure Active Directory" to "Entra ID" - fix "webpart" to "web part" in fluent-ui-integration.md - replace "alternative" with "alternate" in library-component-overview.md --------- Co-authored-by: Andrew Connell <me@andrewconnell.com>
1 parent 91e96c6 commit 820c763

5 files changed

Lines changed: 414 additions & 394 deletions

File tree

docs/spfx/css-recommendations.md

Lines changed: 21 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,41 @@
11
---
22
title: Recommendations for working with CSS in SharePoint Framework solutions
33
description: Use CSS to define how your SharePoint Framework customization should look and behave.
4-
ms.date: 03/08/2023
4+
ms.date: 03/23/2026
55
ms.localizationpriority: high
66
---
7-
8-
97
# Recommendations for working with CSS in SharePoint Framework solutions
108

119
When building SharePoint Framework solutions, you can use CSS to define how your customization should look and behave. This article describes how you can make the best use of the capabilities provided with the SharePoint Framework and build your CSS styles in a robust way.
1210

1311
## SharePoint Framework customizations are part of the page
1412

15-
When building SharePoint customizations using the add-in model, the solution is isolated from other elements on the page. Your code can be executed in an `<iframe>` as an add-in part, or as an immersive application that takes control of the whole page. In both cases, your code is not affected by other elements and styles defined on the page.
13+
When building SharePoint customizations using the add-in model, the solution is isolated from other elements on the page. Your code can be executed in an `iframe` as an add-in part, or as an immersive application that takes control of the whole page. In both cases, your code isn't affected by other elements and styles defined on the page.
1614

17-
SharePoint Framework solutions are a part of the page and integrate fully with the page's DOM. While this removes a number of restrictions that come with the add-in model, it exposes your solution to risk. Because it's a part of the page, unless explicitly isolated, all CSS styles present on the page apply to it, potentially resulting in an experience different from what you intended. To avoid such risks, you should define your CSS styles in such a way so that they won't affect anything else on the page other than your customization.
15+
SharePoint Framework solutions are a part of the page and integrate fully with the page's DOM. While this removes many restrictions that come with the add-in model, it exposes your solution to risk. Because it's a part of the page, unless explicitly isolated, all CSS styles present on the page apply to it, potentially resulting in an experience different from what you intended. To avoid such risks, you should define your CSS styles in such a way so that they won't affect anything else on the page other than your customization.
1816

1917
## Organize CSS files in your solution
2018

2119
The UI of your solutions often consists of multiple building blocks. In many JavaScript libraries, these building blocks are called components. A component can be simple and define only the presentation, or it can be more complex and include state and other components. Splitting your solution into multiple components allows you to simplify the development process and makes it easier to test and reuse the components in your solution.
2220

23-
Because components have presentation, they often require CSS styles. Ideally, components should be isolated and be able to be used on their own. With that in mind, it makes perfect sense for you to store CSS styles for the particular component along with all other asset files next to the component. Following is a sample structure of a React application with a number of components, each with its own CSS file.
21+
Because components have presentation, they often require CSS styles. Ideally, components should be isolated and be able to be used on their own. With that in mind, it makes perfect sense for you to store CSS styles for the particular component along with all other asset files next to the component. Following is a sample structure of a React application with many components, each with its own CSS file.
2422

2523
```text
26-
todoWebPart\components
27-
\todoList
28-
\todoList.tsx
24+
todoWebPart\components\todoList\todoList.tsx
2925
\todoList.module.scss
30-
\todoItem
31-
\todoItem.tsx
26+
\todoItem\todoItem.tsx
3227
\todoItem.module.scss
3328
```
3429

3530
## Use Sass
3631

37-
In SharePoint Framework, you can use both CSS and Sass. Sass is a superset of CSS and offers you a number of features such as variables, nesting selectors, or mixins, all of which simplify working with and managing CSS styles over the long term.
32+
In SharePoint Framework, you can use both CSS and Sass. Sass is a superset of CSS and offers you many features such as variables, nesting selectors, or mixins, all of which simplify working with and managing CSS styles over the long term.
3833

39-
For a complete set of features, see the [Sass website](http://sass-lang.com). All valid CSS is also valid Sass, which is very helpful if you haven't worked with Sass before and want to gradually learn its capabilities.
34+
For a complete set of features, see the [Sass website](http://sass-lang.com). All valid CSS is also valid Sass, which is helpful if you haven't worked with Sass before and want to gradually learn its capabilities.
4035

4136
## Avoid using IDs in markup
4237

43-
Using SharePoint Framework, you build customizations that end-users add to SharePoint. It's impossible to tell upfront if the particular customization is used only once on a page or if there are multiple instances of it.
38+
Using SharePoint Framework, you build customizations that end users add to SharePoint. It's impossible to tell upfront if the particular customization is used only once on a page or if there are multiple instances of it.
4439

4540
To avoid issues, you should always assume that there are multiple instances of your customization on the same page. With that in mind, you should avoid using any IDs in your markup. IDs are meant to be unique on a page, and if a user adds your web part to the page twice, it violates this premise, possibly leading to errors.
4641

@@ -62,8 +57,6 @@ export default class HelloWorldWebPart extends BaseClientSideWebPart<IHelloWorld
6257
}
6358
```
6459

65-
<br/>
66-
6760
#### Good practice
6861

6962
```typescript
@@ -90,7 +83,7 @@ To help you avoid styling conflicts, SharePoint Framework uses [CSS modules](htt
9083

9184
Following the previous example, assume that you had the following two Sass files:
9285

93-
#### todoList.module.scss
86+
### todoList.module.scss
9487

9588
```scss
9689
.todoList {
@@ -103,9 +96,7 @@ Following the previous example, assume that you had the following two Sass files
10396
}
10497
```
10598

106-
<br/>
107-
108-
#### todoItem.module.scss
99+
### todoItem.module.scss
109100

110101
```scss
111102
.todoItem {
@@ -117,11 +108,9 @@ Following the previous example, assume that you had the following two Sass files
117108
}
118109
```
119110

120-
<br/>
121-
122111
After building the project, in the **lib** folder you would see the following two CSS files generated (line breaks and indenting added for readability):
123112

124-
#### todoList.module.css
113+
### todoList.module.css
125114

126115
```css
127116
.todoList_3e9d35f0 {
@@ -134,9 +123,7 @@ After building the project, in the **lib** folder you would see the following tw
134123
}
135124
```
136125

137-
<br/>
138-
139-
#### todoItem.module.css
126+
### todoItem.module.css
140127

141128
```css
142129
.todoItem_f7081cc4 {
@@ -148,13 +135,11 @@ After building the project, in the **lib** folder you would see the following tw
148135
}
149136
```
150137

151-
<br/>
152-
153-
Even though there was a **.text** class defined in both Sass files, notice how in the generated CSS files it has two different hashes appended to it, becoming a unique class name specific to each component.
138+
Even though there was a `.text` class defined in both Sass files, notice how in the generated CSS files it has two different hashes appended to it, becoming a unique class name specific to each component.
154139

155140
The CSS class names in CSS modules are generated dynamically, which makes it impossible for you to refer to them in your code directly. Instead, when processing CSS modules, the SharePoint Framework toolchain generates a JavaScript file with references to the generated class names.
156141

157-
#### todoList.module.scss.js
142+
### todoList.module.scss.js
158143

159144
```javascript
160145
"use strict";
@@ -171,8 +156,6 @@ exports.default = styles;
171156
//# sourceMappingURL=todoList.module.scss.js.map
172157
```
173158

174-
<br/>
175-
176159
To use the generated class names in your code, you first import the styles of your component, and then use the property pointing to the particular class:
177160

178161
```typescript
@@ -190,8 +173,6 @@ export default class TodoList extends React.Component<ITodoListProps, void> {
190173
}
191174
```
192175

193-
<br/>
194-
195176
For the CSS modules to work correctly, you have to meet the following conditions:
196177

197178
* Your Sass files must have the **.module.scss** extension. If you use the **.scss** extension without **.module**, you see a warning in the build process. The Sass file is transpiled to an intermediate CSS file, but the class names *will not be made unique*. In cases when you need to override third-party CSS styles, this might be intended.
@@ -206,7 +187,7 @@ By combining CSS modules with Sass support for nesting rule sets, you can simpli
206187

207188
When building CSS styles for a component, wrap them in a class named after the component. In the component, assign that class to the component's root element.
208189

209-
#### todoList.module.scss
190+
### todoList.module.scss
210191

211192
```scss
212193
.todoList {
@@ -216,9 +197,7 @@ When building CSS styles for a component, wrap them in a class named after the c
216197
}
217198
```
218199

219-
<br/>
220-
221-
#### TodoList.tsx
200+
### TodoList.tsx
222201

223202
```tsx
224203
// ...
@@ -234,8 +213,6 @@ export default class TodoList extends React.Component<ITodoListProps, void> {
234213
}
235214
```
236215

237-
<br/>
238-
239216
After transpilation, the generated CSS file looks similar to:
240217

241218
```css
@@ -258,8 +235,6 @@ In case a web part should use the new flex box model defined by the `display: fl
258235
}
259236
```
260237

261-
<br/>
262-
263238
The Sass code of the SharePoint Framework artefact does not need to have vendor prefixes included. After the Sass-to-CSS compilation, those were added automatically, resulting in the following CSS declaration.
264239

265240
```css
@@ -270,8 +245,6 @@ The Sass code of the SharePoint Framework artefact does not need to have vendor
270245
}
271246
```
272247

273-
<br/>
274-
275248
Removing already applied prefixes does not only make the code of the artefact cleaner, it also makes it easier to read and future-ready. This process is also configured to support only SharePoint Framework-supported browsers and makes it more error-safe.
276249

277250
In case a web part already has vendor prefixes included in the Sass files that are not needed anymore, the same process removes those declarations automatically.
@@ -289,8 +262,6 @@ The following example makes use of the `border-radius` property, which does not
289262
}
290263
```
291264

292-
<br/>
293-
294265
The resulting CSS in the package is converted to the following code.
295266

296267
```css
@@ -299,13 +270,13 @@ The resulting CSS in the package is converted to the following code.
299270
}
300271
```
301272

302-
For more information about auto-prefixing, see the [autoprefixer](https://github.com/postcss/autoprefixer) GitHub repository. The database for this process is available on [Can I use__?](https://caniuse.com).
273+
For more information about auto-prefixing, see the [autoprefixer](https://github.com/postcss/autoprefixer) GitHub repository. The database for this process is available on [Can I use?](https://caniuse.com).
303274

304-
## Integrate Office UI Fabric
275+
## Integrate Fluent UI
305276

306-
By making your customizations look and behave like the standard functionality of SharePoint and Office 365, you make it easier for end-users to work with them. Office UI Fabric offers you a set of controls and styles to use in your customizations to seamlessly integrate with the existing user experience.
277+
By making your customizations look and behave like the standard functionality of SharePoint and Microsoft 365, you make it easier for end users to work with them. Fluent UI (formerly Office UI Fabric) offers you a set of controls and styles to use in your customizations to seamlessly integrate with the existing user experience.
307278

308-
For more information about using Office UI Fabric in SharePoint Framework, see [Using Office UI Fabric Core and Fabric React in SharePoint Framework](./office-ui-fabric-integration.md).
279+
For more information about using Fluent UI in SharePoint Framework, see [Using Fluent UI in SharePoint Framework](./fluent-ui-integration.md).
309280

310281
## Use theme colors
311282

0 commit comments

Comments
 (0)