Thursday, February 15, 2024
HomeCSSLearn How to Create a Random Emoji Generator using HTML, CSS and...

Learn How to Create a Random Emoji Generator using HTML, CSS and JavaScript | Beginner JavaScript Project

Hello Future Coders, Welcome to my blog. Today in this article I am going to teach you how to create a random emoji generator using html, css and javascript. This is going to be a Beginner JavaScript Project.

This project us going to be very simple. When user clicks on the generate button, we will generate a random emoji which will be displayed in the browser window.

As you know that our blog teaches coding using both video tutorials as well as an step by step article. So, below I have provided both video tutorial as well as the step by step article. And you can also download the source code of this project by clicking on the download button at the end of this article.

Random Emoji Generator | JavaScript Project | Video Tutorial

How to Create a Random Emoji Generator | HTML, CSS, JavaScript Project | Step by Step Tutorial

Create three files: index.html, styes.css, script.js. Make sure you link them together inside your html using link and script tag.

Step 1: Setting up the HTML

For the html, First add the boiler plate of the html and now we will create a container div. Inside that we will have our title, and placeholder to display the emoji generated and a generate button which triggers a javascript function getRandomEmoji() that generates a random emoji.

<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>1 Random Emoji Generator</title>
    <link rel="stylesheet" href="styles.css" />
    <div class="container">
      <h2>Random Emoji Generator</h2>
      <p id="emoji-container"></p>
      <button onclick="getRandomEmoji()">Generate</button>
    <script src="script.js"></script>

Step 2: Styling with CSS

Now its time to style, Below I have provided the css code which i used to style. Feel free to change the styling to whatever you like.

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  border: none;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;

body {
  background-color: aliceblue;
  padding: 5rem 0;

.container {
  max-width: 900px;
  margin: 0 auto;
  background-color: #fff;
  padding: 3rem;
  border-radius: 0.5rem;
  box-shadow: rgba(100, 100, 111, 0.2) 0px 7px 29px 0px;
  text-align: center;

.container h2,
.container p,
.container button {
  margin-bottom: 1rem;

.container p {
  font-size: 10rem;

.container button {
  font-size: 1rem;
  padding: 0.5rem 1rem;
  border-radius: 0.5rem;
  background-color: #000;
  color: #fff;
  cursor: pointer;

Step 3: Creating the JavaScript Function

First we create an array of all the possible emojis. Now inside our getRandomEmoji() function, using Math object we will first create a random number which is between 0 and the length of the array. Then using that randomly generated number, we will use it as an array index to get that emoji which is present at that index. Thats it.

const emojis = ["๐Ÿ˜€", "๐Ÿ˜ƒ", "๐Ÿ˜„", "๐Ÿ˜", "๐Ÿ˜†", "๐Ÿ˜…", "๐Ÿคฃ", "๐Ÿ˜‚", "๐Ÿ™‚", "๐Ÿ™ƒ", "๐Ÿ˜‰", "๐Ÿ˜Š", "๐Ÿ˜‡", "๐Ÿฅฐ", "๐Ÿ˜", "๐Ÿคฉ", "๐Ÿ˜˜", "๐Ÿ˜—", "๐Ÿ˜š", "๐Ÿ˜™", "๐Ÿ˜‹", "๐Ÿ˜›", "๐Ÿ˜", "๐Ÿ˜œ", "๐Ÿคช", "๐Ÿคจ", "๐Ÿง", "๐Ÿค“", "๐Ÿ˜Ž", "๐Ÿคฉ", "๐Ÿฅณ", "๐Ÿ˜", "๐Ÿ˜’", "๐Ÿ˜ž", "๐Ÿ˜”", "๐Ÿ˜Ÿ", "๐Ÿ˜•", "๐Ÿ™", "โ˜น๏ธ", "๐Ÿ˜ฃ", "๐Ÿ˜–", "๐Ÿ˜ซ", "๐Ÿ˜ฉ", "๐Ÿฅบ", "๐Ÿ˜ข", "๐Ÿ˜ญ", "๐Ÿ˜ค", "๐Ÿ˜ ", "๐Ÿ˜ก", "๐Ÿคฌ", "๐Ÿคฏ", "๐Ÿ˜ณ", "๐Ÿฅต", "๐Ÿฅถ", "๐Ÿ˜ฑ", "๐Ÿ˜จ", "๐Ÿ˜ฐ", "๐Ÿ˜ฅ", "๐Ÿ˜“", "๐Ÿค—", "๐Ÿค”", "๐Ÿคญ", "๐Ÿคซ", "๐Ÿคฅ", "๐Ÿ˜ถ", "๐Ÿ˜", "๐Ÿ˜‘", "๐Ÿ˜ฌ", "๐Ÿ™„", "๐Ÿ˜ฏ", "๐Ÿ˜ฆ", "๐Ÿ˜ง", "๐Ÿ˜ฎ", "๐Ÿ˜ฒ", "๐Ÿ˜ด", "๐Ÿคค", "๐Ÿ˜ช", "๐Ÿ˜ต", "๐Ÿค", "๐Ÿฅด", "๐Ÿคข", "๐Ÿคฎ", "๐Ÿค•", "๐Ÿฅณ", "๐Ÿ˜ท", "๐Ÿค’", "๐Ÿค•", "๐Ÿค‘", "๐Ÿค ", "๐Ÿ˜ˆ", "๐Ÿ‘ฟ", "๐Ÿ‘น", "๐Ÿ‘บ", "๐Ÿ’€", "๐Ÿ‘ป", "๐Ÿ‘ฝ", "๐Ÿค–", "๐Ÿ’ฉ", "๐Ÿ˜บ", "๐Ÿ˜ธ", "๐Ÿ˜น", "๐Ÿ˜ป", "๐Ÿ˜ผ", "๐Ÿ˜ฝ", "๐Ÿ™€", "๐Ÿ˜ฟ", "๐Ÿ˜พ"]

function getRandomEmoji() {
  let emoji = emojis[Math.floor(Math.random() * emojis.length)]
  document.getElementById("emoji-container").textContent = emoji


So, Congratulations on completing this project. Feel free to watch the video tutorial to understand it better. Thank You, and will see you in the next project.



Please enter your comment!
Please enter your name here

Latest Posts