Generate a Random Birthday Wishes using JavaScript Last Updated : 18 Apr, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report In this article, we are going to learn how to create a webpage that generates random Birthday wishes using HTML, CSS, and JavaScript.Approach: To generate a random birthday wish we will follow the below-given steps.HTML Code: In this section, we will create a basic structure of the HTML file i.e. it contains <html>, <head>, <body> tags, etc. CSS Code: It is used to set the styles to the HTML document. Here, we set the width, height & position of the document. We will use a CSS media query to set the styles on different sizes of screens.JavaScript Code: Now we want to display a random birthday message to someone and this can be done through JavaScript. In this section, we store all messages in an array variable and then use an array.length property to check the size of the array. After that use math.random() function to generate a random number to display the random message. Example: In this example, we are using the above-explained approach. HTML <html> <head> <title>Page Title</title> </head> <body> <div class="body-bg"></div> <div class="container"> <div class="container-data"> <div id="msg"></div> </div> </div> </body> </html> CSS .body-bg { width: 100%; height: 100%; position: fixed; top: 50%; left: 50%; transform: translateX(-50%) translateY(-50%); background: radial-gradient(#00E7BD, #013A4E); transition: all 0.5s; } .container { width: 80%; height: 80%; position: fixed; top: 50%; left: 50%; transform: translateX(-50%) translateY(-50%); background: linear-gradient(#00E7BD, #013A4E); box-shadow: 0 0 20px 2px #013A4E; } .container-data { padding: 24px; position: absolute; top: 50%; left: 50%; width: 80%; transform: translateX(-50%) translateY(-50%); text-align: center; color: #fff; font-family: Arial; font-size: 3vw; } @media only screen and (max-width: 763px) { .container-data { padding: 24px; position: absolute; top: 50%; left: 50%; width: 80%; transform: translateX(-50%) translateY(-50%); text-align: center; color: #fff; font-family: Arial; font-size: 6vw; } } @media only screen and (max-height: 423px) { .container-data { padding: 24px; position: absolute; top: 50%; left: 50%; width: 80%; transform: translateX(-50%) translateY(-50%); text-align: center; color: #fff; font-family: Arial; font-size: 4vw; } } JavaScript let messages = ["Happy birthday to GFG", "Happy birthday to GeeksforGeeks", "Happy birthday to Geeks"]; let i = messages.length; let s = Math.floor(Math.random() * i); document.getElementById("msg") .innerHTML = '" ' + messages[s] + ' "'; Output Comment More infoAdvertise with us Next Article Generate a Random Birthday Wishes using JavaScript N NavdeepSharma Follow Improve Article Tags : JavaScript Web Technologies JavaScript-Projects Similar Reads How to Generate a Random Boolean using JavaScript? To generate a random boolean in JavaScript, use Math.random(), which returns a random number between 0 and 1.Approach: Using Math.random() functionCalculate Math.random() function.If it is less than 0.5, then true otherwise false.Example 1: This example implements the above approach. JavaScript// Fu 1 min read Random Image Generator using JavaScript In this article, we will learn how to generate random images in fixed intervals using only HTML, CSS, and JavaScript.Approach: The pictures that are going to be generated randomly on the website should be stored in the form of an array; these pictures are then displayed to the user within a regular 4 min read Random String Generator using JavaScript A Random String Generator is a small program that creates a string (a set of characters) made up of random letters, numbers, and/or symbols. These random strings are useful in many places like:Creating temporary passwordsGenerating unique IDsMaking test dataCreating captcha codesApproaches to Genera 3 min read Generate random alpha-numeric string in JavaScript In this article with the help of javascript we are generating the alpha-numeric string of specific length using javascript, here are some common method Approach 1: Creates a function that takes 2 arguments one is the length of the string that we want to generate and another is the characters that we 2 min read How to Generate a Random Password using JavaScript? Creating a random password generator is an excellent beginner-friendly project that can be useful in real-world applications. Passwords are vital for securing accounts, and strong, randomized passwords enhance security significantly. How to Generate a Random Password using JavaScriptWhat We're Going 5 min read Like