-1

Which is better for website speed, CSS :hover or jQuery hover? Or are they about the same?

7
  • 7
    not including an external library that the browser can do natively will always be faster Commented May 29, 2014 at 22:53
  • 3
    Counter-question: if CSS :hover is enough for you needs, why would you ever consider replacing it with jQuery? Commented May 29, 2014 at 22:54
  • 1
    Use CSS! When you use jquery, you load Jquery script, it's more fast if you use css. Commented May 29, 2014 at 22:55
  • What if it was something were both CSS and jQuery would require an external library?(like moz-box-styling for CSS) Commented May 29, 2014 at 22:56
  • 2
    Maybe there is a difference between using jQuery or plain CSS, but even if there is, the difference is so small your users will never even notice. So use whatever is easiest for you. Commented May 29, 2014 at 22:59

2 Answers 2

6

CSS

  • CSS is native (built into browsers), like a HTML parser and a JavaScript engine
  • CSS styles are exposed to scripting languages via the CSSOM - the CSS Object Model which defines APIs for media queries, selectors and CSS itself
  • Implementation does not happen through a scripting language (unless the layout engine itself is written in one)

jQuery

  • jQuery is a JavaScript library, and therefore external to browsers
  • Needs to be downloaded and run through the browser's implementation of JavaScript
  • jQuery will need to access the DOM and CSSOM, which is implemented in JavaScript, which the browser has to run

So, theoretically, while you can use jQuery and CSS to both use onEvent methods, CSS would be faster, as it is native to browsers, and does not have to do the added step to download and "translate" the library.

More information

Performance: Pure CSS vs jQuery

How browsers work - Behind the scenes of modern web browsers

Sign up to request clarification or add additional context in comments.

1 Comment

Note : CSS hover (or any selector) for animation purpose is usually slower than jQuery animations (and way slower than pure animations framework (Example). CSS only trigger the event faster.
0

Jquery and CSS can both be onEvent driven. The only time speed is affected is when loading the DOM, because the Jquery library has to be downloaded.

The de-facto for such events is using CSS simply because it is native.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.