Title: Adding CSS Classes to Widgets
Last modified: August 19, 2016

---

# Adding CSS Classes to Widgets

 *  [Cornflower Design](https://wordpress.org/support/users/scarecrow-rye/)
 * (@scarecrow-rye)
 * [16 years, 4 months ago](https://wordpress.org/support/topic/adding-css-classes-to-widgets/)
 * I know that I can assign classes and unique IDs to Widgets via the following 
   code:
 *     ```
       register_sidebar(array(
           'before_widget' => '<div id="%1$s" class="widget %2$s">',
           'after_widget' => '</div>',
           'before_title' => '<h2>',
           'after_title' => '</h2>',
           ));
       ```
   
 * I also know that I can list all of the available Widgets via this code:
 * `print_r(wp_get_sidebars_widgets());`
 * But is there any way to add an additional CSS class to the ‘before_widget’ parameter
   to denote the Widget’s position? So that I might end up with…
 *     ```
       <div id="linkcat-2" class="widget widget-1 widget_links"></div>
       <div id="rss-2" class="widget widget-2 widget_rss"></div>
       <div id="linkcat-16" class="widget widget-3 widget_links"></div>
       ```
   
 * As a client might add, remove or re-order Widgets within a sidebar, I want to
   avoid targeting a Widget via its ID within my CSS. I need to be able to style
   the first Widget within each sidebar.
 * Can anyone help or offer any ideas?

The topic ‘Adding CSS Classes to Widgets’ is closed to new replies.

## Tags

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

 * 0 replies
 * 1 participant
 * Last reply from: [Cornflower Design](https://wordpress.org/support/users/scarecrow-rye/)
 * Last activity: [16 years, 4 months ago](https://wordpress.org/support/topic/adding-css-classes-to-widgets/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
