| sidebar_label | defaultStyles |
|---|---|
| title | defaultStyles Config |
| description | Explore the defaultStyles configuration in the DHTMLX JavaScript RichText library documentation. Find developer guides, API references, try code samples and live demos, and download a free 30-day trial of DHTMLX RichText. |
@short: Optional. Defines default style settings for specific block types.
defaultStyles?: {
"*"?: { // applies to all blocks, letting you set common properties for all of them
"font-family"?: string; // "Roboto"| "Arial" | "Georgia" | "Tahoma" | "Times New Roman" | "Verdana"
"font-size"?: string; // "12px" | "14px" | "16px" | "18px" | "20px" | "24px" | "28px" | "32px" | "36px"
color?: string;
background?: string;
},
p?: {
"font-family"?: string; // "Roboto"| "Arial" | "Georgia" | "Tahoma" | "Times New Roman" | "Verdana"
"font-size"?: string; // "12px" | "14px" | "16px" | "18px" | "20px" | "24px" | "28px" | "32px" | "36px"
color?: string;
background?: string;
},
blockquote?: {
"font-family"?: string; // "Roboto"| "Arial" | "Georgia" | "Tahoma" | "Times New Roman" | "Verdana"
"font-size"?: string; // "12px" | "14px" | "16px" | "18px" | "20px" | "24px" | "28px" | "32px" | "36px"
color?: string;
background?: string;
},
h1?: {
"font-family"?: string; // "Roboto"| "Arial" | "Georgia" | "Tahoma" | "Times New Roman" | "Verdana"
"font-size"?: string; // "12px" | "14px" | "16px" | "18px" | "20px" | "24px" | "28px" | "32px" | "36px"
color?: string;
background?: string;
},
h2?: {
"font-family"?: string; // "Roboto"| "Arial" | "Georgia" | "Tahoma" | "Times New Roman" | "Verdana"
"font-size"?: string; // "12px" | "14px" | "16px" | "18px" | "20px" | "24px" | "28px" | "32px" | "36px"
color?: string;
background?: string;
},
h3?: {
"font-family"?: string; // "Roboto"| "Arial" | "Georgia" | "Tahoma" | "Times New Roman" | "Verdana"
"font-size"?: string; // "12px" | "14px" | "16px" | "18px" | "20px" | "24px" | "28px" | "32px" | "36px"
color?: string;
background?: string;
},
h4?: {
"font-family"?: string; // "Roboto"| "Arial" | "Georgia" | "Tahoma" | "Times New Roman" | "Verdana"
"font-size"?: string; // "12px" | "14px" | "16px" | "18px" | "20px" | "24px" | "28px" | "32px" | "36px"
color?: string;
background?: string;
},
h5?: {
"font-family"?: string; // "Roboto"| "Arial" | "Georgia" | "Tahoma" | "Times New Roman" | "Verdana"
"font-size"?: string; // "12px" | "14px" | "16px" | "18px" | "20px" | "24px" | "28px" | "32px" | "36px"
color?: string;
background?: string;
},
h6?: {
"font-family"?: string; // "Roboto"| "Arial" | "Georgia" | "Tahoma" | "Times New Roman" | "Verdana"
"font-size"?: string; // "12px" | "14px" | "16px" | "18px" | "20px" | "24px" | "28px" | "32px" | "36px"
color?: string;
background?: string;
}
};:::important
The defaultStyles property doesn't actually apply CSS styles to the blocks. To see the styles take effect, you need to add the corresponding CSS separately:
new richtext.Richtext("#root", {
defaultStyles: {
h2: {
"font-family": "Roboto",
"font-size": "28px",
color: "purple",
background: "#FFC0CB"
}
}
});<style>
#root h2 {
font-family: Roboto;
font-size: 28px;
color: purple;
background: #FFC0CB;
}
</style>In this example, every h2 block is set to use the "Roboto" font-family with a font size of 28px, along with changes to the text and background colors. The CSS styles for h2 blocks are also applied accordingly.
:::
const defaultStyles = {
"*": { "font-family": "Arial" },
p: { "font-size": "14px" },
blockquote: { "font-size": "14px" },
h1: { "font-size": "32px" },
h2: { "font-size": "24px" },
h3: { "font-size": "18px" },
h4: { "font-size": "16px" },
h5: { "font-size": "14px" },
h6: { "font-size": "12px" }
};// initialize RichText
new richtext.Richtext("#root", {
defaultStyles: {
h4: {
"font-family": "Roboto"
},
h5: {
"font-family": "Roboto"
},
h6: {
"font-family": "Roboto"
}
},
// other configuration properties
});Change log: This property was updated in version 2.0
Related articles: Configuration
Related sample: RichText. Changing the default value for typography (font, font size, etc.)