How Do I Customize the Styles Drop-Down List?

This website contains links to software which is either no longer maintained or will be supported only until the end of 2019 (CKFinder 2). For the latest documentation about current CKSource projects, including software like CKEditor 4/CKEditor 5, CKFinder 3, Cloud Services, Letters, Accessibility Checker, please visit the new documentation website.

If you look for an information about very old versions of CKEditor, FCKeditor and CKFinder check also the CKEditor forum, which was closed in 2015. If not, please head to StackOverflow for support.

(Article contents added)
 
(Stylesheet Parser Plugin: Text replaced with a link to a dedicated HOWTO article)
 
(2 intermediate revisions by the same user not shown)
Line 2: Line 2:
 
You need to pass your own style definitions to the <code>CKEDITOR.stylesSet.add</code> function, giving them a unique name, and then configure the editor to use them by setting the <code>[http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.config.html#.stylesSet stylesSet]</code> value.
 
You need to pass your own style definitions to the <code>CKEDITOR.stylesSet.add</code> function, giving them a unique name, and then configure the editor to use them by setting the <code>[http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.config.html#.stylesSet stylesSet]</code> value.
  
<source language="js">
+
<source language="javascript">
 
CKEDITOR.stylesSet.add( 'my_styles',
 
CKEDITOR.stylesSet.add( 'my_styles',
 
[
 
[
    // Block-level styles
+
// Block-level styles
    { name : 'Blue Title', element : 'h2', styles : { 'color' : 'Blue' } },
+
{ name : 'Blue Title', element : 'h2', styles : { 'color' : 'Blue' } },
    { name : 'Red Title' , element : 'h3', styles : { 'color' : 'Red' } },
+
{ name : 'Red Title' , element : 'h3', styles : { 'color' : 'Red' } },
  
    // Inline styles
+
// Inline styles
    { name : 'CSS Style', element : 'span', attributes : { 'class' : 'my_style' } },
+
{ name : 'CSS Style', element : 'span', attributes : { 'class' : 'my_style' } },
    { name : 'Marker: Yellow', element : 'span', styles : { 'background-color' : 'Yellow' } }
+
{ name : 'Marker: Yellow', element : 'span', styles : { 'background-color' : 'Yellow' } }
 
]);
 
]);
 
</source>
 
</source>
Line 17: Line 17:
 
Depending on whether your definitions were placed inline or in an external file, you need to set the <code>stylesSet</code> configuration setting accordingly.
 
Depending on whether your definitions were placed inline or in an external file, you need to set the <code>stylesSet</code> configuration setting accordingly.
  
<source language="js">
+
<source language="javascript">
 
// For inline style definition
 
// For inline style definition
 
config.stylesSet = 'my_styles';
 
config.stylesSet = 'my_styles';
Line 26: Line 26:
  
 
For more details on the definition format and best practices on how to customize the styles please refer to the [[CKEditor_3.x/Developers_Guide/Styles|Styles]] article from the [[CKEditor_3.x/Developers_Guide|Developer's Guide]].
 
For more details on the definition format and best practices on how to customize the styles please refer to the [[CKEditor_3.x/Developers_Guide/Styles|Styles]] article from the [[CKEditor_3.x/Developers_Guide|Developer's Guide]].
 +
 +
== Stylesheet Parser Plugin ==
 +
Note that since CKEditor 3.6 you can also populate the '''Styles''' drop-down list with style definitions added in an external CSS stylesheet file. Check the [[CKEditor_3.x/Howto/External_CSS_Styles|How Do I Add Existing CSS Styles from an External File to the Styles Drop-Down List?]] article for more information about using the new (and optional) '''Stylesheet Parser''' plugin.

Latest revision as of 14:22, 31 May 2011

You need to pass your own style definitions to the CKEDITOR.stylesSet.add function, giving them a unique name, and then configure the editor to use them by setting the stylesSet value.

CKEDITOR.stylesSet.add( 'my_styles',
[
	// Block-level styles
	{ name : 'Blue Title', element : 'h2', styles : { 'color' : 'Blue' } },
	{ name : 'Red Title' , element : 'h3', styles : { 'color' : 'Red' } },

	// Inline styles
	{ name : 'CSS Style', element : 'span', attributes : { 'class' : 'my_style' } },
	{ name : 'Marker: Yellow', element : 'span', styles : { 'background-color' : 'Yellow' } }
]);

Depending on whether your definitions were placed inline or in an external file, you need to set the stylesSet configuration setting accordingly.

// For inline style definition
config.stylesSet = 'my_styles';

// For a definition in an external file
config.stylesSet = 'my_styles:http://www.example.com/styles.js';

For more details on the definition format and best practices on how to customize the styles please refer to the Styles article from the Developer's Guide.

Stylesheet Parser Plugin

Note that since CKEditor 3.6 you can also populate the Styles drop-down list with style definitions added in an external CSS stylesheet file. Check the How Do I Add Existing CSS Styles from an External File to the Styles Drop-Down List? article for more information about using the new (and optional) Stylesheet Parser plugin.

This page was last edited on 31 May 2011, at 14:22.