Socket
Book a DemoInstallSign in
Socket

css-exp

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

css-exp

Expression-driven CSS Property Binder - Dynamic CSS values using JavaScript expressions

1.0.0
latest
Source
npmnpm
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

css-exp

Tests

Dynamic CSS property binding using JavaScript expressions. Bind CSS properties to element dimensions, create responsive layouts, and implement conditional styling.

Installation

npm install css-exp

CDN

<script src="https://unpkg.com/css-exp@latest/dist/css-exp.min.js"></script>

Usage

Basic Example

<div id="container" style="width: 1000px;">
  <div data-expression="this.width = el('#container').width * 0.5"></div>
</div>

<script type="module">
  import { cssExp } from 'css-exp';
  cssExp.start();
</script>

Responsive Layout

<div data-expression="
  this.display = el('#sidebar').width > 768 ? 'flex' : 'block';
  this.fontSize = this.width < 480 ? 14px : 16px;
"></div>

Expression Syntax

Access element properties using el('#selector') or reference the current element with this:

// Element dimensions  
this.width = el('#container').width * 0.5;
this.height = this.baseHeight * 1.2;

// Conditional styling
this.display = el('#menu').width > 768 ? 'block' : 'none';

// Logical operators
this.fontSize = this.width > 500 && this.height > 300 ? 18px : 14px;

Available Properties

  • width, height, top, left, right, bottom
  • fontSize, lineHeight, letterSpacing, fontWeight
  • Base values: baseWidth, baseHeight, baseFontSize, etc.

API

import { cssExp } from 'css-exp';

cssExp.start();                                    // Initialize
cssExp.addBinding(element, 'width', 'this.baseWidth * 2');  // Add binding
cssExp.removeBindings(element);                    // Remove bindings
cssExp.destroy();                                  // Cleanup

Development

npm install
npm test
npm run build

License

MIT

Keywords

css

FAQs

Package last updated on 18 Jun 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.