A compact (< 1Kb) snippet to get the benefits of Lorem Ipsum, without the clutter of having Ipsum in the code.

The snippet executes on the DOMContentLoaded event and will fill any elements having an ipsum attribute with Ipsum automatically. Instead of adding Lorem Ipsum inside of the elements you want to flesh out, simply add an ipsum="N" attribute to that element, where N is the number of words to generate.

document.addEventListener('DOMContentLoaded', () =>
	const ipsum = ['amet','arcu','auctor','bibendum','commodo','congue','cursus','donec','duis','eget','elementum','enim','eu','fusce','gravida','in','ipsum','justo','leo','ligula','lorem','maecenas','magna','mattis','metus','nibh','non','nulla','orci','ornare','pellentesque','porta','porttitor','quam','quisque','risus','rutrum','sagittis','sapien','sit','sodales','tellus','tempus','ultricies','urna','ut','vitae','vulputate'];

	for(let node of document.querySelectorAll('[ipsum]'))
		let str	= '';

		for(let j = 0, jj = parseInt(node.getAttribute('ipsum')); j < jj; j++)
			str += ipsum[Math.floor(Math.random() * ipsum.length)] + ' ';

		node.innerText = str;
}, false);

This code snippet was published on It was last edited on

Contributing Authors



  • Votes
  • Oldest
  • Latest