Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
148 lines (133 sloc) 10.3 KB
<!DOCTYPE html>
<!--
Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
For licensing, see LICENSE.md or http://ckeditor.com/license.
-->
<html>
<head>
<meta charset="utf-8">
<meta name="description" content="Setting Text and Background Color with the Color Button">
<meta name="keywords" content="ckeditor, editor, wysiwyg, color, text, font, background">
<meta name="sdk-samples" content="Text and background color with Color Dialog|Custom text and background colors">
<meta name="sdk-category" content="sdk-styling-and-formatting">
<meta name="sdk-order" content="60">
<title>Text and Background Color</title>
<link href="https://fonts.googleapis.com/css?family=Maven+Pro:700,500,400" rel="stylesheet">
<link href="../template/theme/css/sdk.css" rel="stylesheet">
<script src="../../ckeditor-dev/ckeditor.js"></script>
<script src="assets/picoModal-2.0.1.min.js"></script>
<script src="assets/sample.js"></script>
<script src="assets/contentloaded.js"></script>
<script src="assets/simplesample.js"></script>
<script src="assets/beautify-html.js"></script>
<!--[if lt IE 9]>
<script src="assets/html5shiv.min.js"></script>
<![endif]-->
<link rel="icon" href="../template/theme/img/favicon.ico">
</head>
<body>
<header class="sdk-header">
</header>
<section class="sdk-container">
<nav class="sdk-sidebar">
</nav>
<section class="sdk-contents">
<h1>Setting Text and Background Color <a class="documentation" href="https://ckeditor.com/docs/ckeditor4/latest/features/colorbutton.html">Documentation</a></h1>
<p>
The optional <strong>Text and Background Color</strong> feature is provided through the
<a href="https://ckeditor.com/cke4/addon/colorbutton">Color Button</a> plugin which by default is available
in the Full distribution.
</p>
<p>
When the plugin is enabled, the <span class="button_icon" data-icon="textcolor" title="Text Color">&nbsp;</span>
and <span class="button_icon" data-icon="bgcolor" title="Background Color">&nbsp;</span>
buttons are automatically added to the toolbar. You can use them to add some color to your content.
If you want to quickly remove colors from your document,
use the <span class="button_icon" data-icon="removeformat" title="Remove Format">&nbsp;</span> button provided
by the <a href="./removeformat.html">Remove Format</a> plugin.
</p>
<h2>More Colors Option and Color Dialog</h2>
<p>
You can also add an optional <a href="https://ckeditor.com/cke4/addon/colordialog">Color Dialog</a>
plugin which provides the <strong>More Colors</strong> option and a user-friendly way to select the desired
color through a dedicated dialog window. The editor instance below includes both features.
</p>
<textarea cols="80" id="editor1" name="editor1" rows="10" data-sample="1" data-sample-short>
&lt;h1&gt;Apollo 11&lt;/h1&gt; &lt;p&gt;&lt;b&gt;Apollo 11&lt;/b&gt;
was the spaceflight that landed the first humans, Americans &lt;a href=&quot;http://en.wikipedia.org/wiki/Neil_Armstrong&quot; title=&quot;Neil Armstrong&quot;&gt;Neil Armstrong&lt;/a&gt;
and &lt;a href=&quot;http://en.wikipedia.org/wiki/Buzz_Aldrin&quot; title=&quot;Buzz Aldrin&quot;&gt;Buzz Aldrin&lt;/a&gt;, on the Moon on July 20, 1969, at 20:18 UTC. Armstrong became
the first to step onto the lunar surface 6 hours later on July 21 at 02:56 UTC.&lt;/p&gt; &lt;p&gt;Armstrong spent about &lt;s&gt;three and a half&lt;/s&gt; two and a half hours
outside the spacecraft, Aldrin slightly less; and together they collected 47.5 pounds (21.5&amp;nbsp;kg) of lunar material for return to Earth. A third member of the mission, &lt;a
href=&quot;http://en.wikipedia.org/wiki/Michael_Collins_(astronaut)&quot; title=&quot;Michael Collins (astronaut)&quot;&gt;Michael Collins&lt;/a&gt;, piloted the &lt;a href=&quot;http://en.wikipedia.org/wiki/Apollo_Command/Service_Module&quot;
title=&quot;Apollo Command/Service Module&quot;&gt;command&lt;/a&gt; spacecraft alone in lunar orbit until Armstrong and Aldrin returned to it for the trip back to Earth.&lt;/p&gt;
&lt;h2&gt;Broadcasting and &lt;em&gt;quotes&lt;/em&gt; &lt;a id=&quot;quotes&quot; name=&quot;quotes&quot;&gt;&lt;/a&gt;&lt;/h2&gt; &lt;p&gt;Broadcast on live TV to a world-wide
audience, Armstrong stepped onto the lunar surface and described the event as:&lt;/p&gt; &lt;blockquote&gt;&lt;p&gt;One small step for [a] man, one giant leap for mankind.&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;Apollo 11 effectively ended the &lt;a href=&quot;http://en.wikipedia.org/wiki/Space_Race&quot; title=&quot;Space Race&quot;&gt;Space Race&lt;/a&gt; and fulfilled a national
goal proposed in 1961 by the late U.S. President &lt;a href=&quot;http://en.wikipedia.org/wiki/John_F._Kennedy&quot; title=&quot;John F. Kennedy&quot;&gt;John F. Kennedy&lt;/a&gt; in a
speech before the United States Congress:&lt;/p&gt; &lt;blockquote&gt;&lt;p&gt;[...] before this decade is out, of landing a man on the Moon and returning him safely to the Earth.&lt;/p&gt;&lt;/blockquote&gt;
&lt;hr/&gt; &lt;p style=&quot;text-align:
right;&quot;&gt;&lt;small&gt;Source: &lt;a href=&quot;http://en.wikipedia.org/wiki/Apollo_11&quot;&gt;Wikipedia.org&lt;/a&gt;&lt;/small&gt;&lt;/p&gt;
</textarea>
<h2>Custom Color List</h2>
<p>
Allowing your users to use any colors they wish might lead to undesired results, i.e. joyfully colorful content
that will make your page look like it was created in the early 1990s. You can prevent this situation by customizing the
color list to only include a limited number of colors that match your website style. The editor instance below
uses the <code><a href="https://ckeditor.com/docs/ckeditor4/latest/api/CKEDITOR_config.html#cfg-colorButton_colors">config.colorButton_colors</a></code>
option to trim down the color list to a selected few.
</p>
<p>
Additionally, since CKEditor 4.5.8 you can also disable the "Automatic" option by setting the <code><a href="https://ckeditor.com/docs/ckeditor4/latest/api/CKEDITOR_config.html#cfg-colorButton_enableAutomatic">config.colorButton_enableAutomatic</a></code>
option to <code>false</code>. The editor instance below includes customizations.
</p>
<textarea cols="80" id="editor2" name="editor2" rows="10" data-sample="2" data-sample-short>
&lt;h1&gt;&lt;span style=&quot;color:#66AB16&quot;&gt;Apollo 11&lt;/span&gt;&lt;/h1&gt;
&lt;p&gt;&lt;span style=&quot;color:#FFFFFF&quot;&gt;&lt;strong&gt;&lt;span style=&quot;background-color:#454545&quot;&gt;Apollo 11&lt;/span&gt;&lt;/strong&gt;&lt;/span&gt; was the spaceflight that landed the first humans, Americans &lt;a href=&quot;http://en.wikipedia.org/wiki/Neil_Armstrong&quot;&gt;Neil Armstrong&lt;/a&gt; and &lt;a href=&quot;http://en.wikipedia.org/wiki/Buzz_Aldrin&quot;&gt;Buzz Aldrin&lt;/a&gt;, on the Moon on July 20, 1969, at 20:18 UTC. Armstrong became the first to step onto the lunar surface 6 hours later on July 21 at 02:56 UTC.&lt;/p&gt;
&lt;p&gt;Armstrong spent about &lt;s&gt;three and a half&lt;/s&gt; two and a half hours outside the spacecraft, Aldrin slightly less; and together they collected 47.5 pounds (21.5&amp;nbsp;kg) of lunar material for return to Earth. A third member of the mission, &lt;a href=&quot;http://en.wikipedia.org/wiki/Michael_Collins_(astronaut)&quot;&gt;Michael Collins&lt;/a&gt;, piloted the &lt;a href=&quot;http://en.wikipedia.org/wiki/Apollo_Command/Service_Module&quot;&gt;command&lt;/a&gt; spacecraft alone in lunar orbit until Armstrong and Aldrin returned to it for the trip back to Earth.&lt;/p&gt;
&lt;h2&gt;&lt;span style=&quot;color:#CF5D4E&quot;&gt;Broadcasting and &lt;em&gt;quotes&lt;/em&gt;&lt;/span&gt; &lt;a id=&quot;quotes&quot; name=&quot;quotes&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Broadcast on live TV to a world-wide audience, Armstrong stepped onto the lunar surface and described the event as:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;span style=&quot;background-color:#DDDDDD&quot;&gt;One small step for [a] man, one giant leap for mankind.&lt;/span&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Apollo 11 effectively ended the &lt;a href=&quot;http://en.wikipedia.org/wiki/Space_Race&quot;&gt;Space Race&lt;/a&gt; and fulfilled a national goal proposed in 1961 by the late U.S. President &lt;a href=&quot;http://en.wikipedia.org/wiki/John_F._Kennedy&quot;&gt;John F. Kennedy&lt;/a&gt; in a speech before the United States Congress:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;span style=&quot;background-color:#DDDDDD&quot;&gt;[...] before this decade is out, of landing a man on the Moon and returning him safely to the Earth.&lt;/span&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;hr /&gt;
&lt;p&gt;&lt;small&gt;Source: &lt;a href=&quot;http://en.wikipedia.org/wiki/Apollo_11&quot;&gt;Wikipedia.org&lt;/a&gt;&lt;/small&gt;&lt;/p&gt;
</textarea>
<div class="tip">
The <strong>Text and Background Color</strong> feature does not create semantically meaningful content.
To create semantic content and also maintain consistent styling across your website, including user-created
content, consider configuring the <a href="./styles.html">Styles</a> drop-down list to include some
colored styles that could be used by your users and would match your website design instead of enabling the
<strong>Text and Background Color</strong> buttons and dealing with a stylistic nightmare later.
</div>
<h2>Related Features</h2>
<ul>
<li><a href="./copyformatting.html">Styling and Formatting &ndash; Copying Text Formatting</a></li>
<li><a href="./removeformat.html">Styling and Formatting &ndash; Removing Text Formatting</a></li>
<li><a href="./basicstyles.html">Styling and Formatting &ndash; Basic Text Styles: Bold, Italic and More</a></li>
<li><a href="./styles.html">Styling and Formatting &ndash; Applying Styles to Editor Content</a></li>
<li><a href="./format.html">Styling and Formatting &ndash; Applying Block-Level Text Formats</a></li>
</ul>
<script data-sample="1">
CKEDITOR.replace( 'editor1', {
height: 250,
extraPlugins: 'colorbutton,colordialog'
} );
</script>
<script data-sample="2">
CKEDITOR.replace( 'editor2', {
height: 250,
extraPlugins: 'colorbutton',
colorButton_colors: 'CF5D4E,454545,FFF,CCC,DDD,CCEAEE,66AB16',
colorButton_enableAutomatic: false
} );
</script>
</section>
</section>
<footer class="sdk-footer">
</footer>
</body>
</html>
You can’t perform that action at this time.