jQuery CSS Methods

About This Index
This page is the jQuery CSS index for the tutorial track. Each row links to a full guide with syntax, examples, and FAQs.
Learn the jQuery overview on /jquery. Use this page when you need a CSS API such as .addClass(), .css(), or .width().
Start with .addClass() and .css(), then .width() / .height()—add .offset() and .scrollTop() when you need coordinates or scroll UI.
How to Call a CSS Method
Prefer classes for reusable styles; use .css() for one-off inline values:
$("p").addClass("highlight");
$("p").toggleClass("active");
$("p").hasClass("active"); // true/false
$("div").css("color"); // get computed
$("div").css({ color: "navy", "font-size": "18px" });
$("div").width(); // content width
$("div").outerHeight(true); // include margin
$("div").offset(); // { top, left }
$(window).scrollTop(0); jQuery CSS Methods Table
All CSS method guides in this jQuery tutorial series (17 tutorials).
Class Attributes
4 methodsAdd, remove, toggle, and test CSS classes on matched elements.
| Method | Description | Tutorial |
|---|---|---|
.addClass() | Add one or more CSS classes — string, space-separated list, array, or callback. | Try it |
.hasClass() | Return true if any matched element has the given CSS class. | Try it |
.removeClass() | Remove one, several, or all CSS classes — string, array, or callback. | Try it |
.toggleClass() | Add or remove classes — flip on/off, or force with a boolean state. | Try it |
Inline & Computed Styles
3 methodsRead rendered CSS values and write inline style properties.
| Method | Description | Tutorial |
|---|---|---|
.css() | Get a computed style from the first match, or set inline styles on every match. | Try it |
$.cssHooks | Override how .css() gets or sets a property — custom hooks and vendor prefixes. | Try it |
$.cssNumber | Unitless CSS property map — controls whether .css() appends px to numbers. | Try it |
Dimensions
6 methodsRead and set element height and width — content, inner, and outer boxes.
| Method | Description | Tutorial |
|---|---|---|
.height() | Get content height as a unitless number, or set height on every match. | Try it |
.width() | Get content width as a unitless number, or set width on every match. | Try it |
.innerHeight() | Get or set height including padding but not border. | Try it |
.outerHeight() | Get or set height including padding and border — margin with outerHeight(true). | Try it |
.innerWidth() | Get or set width including padding but not border. | Try it |
.outerWidth() | Get or set width including padding and border — margin with outerWidth(true). | Try it |
Offset & Position
2 methodsDocument coordinates with .offset() and offset-parent coordinates with .position().
| Method | Description | Tutorial |
|---|---|---|
.offset() | Get or set top/left coordinates relative to the document. | Try it |
.position() | Get top/left coordinates relative to the offset parent. | Try it |
Scroll
2 methodsRead and set horizontal and vertical scroll positions.
| Method | Description | Tutorial |
|---|---|---|
.scrollLeft() | Get or set the horizontal scroll position in pixels. | Try it |
.scrollTop() | Get or set the vertical scroll position in pixels. | Try it |
Frequently Asked Questions
Start with .addClass()
Open the class guide—syntax, examples, and FAQs.
16 people found this page helpful
