
Security News
Insecure Agents Podcast: Certified Patches, Supply Chain Security, and AI Agents
Socket CEO Feross Aboukhadijeh joins Insecure Agents to discuss CVE remediation and why supply chain attacks require a different security approach.
Writing HTML is stupid. It's slow, messy, and should not be done in JavaScript.
The best way to make DOM elements is via document.createElement, but making lots of them with it is tedious.
Crel makes this process easier.
Inspiration was taken from laconic, but Crel wont screw with your bad in-DOM event listeners, and it's smaller, faster, etc...
npm i crel2
let crel = require('crel2');
For AMD:
require.config({paths: { crel: 'crel.min' }});
require(['crel'], (crel) => {
// Your code
});
For standard script tag style:
<script src="crel.min.js"></script>
Syntax:
// Returns a DOM element
crel(tagName / domElement, attributes, child1, child2, childN);
where childN may be:
textNode,null, which will be ignored, orArray containing any of the abovelet element = crel('div',
crel('h1', 'Crello World!'),
crel('p', 'This is crel'),
crel('input', { type: 'number' })
);
// Do something with 'element'
You can add attributes that have dashes or reserved keywords in the name, by using strings for the objects keys:
crel('div', { 'class': 'thing', 'data-attribute': 'majigger' });
You can define custom functionality for certain keys seen in the attributes object:
crel.attrMap['on'] = (element, value) => {
for (let eventName in value) {
element.addEventListener(eventName, value[eventName]);
}
};
// Attaches an onClick event to the img element
crel('img', { on: {
click: () => {
console.log('Clicked');
}
}});
You can pass already available elements to Crel to modify their attributes / add child elements to them
crel(document.body, crel('h1', 'Page title'));
You can assign child elements to variables during creation:
let button;
let wrapper = crel('div',
button = crel('button')
);
You could probably use Crel to rearrange existing DOM elements..
crel(someDiv, crel(someOtherDiv, anotherOne));
But don't.
If you are using Crel in an environment that supports Proxies, you can also use the new API:
let crel = require('crel').proxy;
let element = crel.div(
crel.h1('Crello World!'),
crel.p('This is crel'),
crel.input({ type: 'number' })
);
FAQs
A small, simple, and fast DOM creation utility
We found that crel2 demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?

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.

Security News
Socket CEO Feross Aboukhadijeh joins Insecure Agents to discuss CVE remediation and why supply chain attacks require a different security approach.

Security News
Tailwind Labs laid off 75% of its engineering team after revenue dropped 80%, as LLMs redirect traffic away from documentation where developers discover paid products.

Security News
The planned feature introduces a review step before releases go live, following the Shai-Hulud attacks and a rocky migration off classic tokens that disrupted maintainer workflows.