|
| 1 | +--- |
| 2 | +sidebar_label: defaultStyles |
| 3 | +title: defaultStyles Config |
| 4 | +description: You can learn about the defaultStyles config in the documentation of the DHTMLX JavaScript RichText library. Browse developer guides and API reference, try out code examples and live demos, and download a free 30-day evaluation version of DHTMLX RichText. |
| 5 | +--- |
| 6 | + |
| 7 | +# defaultStyles |
| 8 | + |
| 9 | +### Description |
| 10 | + |
| 11 | +@short: Optional. Specifies default style values for specific block types |
| 12 | + |
| 13 | +### Usage |
| 14 | + |
| 15 | +~~~jsx {} |
| 16 | +defaultStyles?: { |
| 17 | + "*"?: { // affects all blocks, allowing you to set common properties for all of these blocks |
| 18 | + "font-family"?: string; // "Roboto"| "Arial" | "Georgia" | "Tahoma" | "Times New Roman" | "Verdana" |
| 19 | + "font-size"?: string; // "12px" | "14px" | "16px" | "18px" | "20px" | "24px" | "28px" | "32px" | "36px" |
| 20 | + color?: string; |
| 21 | + background?: string; |
| 22 | + }, |
| 23 | + p?: { |
| 24 | + "font-family"?: string; // "Roboto"| "Arial" | "Georgia" | "Tahoma" | "Times New Roman" | "Verdana" |
| 25 | + "font-size"?: string; // "12px" | "14px" | "16px" | "18px" | "20px" | "24px" | "28px" | "32px" | "36px" |
| 26 | + color?: string; |
| 27 | + background?: string; |
| 28 | + }, |
| 29 | + blockquote?: { |
| 30 | + "font-family"?: string; // "Roboto"| "Arial" | "Georgia" | "Tahoma" | "Times New Roman" | "Verdana" |
| 31 | + "font-size"?: string; // "12px" | "14px" | "16px" | "18px" | "20px" | "24px" | "28px" | "32px" | "36px" |
| 32 | + color?: string; |
| 33 | + background?: string; |
| 34 | + }, |
| 35 | + h1?: { |
| 36 | + "font-family"?: string; // "Roboto"| "Arial" | "Georgia" | "Tahoma" | "Times New Roman" | "Verdana" |
| 37 | + "font-size"?: string; // "12px" | "14px" | "16px" | "18px" | "20px" | "24px" | "28px" | "32px" | "36px" |
| 38 | + color?: string; |
| 39 | + background?: string; |
| 40 | + }, |
| 41 | + h2?: { |
| 42 | + "font-family"?: string; // "Roboto"| "Arial" | "Georgia" | "Tahoma" | "Times New Roman" | "Verdana" |
| 43 | + "font-size"?: string; // "12px" | "14px" | "16px" | "18px" | "20px" | "24px" | "28px" | "32px" | "36px" |
| 44 | + color?: string; |
| 45 | + background?: string; |
| 46 | + }, |
| 47 | + h3?: { |
| 48 | + "font-family"?: string; // "Roboto"| "Arial" | "Georgia" | "Tahoma" | "Times New Roman" | "Verdana" |
| 49 | + "font-size"?: string; // "12px" | "14px" | "16px" | "18px" | "20px" | "24px" | "28px" | "32px" | "36px" |
| 50 | + color?: string; |
| 51 | + background?: string; |
| 52 | + }, |
| 53 | + h4?: { |
| 54 | + "font-family"?: string; // "Roboto"| "Arial" | "Georgia" | "Tahoma" | "Times New Roman" | "Verdana" |
| 55 | + "font-size"?: string; // "12px" | "14px" | "16px" | "18px" | "20px" | "24px" | "28px" | "32px" | "36px" |
| 56 | + color?: string; |
| 57 | + background?: string; |
| 58 | + }, |
| 59 | + h5?: { |
| 60 | + "font-family"?: string; // "Roboto"| "Arial" | "Georgia" | "Tahoma" | "Times New Roman" | "Verdana" |
| 61 | + "font-size"?: string; // "12px" | "14px" | "16px" | "18px" | "20px" | "24px" | "28px" | "32px" | "36px" |
| 62 | + color?: string; |
| 63 | + background?: string; |
| 64 | + }, |
| 65 | + h6?: { |
| 66 | + "font-family"?: string; // "Roboto"| "Arial" | "Georgia" | "Tahoma" | "Times New Roman" | "Verdana" |
| 67 | + "font-size"?: string; // "12px" | "14px" | "16px" | "18px" | "20px" | "24px" | "28px" | "32px" | "36px" |
| 68 | + color?: string; |
| 69 | + background?: string; |
| 70 | + } |
| 71 | +}; |
| 72 | +~~~ |
| 73 | + |
| 74 | +:::important |
| 75 | +The `defaultStyles` property DOES NOT set the actual CSS to the affected blocks. CSS styles have to be applied separately: |
| 76 | + |
| 77 | +```jsx title="index.js" |
| 78 | +new richtext.Richtext("#root", { |
| 79 | + defaultStyles: { |
| 80 | + h2: { |
| 81 | + "font-family": "Roboto", |
| 82 | + "font-size": "28px", |
| 83 | + color: "purple", |
| 84 | + background: "#FFC0CB" |
| 85 | + } |
| 86 | + } |
| 87 | +}); |
| 88 | +``` |
| 89 | + |
| 90 | +```css title="index.css" |
| 91 | +<style> |
| 92 | + #root h2 { |
| 93 | + font-family: Roboto; |
| 94 | + font-size: 28px; |
| 95 | + color: purple; |
| 96 | + background: #FFC0CB; |
| 97 | + } |
| 98 | +</style> |
| 99 | +``` |
| 100 | + |
| 101 | +In this example, all `h2` blocks are assigned to the `"Roboto"` font-family with a font-size of 28px with both the foreground and the background colors changed as well. Css styles assigned to `h2` blocks as well. |
| 102 | +::: |
| 103 | + |
| 104 | +### Default config |
| 105 | + |
| 106 | +~~~jsx |
| 107 | +const defaultStyles = { |
| 108 | + "*": { "font-family": "Arial" }, |
| 109 | + p: { "font-size": "14px" }, |
| 110 | + blockquote: { "font-size": "14px" }, |
| 111 | + h1: { "font-size": "32px" }, |
| 112 | + h2: { "font-size": "24px" }, |
| 113 | + h3: { "font-size": "18px" }, |
| 114 | + h4: { "font-size": "16px" }, |
| 115 | + h5: { "font-size": "14px" }, |
| 116 | + h6: { "font-size": "12px" } |
| 117 | +}; |
| 118 | +~~~ |
| 119 | + |
| 120 | +### Example |
| 121 | + |
| 122 | +~~~jsx {3-13} |
| 123 | +// initialize RichText |
| 124 | +new richtext.Richtext("#root", { |
| 125 | + defaultStyles: { |
| 126 | + h4: { |
| 127 | + "font-family": "Roboto" |
| 128 | + }, |
| 129 | + h5: { |
| 130 | + "font-family": "Roboto" |
| 131 | + }, |
| 132 | + h6: { |
| 133 | + "font-family": "Roboto" |
| 134 | + } |
| 135 | + }, |
| 136 | + // other configuration properties |
| 137 | +}); |
| 138 | +~~~ |
| 139 | + |
| 140 | +**Change log:** The property was updated in v2.0 |
| 141 | + |
| 142 | +**Related articles:** [Configuration](guides/configuration.md) |
| 143 | + |
| 144 | +**Related sample:** [RichText. Changing the default value for typography (font, font size, etc.)](https://snippet.dhtmlx.com/6u3ti01s) |
0 commit comments