jQuery Tutorial
jQuery Introduction jQuery Getting Started jQuery Syntax jQuery Selectors jQuery Events
jQuery Effects
jQuery Hide/Show jQuery Fade jQuery Slide jQuery Animation jQuery stop() jQuery Callback jQuery Chaining
jQuery Manipulation
jQuery Get/Set jQuery Add jQuery Remove jQuery CSS Classes jQuery css() jQuery Dimensions
jQuery Traversing
jQuery Traversing jQuery Ancestors jQuery Descendants jQuery Siblings jQuery Filtering
jQuery AJAX
jQuery AJAX Intro jQuery Load jQuery Get/Post jQuery AJAX Events
jQuery Misc
jQuery noConflict() jQuery Filters
jQuery References
jQuery Reference jQuery Selectors jQuery Events jQuery Effects jQuery HTML/CSS jQuery Traversing jQuery AJAX jQuery Miscellaneous jQuery Properties

jQuery CSS() Method

The jQuery css() method gets or sets one or more style properties for the selected elements.

This method provides a quick way to apply the styles (inline styles) directly to the HTML elements.

Return a CSS Property Value

To return the value of a specified CSS property, use the following syntax:


The following example returns the background color of a clicked DIV:

Run code

Set a CSS Property and Value

To set a specified CSS property and value, use the following syntax:

$(selector).css(property, value)

The following example sets the color property of all paragraphs:

Run code

When the css() method is used to get the property value, it returns the value of the first selected element.

When the css() method is used to set property values, it sets one or more property/value pairs for all selected elements.

Set Multiple CSS Properties and Values

To set multiple CSS properties and values, use the following syntax:

$(selector).css({property:value, property:value, ...})

The following example sets multiple CSS properties and values for all paragraphs:

Run code

jQuery CSS Reference

For a complete CSS methods reference, visit our jQuery HTML/CSS Reference.