---
title: "How to Add Color Picker in Magento 2 System Configuration"
url: "https://magecomp.com/blog/add-color-picker-in-magento-2-system-configuration/"
date: "2018-01-16T10:12:45+00:00"
modified: "2025-02-22T06:43:13+00:00"
author:
  name: "Dhiren Vasoya"
  url: "https://magecomp.com/"
categories:
  - "How To"
  - "Magento 2"
word_count: 494
reading_time: "3 min read"
summary: "When it comes to building online E-commerce store, Magento is first pick of store owners due to its ability to mold Magento according to meet unique need of store owners. Sometimes you require to a..."
description: "Whenever you want to provide admin the permission to modify UI of frontend pages, sections or some specific layouts, you require to add color picker in Magen..."
keywords: "How To, Magento 2"
language: "en"
schema_type: "Article"
related_posts:
  - title: "Laravel 8: Database Seeder with Example"
    url: "https://magecomp.com/blog/laravel-8-database-seeder/"
  - title: "Magento 2: How To configure Auto Select Shipping Methods when more than one shipping methods are available."
    url: "https://magecomp.com/blog/how-to-configure-auto-select-shipping-methods-in-magento-2/"
  - title: "How to Create your Own Custom Theme in Magento 2?"
    url: "https://magecomp.com/blog/create-custom-theme-magento-2/"
---

# How to Add Color Picker in Magento 2 System Configuration

_Published: January 16, 2018_  
_Author: Dhiren Vasoya_  

![img How to Add Color Picker in Magento 2 System Configuration](https://magecomp.com/blog/wp-content/uploads/2018/01/img_How-to-Add-Color-Picker-in-Magento-2-System-Configuration-1024x332.webp)

When it comes to building online E-commerce store, Magento is first pick of store owners due to its ability to mold Magento according to meet unique need of store owners. Sometimes you require to allow admin change the UI of frontend such as background color of pages, layout color etc. To implement this functionality, you need to ***add color picker in Magento 2 System configuration***. So, today I’m sharing 3 steps guide to add Color Picker in Magento 2 System Configuration.

[![Magento version upgrade](https://magecomp.com/blog/wp-content/uploads/2025/02/Magento-2-Version-Upgrade-CTA-3.webp)](https://magecomp.com/services/magento-upgrade-services/)

On the very first step, we need to add color picker to textbox through **system.xml** file located at
**app\code\Vendor\Extension\etc\adminhtml**

<label>Background Color</label> <![CDATA[Background color]]> Vendor\Extension\Block\Color```

<config ...>
	<system>
    	        	<group id="my_color_group" ...>
            	<field id="my_color_option" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Background Color</label>
                    <comment><![CDATA[Background color]]></comment>
                    <frontend_model>VendorExtensionBlockColor</frontend_model>
                    </field>
        	</group>
    		</system>
</config>
```

Once a code is added, now we have to create one **Color.php** file at below location under the hood of extension **app\code\Vendor\Extension\Block**

```

<?php
namespace VendorExtensionBlock;

class Color extends MagentoConfigBlockSystemConfigFormField {

	public function __construct(
    MagentoBackendBlockTemplateContext $context, array $data = []
	) {
        parent::__construct($context, $data);
	}

	protected function _getElementHtml(MagentoFrameworkDataFormElementAbstractElement $element) {
    	$html = $element->getElementHtml();
    	$value = $element->getData('value');

    	$html .= '<script type="text/javascript">
            require(["jquery","jquery/colorpicker/js/colorpicker"], function ($) {
                $(document).ready(function () {
                	var $el = $("#' . $element->getHtmlId() . '");
                    $el.css("backgroundColor", "'. $value .'");

                	// Attach the color picker
                    $el.ColorPicker({
                    	color: "'. $value .'",
                        onChange: function (hsb, hex, rgb) {
                            $el.css("backgroundColor", "#" + hex).val("#" + hex);
                    	}
                	});
            	});
        	});
	        </script>';
    	return $html;
	}

}
```

[![Magento Malware Removal](https://magecomp.com/blog/wp-content/uploads/2025/02/Magento-Malware-Removal-CTA-4.webp)](https://magecomp.com/magento-malware-removal.html)

At last, we need to implement JavaScript color picker library to **adminhtml_system_config_edit.xml** file available at **app\code\Vendor\Extension\view\adminhtml\layout**

```

<?xml version="1.0" encoding="UTF-8"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="admin-2columns-left" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">
	<head>
    	<css src="jquery/colorpicker/css/colorpicker.css"/>
    		</head>
</page>
```

Tadaa, now clear the cache and navigate to system configuration and you can see color picker option. You can even customize and use this code to place color picker anywhere in Magento.

Comment down below if you face any issue while implementing this code. And Yeah, don’t forget to hit below stars.

[![Magento 2 Speed & Performance Optimization Services](https://magecomp.com/blog/wp-content/uploads/2023/10/Magento-2-Speed-Performance-Optimization-Services-CTA-4.webp)](https://magecomp.com/magento-performance-optimization.html)
Happy Coloring!


---

_View the original post at: [https://magecomp.com/blog/add-color-picker-in-magento-2-system-configuration/](https://magecomp.com/blog/add-color-picker-in-magento-2-system-configuration/)_  
_Served as markdown by [Third Audience](https://github.com/third-audience) v3.5.3_  
_Generated: 2026-08-31 11:13:08 UTC_  
