Title: Set CSS attribute for widgets
Last modified: August 19, 2016

---

# Set CSS attribute for widgets

 *  [arjanver](https://wordpress.org/support/users/arjanver/)
 * (@arjanver)
 * [15 years, 6 months ago](https://wordpress.org/support/topic/set-css-attribute-for-widgets/)
 * Hi,
 * Is there a pluging or does someone have code to get the option to set a CSS class
   for widgets?
 * For example in the admin panel i add widgets and i want there a custom field 
   to add some css code to make the widgets background red and another widget blue.
 * i’ve search but couldn’t find such thing.
 * anyone?
 * thanks

Viewing 7 replies - 1 through 7 (of 7 total)

 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [15 years, 6 months ago](https://wordpress.org/support/topic/set-css-attribute-for-widgets/#post-1780924)
 * [http://codex.wordpress.org/Function_Reference/register_sidebar](http://codex.wordpress.org/Function_Reference/register_sidebar)
 *  Thread Starter [arjanver](https://wordpress.org/support/users/arjanver/)
 * (@arjanver)
 * [15 years, 6 months ago](https://wordpress.org/support/topic/set-css-attribute-for-widgets/#post-1780985)
 * that is not what i mean.
 * For example in the admin panel i add widgets and i want there a custom field 
   to add some css code to make the widgets background red and another widget blue.
 * so i define some background classes in the template css file.
    and i want a option
   to choose from the admin area to set the class. So i can easy change the background
   color for different sidebar boxes.
 *  [ambrosite](https://wordpress.org/support/users/ambrosite/)
 * (@ambrosite)
 * [15 years, 6 months ago](https://wordpress.org/support/topic/set-css-attribute-for-widgets/#post-1780988)
 * If you inspect the code generated by those widgets using a tool like Firebug,
   you will see that they are already being assigned unique CSS classes. For example,
   the div for the default Pages widget gets a class called “widget_pages”. Just
   use the existing classes along with descendant selectors to style the widgets.
 *  Thread Starter [arjanver](https://wordpress.org/support/users/arjanver/)
 * (@arjanver)
 * [15 years, 6 months ago](https://wordpress.org/support/topic/set-css-attribute-for-widgets/#post-1781007)
 * no offence but you didn’t understand my question 😉
 * i know i can predefine these id’s/classes, but that is not what i want.
 * i want to change the background color of a widget from the widgets admin panel.
 *  [ambrosite](https://wordpress.org/support/users/ambrosite/)
 * (@ambrosite)
 * [15 years, 6 months ago](https://wordpress.org/support/topic/set-css-attribute-for-widgets/#post-1781009)
 * Why would you want to do that?
 * To answer your question, no, it is not possible without rewriting the PHP code
   of the widgets. The code for the default widgets is in this file:
 * /wp-includes/default-widgets.php
 * Of course, hacking the core files is highly inadvisable, since all your hacks
   will be lost whenever you upgrade to a new WP version. What you should do instead
   is create custom widgets based on the default widget code, and then install them
   as plugins — if you really want to take it that far. Personally, I think it would
   be much easier to style the widgets by editing the CSS file.
 *  [zactoff](https://wordpress.org/support/users/zactoff/)
 * (@zactoff)
 * [15 years ago](https://wordpress.org/support/topic/set-css-attribute-for-widgets/#post-1781168)
 * Did you ever solve this? I want to do the same thing, got a lot of widget areas
   in the back end that I’d like to colour code for the client.
 *  Thread Starter [arjanver](https://wordpress.org/support/users/arjanver/)
 * (@arjanver)
 * [15 years ago](https://wordpress.org/support/topic/set-css-attribute-for-widgets/#post-1781169)
 * no, sorry

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Set CSS attribute for widgets’ is closed to new replies.

## Tags

 * [sidebar](https://wordpress.org/support/topic-tag/sidebar/)
 * [widget](https://wordpress.org/support/topic-tag/widget/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 7 replies
 * 4 participants
 * Last reply from: [arjanver](https://wordpress.org/support/users/arjanver/)
 * Last activity: [15 years ago](https://wordpress.org/support/topic/set-css-attribute-for-widgets/#post-1781169)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
