Design Joke Generator App in HTML CSS & JavaScript Last Updated : 23 Jul, 2025 Comments Improve Suggest changes Like Article Like Report We will go to learn how can we create a Joke generator app using HTML, CSS, and JavaScript. We will also add a feature to copy the generated joke. We will use API to fetch the jokes and will show those jokes on the screen. PrerequisitesHTMLCSSJavaScriptApproachCreate the Joke Generator Application UI Structure using HTML Elements like <div>, <h1>, <button>. Then link all the required CDNs for external fonts and icons. Once we design the structure of the application, then we can style the elements and the application using CSS properties for a responsive and attractive layout with different properties like width, padding, height, etc.In the JavaScript code, as we are fetching the Joke from the external API, we need to define the function jokeFn() which requests the External API for the joke and once the joke is received, it is displayed in the Application's UI.The cpyFn() allows us to copy the generated Joke to the clipboard for further use. Example: This example describes the basic implementation for a Joke generator App in HTML, CSS & JavaScript. HTML <!DOCTYPE html> <html lang="en"> <head> <link rel="stylesheet" href= "https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css"> <link rel="stylesheet" href="style.css"> <title>Joke Generator</title> </head> <body> <div class="container"> <div class="joke-container animate__animated animate__fadeIn"> <h1 class="app-title">GeeksforGeeks Joke Generator</h1> <i class="laugh-icon"></i> <p id="jokeText">Loading joke...</p> <button id="newJokeBtn"><i class="random-icon"> </i> New Joke</button> <button id="copyJokeBtn"><i class="copy-icon"> </i> Copy Joke</button> </div> </div> <script src="script.js"></script> </body> </html> CSS body { margin: 0; padding: 0; font-family: 'Montserrat', sans-serif; background: linear-gradient(to right, #3494E6, #EC6EAD); height: 100vh; display: flex; align-items: center; justify-content: center; } .container { text-align: center; } .app-title { color: #4CAF50; font-size: 32px; margin-bottom: 20px; } .joke-container { padding: 20px; background: #fff; border-radius: 10px; width: 60%; height: 60%; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); margin: 20px; overflow: hidden; } .laugh-icon, .random-icon, .copy-icon { font-size: 20px; margin-bottom: 10px; color: #FFD700; } #jokeText { font-size: 18px; color: #555; margin: 20px 10px; } button { padding: 12px 30px; font-size: 18px; background: #FF4848; color: #fff; border: none; border-radius: 5px; margin: 20px 10px; cursor: pointer; transition: background 0.3s ease-in-out; } button:hover { background: #FF6565; } @media screen and (max-width: 600px) { .joke-container { width: 90%; } } JavaScript const joke = document.getElementById('jokeText'); const jokeBtn = document.getElementById('newJokeBtn'); const cpyBtn = document.getElementById('copyJokeBtn'); jokeBtn.addEventListener('click', jokeFn); cpyBtn.addEventListener('click', cpyFn); jokeFn(); function jokeFn() { fetch('...') .then(response => response.json()) .then(data => { joke.textContent = data.joke; }) .catch(error => { console.error('Error fetching joke:', error); joke.textContent = 'Failed to fetch joke. Please try again.'; }); } function cpyFn() { const textArea = document.createElement('textarea'); textArea.value = joke.textContent; document.body.appendChild(textArea); textArea.select(); document.execCommand('copy'); document.body.removeChild(textArea); alert('Joke copied to clipboard!'); } Output: Design Joke Generator App in HTML CSS & JavaScript Comment More info G gpancomputer Follow Improve Article Tags : Project JavaScript Web Technologies Dev Scripter JavaScript-Projects Dev Scripter 2024 +2 More Explore JavaScript BasicsIntroduction to JavaScript4 min readVariables and Datatypes in JavaScript6 min readJavaScript Operators5 min readControl Statements in JavaScript4 min readArray & StringJavaScript Arrays7 min readJavaScript Array Methods7 min readJavaScript Strings6 min readJavaScript String Methods9 min readFunction & ObjectFunctions in JavaScript5 min readJavaScript Function Expression3 min readFunction Overloading in JavaScript4 min readObjects in Javascript4 min readJavaScript Object Constructors4 min readOOPObject Oriented Programming in JavaScript3 min readClasses and Objects in JavaScript4 min readWhat Are Access Modifiers In JavaScript ?5 min readJavaScript Constructor Method7 min readAsynchronous JavaScriptAsynchronous JavaScript2 min readJavaScript Callbacks4 min readJavaScript Promise4 min readEvent Loop in JavaScript4 min readAsync and Await in JavaScript2 min readException HandlingJavascript Error and Exceptional Handling6 min readJavaScript Errors Throw and Try to Catch2 min readHow to create custom errors in JavaScript ?2 min readJavaScript TypeError - Invalid Array.prototype.sort argument1 min readDOMHTML DOM (Document Object Model)9 min readHow to select DOM Elements in JavaScript ?3 min readJavaScript Custom Events4 min readJavaScript addEventListener() with Examples9 min readAdvanced TopicsClosure in JavaScript4 min readJavaScript Hoisting6 min readJavascript Scope3 min readJavaScript Higher Order Functions7 min readDebugging in JavaScript4 min read Like