Introduction
CssBaseline is a component that kickstarts an elegant, consistent, and simple baseline to build upon. It applies a set of opinionated CSS resets and normalizations to provide a solid foundation for your application.Basic Usage
What It Does
CssBaseline applies the following resets and normalizations:HTML Element
- Sets
box-sizing: border-boxglobally - Removes default margin on the body
- Applies antialiasing for smoother font rendering:
WebkitFontSmoothing: antialiasedMozOsxFontSmoothing: grayscale
- Fixes font resize problem in iOS with
WebkitTextSizeAdjust: 100%
Body Element
- Sets default text color from theme:
theme.palette.text.primary - Sets default background color:
theme.palette.background.default - Applies default typography:
theme.typography.body1 - Sets background to white for print media
- Adds
::backdropsupport for fullscreen mode
Typography
- Sets
fontWeight: theme.typography.fontWeightBoldfor<strong>and<b>elements - Ensures consistent box-sizing with
*, *::before, *::after { boxSizing: inherit }
Props
children
- Type:
React.ReactNode - Default:
undefined
enableColorScheme
- Type:
boolean - Default:
false
color-scheme CSS property to use theme.palette.mode. This allows the browser to apply appropriate styles for light/dark modes.
Usage with Theme
Global Overrides
You can customize the baseline styles using the theme:With Custom Fonts
Color Scheme Support
When using theenableColorScheme prop with theme color schemes:
color-scheme property, which:
- Tells the browser which color scheme the page is designed for
- Allows native form controls and scrollbars to adapt to the color scheme
- Ensures appropriate default colors for browser UI elements
Scoping to a Subtree
You can scope the baseline to a specific part of your application:Alternative: GlobalStyles
If you need more control over global styles, consider using theGlobalStyles component instead:
Server-Side Rendering
CssBaseline works seamlessly with server-side rendering. Place it at the root of your application:Best Practices
- Place at the root: Include CssBaseline at the root of your component tree
- Single instance: You typically only need one CssBaseline component
- Before content: Render CssBaseline before your main content components
- With ThemeProvider: Always use within a ThemeProvider for consistent theming