🔥 Just Launched! Werra Premium Template for HyväSee it in Action

How to Add WYSIWYG Editor in Magento 2 Admin Form

By Sanjay JethvaUpdated on May 22, 2025 1 min read

WYSIWYG is an HTML editor to easily play with the content editing. WYSIWYG allows adding and formatting the content providing “What You See Is What You Get ” view. One can see the end result that’ll be displayed in the editing phase. Save yourself from the hassle of HTML programming for enhancing the appearance of frontend!

Magento 2, designed to be as user-friendly as possible, has WYSIWYG as the default editor. ? But sometimes, you need to add WYSIWYG editor in Magento 2 Admin Form to collect data.

Adding WYSIWYG editor in Magento 2 backend eases the task of website development. What more luxury does a developer wish for?

So, here’s the code for you, ready to be implemented in the admin backend!

Code to Add WYSIWYG Editor in Magento 2 Admin Form

Add the following code in your block file:

protected $wysiwygConfig;

public function __construct(
    \Magento\Backend\Block\Template\Context $context,
    \Magento\Cms\Model\Wysiwyg\Config $wysiwygConfig,
    array $data = []
) {
    $this->wysiwygConfig = $wysiwygConfig;
    parent::__construct($context, $data);
}


Add field code 

$fieldset->addField(
    'content',
    'editor',
    [
        'name' => 'content',
        'label' => __('Body'),
        'title' => __('Body'),
        'rows' => '5',
        'cols' => '30',
        'wysiwyg' => true,
        'config' => $this->wysiwygConfig->getConfig(),
        'required' => true
    ]
);​​​​​​​

Follow the above method and the content editing is as easy as ABC!

Sanjay Jethva Full Image
Article bySanjay Jethva

Sanjay is the co-founder and CTO of Meetanshi with hands-on expertise with Magento since 2011. He specializes in complex development, integrations, extensions, and customizations. Sanjay is one the top 50 contributor to the Magento community and is recognized by Adobe. His passion for Magento 2 and Shopify solutions has made him a trusted source for businesses seeking to optimize their online stores. He loves sharing technical solutions related to Magento 2 & Shopify.