Report an issue



The class used to write HTML data.

var writer = new CKEDITOR.htmlWriter();
writer.openTag( 'p' );
writer.attribute( 'class', 'MyClass' );
writer.openTagClose( 'p' );
writer.text( 'Hello' );
writer.closeTag( 'p' );
alert( writer.getHtml() ); // '<p class="MyClass">Hello</p>'



  • indentationChars : String

    The characters to be used for each indentation step.

    // Use tab for indentation.
    editorInstance.dataProcessor.writer.indentationChars = '\t';

    Defaults to '\t'

  • lineBreakChars : String

    The characters to be used for line breaks.

    // Use CRLF for line breaks.
    editorInstance.dataProcessor.writer.lineBreakChars = '\r\n';

    Defaults to '\n'

  • selfClosingEnd : String

    The characters to be used to close "self-closing" elements, like <br> or <img>.

    // Use HTML4 notation for self-closing elements.
    editorInstance.dataProcessor.writer.selfClosingEnd = '>';

    Defaults to ' />'


  • inherited

    constructor() → basicWriter

    Creates a basicWriter class instance.


  • inherited

    attribute( attName, attValue )

    Writes an attribute. This function should be called after opening the tag with openTagClose.

    // Writes ' class="MyClass"'.
    writer.attribute( 'class', 'MyClass' );


    attName : String

    The attribute name.

    attValue : String

    The attribute value.

  • inherited

    closeTag( tagName )

    Writes a closer tag.

    // Writes '</p>'.
    writer.closeTag( 'p' );


    tagName : String

    The element name for this tag.

  • inherited

    comment( comment )

    Writes a comment.

    // Writes '<!-- My comment -->'.
    writer.comment( ' My comment ' );


    comment : String

    The comment text.

  • inherited

    getHtml( reset ) → String

    Empties the current output buffer.

    var html = writer.getHtml();


    reset : Boolean

    Indicates that the reset method is to be automatically called after retrieving the HTML.



    The HTML written to the writer so far.

  • indentation()

    Writes the current indentation character. It uses the indentationChars property, repeating it for the current indentation steps.

    // Writes '\t' (e.g.).
  • lineBreak()

    Writes a line break. It uses the lineBreakChars property for it.

    // Writes '\n' (e.g.).
  • inherited

    openTag( tagName, attributes )

    Writes the tag opening part for a opener tag.

    // Writes '<p'.
    writer.openTag( 'p', { class : 'MyClass', id : 'MyId' } );


    tagName : String

    The element name for this tag.

    attributes : Object

    The attributes defined for this tag. The attributes could be used to inspect the tag.

  • inherited

    openTagClose( tagName, isSelfClose )

    Writes the tag closing part for a opener tag.

    // Writes '>'.
    writer.openTagClose( 'p', false );
    // Writes ' />'.
    writer.openTagClose( 'br', true );


    tagName : String

    The element name for this tag.

    isSelfClose : Boolean

    Indicates that this is a self-closing tag, like <br> or <img>.

  • inherited


    Empties the current output buffer.

  • setRules( tagName, rules )

    Sets formatting rules for a given element. Possible rules are:

    • indent – indent the element content.
    • breakBeforeOpen – break line before the opener tag for this element.
    • breakAfterOpen – break line after the opener tag for this element.
    • breakBeforeClose – break line before the closer tag for this element.
    • breakAfterClose – break line after the closer tag for this element.

    All rules default to false. Each function call overrides rules that are already present, leaving the undefined ones untouched.

    By default, all elements available in the CKEDITOR.dtd.$block, CKEDITOR.dtd.$listItem, and CKEDITOR.dtd.$tableContent lists have all the above rules set to true. Additionaly, the <br> element has the breakAfterOpen rule set to true.

    // Break line before and after "img" tags.
    writer.setRules( 'img', {
        breakBeforeOpen: true
        breakAfterOpen: true
    } );
    // Reset the rules for the "h1" tag.
    writer.setRules( 'h1', {} );


    tagName : String

    The name of the element for which the rules are set.

    rules : Object

    An object containing the element rules.

  • inherited

    text( text )

    Writes text.

    // Writes 'Hello Word'.
    writer.text( 'Hello Word' );


    text : String

    The text value.

  • inherited

    write( data )

    Writes any kind of data to the ouput.

    writer.write( 'This is an <b>example</b>.' );


    data : String