April 3, 2025

code snippet
code component

How to Add Advanced CSS Styling to Framer Code Components

Discover the workaround for styling Framer code components with advanced CSS techniques. This tutorial explains how to add pseudo-elements, webkit properties, and custom styling to Framer projects despite the CSS file limitation using JavaScript multiline strings.

David McBacon

Created by

David McBacon
How to Add Advanced CSS Styling to Framer Code Components

Overview

Framer code components are powerful, but they have one limitation: you can't include separate CSS files. This becomes problematic when you need to style pseudo-elements or use vendor-specific properties that don't work with inline styles.

The solution is straightforward: create a multiline string variable for your CSS styles and inject it using a style tag. This gives you the full power of CSS while respecting Framer's file constraints.

Example

export default function Slider() {
  const style = \`
    input[type=range].customSlider {
        -webkit-appearance: none;
    }

    input[type=range].customSlider::-webkit-slider-thumb {
      -webkit-appearance: none;
      background: #f0591a;
      width: 16px;
      height: 16px;
      border-radius: 100%;
      cursor: pointer;
    }
  \`;
  return (
    <>
      <style>{style}</style>
      <input type="range" min={0} max={100} className="customSlider" />
    </>
  );
}

This example shows how to customize a range slider's thumb appearance using -webkit-appearance and pseudo-elements - something impossible with regular inline styling.

This technique essentially embeds a CSS file within your JavaScript, giving you complete styling flexibility within Framer's component structure.

Sign up for the newsletter_

Get notifications about the latest Framer components or templates from BACHOFF Studio directly to your inbox.