Learn how to integrate FSCSS into your HTML projects using different methods for various use cases.
The simplest way to include FSCSS in your HTML projects.
Create a file with the .fscss extension (e.g., styles.fscss
) and add your FSCSS code.
/* Variables */ $primary-color: midnightblue; $bg-stack: #FF9955 url(image.png) no-repeat center; $border: 1px solid #4CAF50; /* Body element styling */ Body { Background: linear-gradient(30deg, #111, #000); color: $primary-color!; } /* Select by name attribute */ $(name: foo) { Background: $bg-stack!; Border: $border!; %2(width, height[:200px;]) }
In your HTML file, use a <link>
tag with type="text/fscss"
and include the FSCSS execution script.
<!DOCTYPE html> <html> <head> <title>FSCSS Example</title> <!-- FSCSS file --> <link href="styles/style.fscss" rel="stylesheet" type="text/fscss"> <!-- FSCSS execution script --> <script src="https://cdn.jsdelivr.net/npm/fscss@1.1.6/e/exec.js" async></script> </head> <body> <div name="foo"> This div will be styled by FSCSS. </div> <!-- Regular CSS still works --> <style> body { font-family: sans-serif; } </style> </body> </html>
type="text/fscss"
to identify the file for processingFor more control, especially with dynamic loading or error handling.
Good for simple projects without module systems.
<!DOCTYPE html> <html> <head> <title>FSCSS JavaScript Load</title> </head> <body> <div name="card" class="card"> This is a card styled with FSCSS. </div> <!-- Load FSCSS execution script --> <script src="https://cdn.jsdelivr.net/npm/fscss@1.1.6/e/exec.js"></script> <script> // Call the exec function after loading exec({ type: 'URL', content: 'styles/style.fscss', onSuccess: (styleElement) => { console.log('CSS applied:', styleElement); }, onError: (msg) => { console.warn('Error applying CSS:', msg); } }); </script> </body> </html>
Better for applications using JavaScript modules.
<!DOCTYPE html> <html> <head> <title>FSCSS ES Module Load</title> </head> <body> <div name="card" class="card"> Another card styled with FSCSS. </div> <script type="module"> // Import the exec function import { exec } from "https://cdn.jsdelivr.net/npm/fscss@1.1.6/e/xfscss.min.js"; // Call the exec function exec({ type: 'URL', content: 'styles/style.fscss', onSuccess: (styleElement) => { console.log('CSS applied:', styleElement); }, onError: (msg) => { console.warn('Error applying CSS:', msg); } }); </script> </body> </html>
A robust implementation for production applications.
import { exec } from "https://cdn.jsdelivr.net/npm/fscss@1.1.6/e/xfscss.min.js"; // Set to false for production const DEBUG = true; function applyFSCSS({ type, content }) { exec({ type, content, onSuccess: (styleElement) => { if (DEBUG) { console.log("✅ FSCSS applied successfully:", styleElement); } }, onError: (error) => { console.error("❌ Failed to apply FSCSS:", error); // User-friendly error message const errorElement = document.createElement('div'); errorElement.style.cssText = ` position: fixed; top: 20px; right: 20px; padding: 15px; background: #ff4757; color: white; border-radius: 5px; z-index: 1000; max-width: 300px; `; errorElement.innerHTML = ` <strong>⚠️ Style Error</strong> <p>Could not load styles. Please try again later.</p> `; document.body.appendChild(errorElement); // Remove error after 5 seconds setTimeout(() => { errorElement.remove(); }, 5000); } }); } // Example usage: applyFSCSS({ type: "URL", content: "styles/main.fscss" });
type="text/fscss"
is requiredWhen to use:
When to use: