# Themes

Home Search

## Theming overview

The theming system used in jQuery Mobile is similar to the ThemeRoller system in jQuery UI with a few important improvements:

- It takes advantage of CSS3 properties to add rounded corners, box and text shadow and gradients instead of images, allowing the theme file to be very lightweight and reducing server requests.
- Themes include multiple color "swatches" — each consisting of a header bar, content body, and button states that can be freely mixed and matched to create visual texture — to make richer designs possible.
- Open-ended theming allows for up to 26 unique swatches per theme, to add almost unlimited variety to designs.
- All backgrounds now use CSS3 gradients to dramatically reduce file size and number of server requests.
- There is a simplified icon set in a sprite to reduce image weight.

## ThemeRoller

The easiest way to create custom themes is with the ThemeRoller tool. It allows you to build a theme, then download a custom CSS file, ready to be dropped into your project.

## Themes & swatches

The theme system separates color and texture from structural styles that define things like padding and dimensions. This allows theme colors and textures to be defined once in the stylesheet and to be mixed, matched, and combined to achieve a wide range of visual effects.

Each theme includes several global settings, including font family, drop shadows for overlays, and corner radius values for buttons and boxes. In addition, the theme can include multiple color swatches, each with color values for bars, content blocks, buttons and list items, and font `text-shadow`.

The default theme includes 5 swatches that are given letters (a, b, c, d, e) for quick reference. To make mapping of color swatches consistent across our widgets, we have followed the convention that swatch "a" is the highest level of visual priority (black in our default theme), "b" is secondary level (blue) and "c" is the baseline level (gray) that we use by default in many situations, "d" for an alternate secondary level and "e" as an accent swatch. Themes may have additional swatches for accent colors or specific situations. For example, you could add a new theme swatch "f" that has a red bar and button for use in error situations.

Most theme changes can be done using ThemeRoller, but it's also simple to manually edit the base swatches in the default theme and/or add additional swatches by editing the theme CSS file. Just copy a block of swatch styles, rename the classes with the new swatch letter name, and tweak colors as you see fit.

### Bars

The default theme contains the following five bar styles:

Bar A - Link
Bar B - Link
Bar C - Link
Bar D - Link
Bar E - Link

By default, the framework assigns the "a" swatch to all headers and footers, because these are typically given high visual priority in an application. To set the color of a bar to a different swatch color, simply add the `data-theme` attribute to your header or footer and specify an alternate swatch letter ('b' or 'd', for example) and the specified theme swatch color will be applied. Learn more about toolbar theming.

### Content Blocks

The default theme also includes color swatch values for use in content blocks, designed to coordinate with the header color swatches in the theme.

Block A - Link
Block B - Link
Block C - Link
Block D - Link
Block E - Link

If a theme isn't specified on a content block, the framework will default to "c" to maximize contrast against the default header "a", as shown here:

Back

# Default Header

### Default Theme Content Header

This is the default content color swatch and a preview of a link.

Input slider:
Cache settings: On Off
Button
Button Button Button

Learn more about content theming.

## Lists & Buttons

Each swatch also includes default styles for interactive elements like list items and buttons.

- List item
- List item

- List item
- List item

- List item
- List item

- List item
- List item

- List item
- List item

A button is included for each swatch in the theme. Each button has styles for normal, hover/focus and pressed states.

Button A Button B Button C Button D Button E

By default, any button that's placed in a bar is automatically assigned a swatch letter that matches its parent bar or content box. Thus, the button is visually integrated into the parent theme as shown here:

# Bar A

Button A

# Bar B

Button B

# Bar C

Button C

# Bar D

Button D

# Bar E

Button E

This default behavior makes it easy to ripple a theme change through a page by setting a theme swatch on a parent because you know the buttons will maintain the same relative visual weight across themes. Since form elements use the button styles, they will also adapt to their parent container.

If you want to add visual emphasis to a button, an alternate swatch color can be set by adding a `data-theme="a"` to the anchor. Once an alternate swatch color is set on a button in the markup, the framework won't override that color if the parent theme is changed, because you made a conscious decision to set it.

A B C D E
A B C D E
A B C D E
A B C D E
A B C D E

Learn more about list theming and button theming.

### Global "Active" state

The jQuery Mobile framework uses a swatch called "active" (bright blue in the default theme) to consistently indicate the selected state, regardless of the individual swatch of the given widget. We apply this in navigation and form controls whenever there is a need to indicate what is currently selected. Because this theme swatch is designed for clear, consistent user feedback, it cannot be overridden via the markup; it is set once in the theme and applied by the framework whenever a selected or active state is needed. The styling for this state is in the theme stylesheet under the `ui-btn-active` style rules.

Active is used for the on state of these toggles: On Off

### Icons

There is a core set of standard icons included in the framework that can be assigned to any button. To minimize the download size of the core icons, jQuery Mobile only includes these icons in white and automatically adds a semi-transparent black circle behind the icon to make sure it has good contrast on all background colors.

### Theme classes

Assigning color swatches through the `data-theme` attribute is one way to leverage the theme system, but it's also possible to apply any of the theme swatches directly to your markup through classes to apply the colors, textures and font formatting of your theme to any markup. This is especially useful when creating your own custom layout elements or UI widgets. Here are a few common theme classes, but many more are available in the theme stylesheet:

`ui-bar-(a-z)`
  Applies the toolbar theme styles for the selected swatch letter. Commonly used in conjunction with `ui-bar` structural class to add the standard bar padding styles.
`ui-body-(a-z)`
  Applies the content body theme styles for the selected swatch letter. Commonly used in conjunction with `ui-body` structural class to add the standard content block padding styles.
`ui-btn-up-(a-z)`
  Applies the button/clickable element theme styles for the selected swatch letter. Commonly used in with the `ui-btn-hover-(a-z)` and `ui-btn-down-(a-z)` interaction class states to provide visual feedback and `ui-btn-active` to indicate the selected or "on" state.
`ui-corner-all`
  Applies the theme's global border-radius for rounded corners and is used for container or grouped items in the framework (inset lists, radiobutton sets). There are additional classes for all the possible combinations of rounded corners, for example: `ui-corner-tl` (top left only), `-top` (both top corners), `-left` (both left corners), etc. A second full set of corner classes is provided for buttons so these can have a different corner radius. These use classes with a similar naming convention, but with "btn-corner" instead of "corner", like this: `.ui-btn-corner-all`.
`ui-shadow`
  Applies the theme's global drop shadow to any element using CSS `box-shadow` property.
`ui-disabled`
  Applies the disabled look and feel which essentially reduces the opacity of any element with this class to 30%, hides the cursor, and sets `pointer-events: none;` which prevents any interaction in many modern browsers.

### Overriding themes

The themes are meant as a solid starting point, but are meant to be customized. Since everything is controlled by CSS, it's easy to use a web inspector tool to identify the style properties you want to modify. The set of of theme classes (global) and semantic structural classes (widget-specific) added to elements provide a rich set of possible selectors to target style overrides against. We recommend adding an external stylesheet to the `head`, placed after the structure and theme stylesheet references, that contain all your style overrides. This allows you to easily update to newer versions of the library because overrides are kept separate from the library code.

Learn more about theming individual components:

- Page theming
- Toolbar theming
- Content theming
- Button theming
- Form theming
- List theming

### More in this section

- API
- Configuring defaults
- Events
- Methods & Utilities
- Data attribute reference
- Theme framework