jQuery Tutorial

jQuery css() Method With Syntax and Example

What is css method in jQuery?

One or more style properties are set or returned by the CSS() function. The value of the provided CSS attribute of the FIRST matched element is returned by this function when used to return properties. 

Shorthand CSS properties (like "background" and "border"), on the other hand, are not fully supported and may produce different results across browsers.

Syntax of css method in jQuery

  • Return the value of the CSS property:


  • Set the CSS property and value:


  • Set CSS property and value using a function:


  • Set multiple properties and values:

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

Example of jQuery css method

The colour property of all p> elements should be set to:

  $("p").css("color", "red");
Did you find this article helpful?