Hello, guys in this tutorial we will learn how to make a website like CodePen, How to create a live coding playground
Prism js CDN
Prism Live ( Lightweight, extensible, powerful web-based code editor )
Today we will try to solve out below mentioned query.
- How to make a website like CodePen
- How to create Live Coding Playground
- How to create a live code editor for a website
- How to make a web-based compiler like code pen
First, we need to create three files index.html, style.css and App.js then we need to do code for it.
Website like CodePen Step:1
Add below code inside index.html
<!DOCTYPE html> <html> <head> <title>Live Coding Playground</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="./assets/style.css"> <link href="https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:wght@500&display=swap" rel="stylesheet"> <!-- Need prism CSS for highlight code --> <link rel="stylesheet" href="./prism/css/prism-tomorrow.css"> <link rel="stylesheet" href="./prism/css/prism-live.css"> </head> <body> <div id="coding_playground_outer"> <header id="playground_header"> <h1>live Coding Playground</h1> </header> <div class="page-wrap twilight"> <div class="boxes"> <div id="coding_area"> <textarea id="html" placeholder="HTML" class="prism-live language-html"></textarea> <textarea id="css" placeholder="CSS" class="prism-live language-css"></textarea> <textarea id="js" placeholder="javascript" class="prism-live language-js"></textarea> </div> <div id="code_output"> <iframe id="code"></iframe> </div> </div> </div> </div> <script type="text/javascript" src="./assets/app.js"></script> <!-- Need prism js for highlight code --> <script type="text/javascript" src="./prism/js/prism.js"></script> <script type="text/javascript" src="./prism/js/prism-live.js"></script> </body> </html>
Website like CodePen Step:2
Then we need to add code for style.css which code I provide in the below screen.
* { padding: 0; margin: 0; outline: 0; } header#playground_header { background: #1e1f26; height: 65px; } header#playground_header > h1 { padding: 0; text-align: center; color: #fff; font-weight: 700; height: 100%; display: flex; align-items: center; justify-content: center; font-size: 25px; line-height: 35px; font-family: 'IBM Plex Sans', sens-serif; } iframe#code { bottom: 0; position: relative; width: 100%; height: 40vh; border: unset; background: #f2f4f6; } .prism-live { min-height: 350px; overflow-x: hidden; width: 100%; } div#coding_area > div { width: 100%; border-left: 15px solid #555865; } div#coding_area > div:first-child { border-left: none; } div#coding_area { width: 100%; height: calc(60vh - 60px); min-height: 125px; display: flex; overflow: hidden; border-bottom: 15px solid #555865; } div#code_output { height: 100%; }
Website like CodePen Step:3
then we need to do code for app.js file
function compile(){ var html = document.getElementById("html"); var css = document.getElementById("css"); var js = document.getElementById("js"); var code = document.getElementById("code").contentWindow.document; document.body.onkeyup = function(){ code.open(); code.writeln(html.value+"<style>"+css.value+"</style>" + "<script>"+js.value+"</script>") code.close(); } } compile();
prism-tomorrow.css | prism.js |
prism-live.css | prism-live.js |
Hi Rahul,
Can we add other languages like python, java, php to the online editor.
Yes we can add multiple language.
here you can check supported language.
https://prismjs.com/