• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
JavaScriptSource

JavaScriptSource

Search 5,000+ Free JavaScript Snippets

  • Home
  • Browse Snippets
    • Addon
    • Ajax
    • Buttons
    • Cookies
    • CSS
    • Featured
    • Forms
    • Games
    • Generators
    • Image Effects
    • Math Related
    • Miscellaneous
    • Multimedia
    • Navigation
    • Page Details
    • Passwords
    • Text Effects
    • Time & Date
    • User Details
Home / CSS / Retrieve the value of a CSS rule for the specified element

Retrieve the value of a CSS rule for the specified element

Retrieve the value of a CSS rule for the specified element

Use Window.getComputedStyle() to get the value of the CSS rule for the specified element.

const getStyle = (el, ruleName) => getComputedStyle(el)[ruleName];

// EXAMPLE
getStyle(document.querySelector('p'), 'font-size'); // '16px'

Source

https://www.30secondsofcode.org/js/s/get-style

CSS

Related Snippets:

  • Get the computed style of an element
  • Find all matching elements on a page with document.querySelectorAll()
  • Get the default value of a CSS property with JavaScript
  • Apply a CSS animation to an element with JavaScript

Primary Sidebar

Popular Posts

Story Generator

IP Grabber – get a users IP address with JavaScript

Simple Calendar

Remove Ads

Astrological Calculator

Copyright © 2025 JavaScriptSource.com

  • About
  • Privacy Policy
  • FAQ
  • Jobs For Developers