Emojis in HTML

Adding Emojis in HTML - Codes With Pankaj

Welcome to codes with pankaj! In this tutorial, we’ll cover different methods for adding emojis to your HTML pages, from using emoji Unicode to direct emoji copy-pasting and even embedding emojis using images.

Why Use Emojis in HTML?

Emojis can make your content feel friendlier, more expressive, and visually appealing. You can use emojis to add emphasis, make buttons more interactive, and communicate ideas with minimal text.


Method 1: Using Emoji Unicode

Each emoji has a unique Unicode character that you can use directly in HTML. Let’s see how to add emojis using Unicode.

Step 1: Find the Unicode for an Emoji

  1. Search for your emoji on a site like Emojipedia.

  2. Find the Unicode (usually a code starting with U+ followed by numbers or letters).

For example:

  • πŸ˜ƒ (Grinning Face) has a Unicode of U+1F603.

  • ❀️ (Red Heart) has a Unicode of U+2764.

Step 2: Add the Emoji Unicode in HTML

To add Unicode in HTML, replace U+ with &#x; followed by the code. End it with a ;.

Example

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Using Emoji Unicode in HTML</title>
</head>
<body>

    <h2>Using Emoji Unicode</h2>
    <p>Smiling Face: &#x1F603;</p>
    <p>Red Heart: &#x2764;</p>
    <p>Thumbs Up: &#x1F44D;</p>

</body>
</html>

In this example:

  • The code &#x1F603; produces a smiling face emoji 😊.

  • You can place emojis in headings, paragraphs, buttons, and any other HTML text.


Method 2: Direct Copy-Paste of Emojis

If you prefer a quicker method, you can directly copy and paste emojis into your HTML. Most modern browsers and devices support emojis, so this approach is simple and reliable.

Example

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Direct Emoji Copy-Paste</title>
</head>
<body>

    <h2>Direct Copy-Paste Method</h2>
    <p>Smiling Face 😊</p>
    <p>Red Heart ❀️</p>
    <p>Thumbs Up πŸ‘</p>

</body>
</html>

In this example:

  • Simply paste emojis like 😊, ❀️, and πŸ‘ directly into the HTML code.

Tip: This method is ideal when you want to quickly add a few emojis without worrying about Unicode.


Method 3: Using alt Attribute in HTML Images

If you want more control over emoji size and appearance, you can use image files of emojis. This method is helpful if you're using custom emoji designs or need consistency across all devices.

Example

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Emoji with Images</title>
</head>
<body>

    <h2>Adding Emojis with Images</h2>
    <p>
        Smile Emoji:
        <img src="smile.png" alt="😊" width="24" height="24">
    </p>
    <p>
        Heart Emoji:
        <img src="heart.png" alt="❀️" width="24" height="24">
    </p>

</body>
</html>

In this example:

  • Replace smile.png and heart.png with the paths to your emoji images.

  • Set the alt attribute to provide a text-based emoji fallback if the image doesn’t load.

  • Use width and height to control emoji size.

Tip: Using images ensures your emojis look the same across all browsers and operating systems, which can be important for branding or design consistency.


Emojis are versatile and can be used within links, buttons, and even HTML titles.

Example

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Emoji in HTML Elements</title>
</head>
<body>

    <h2>Using Emojis in Various HTML Elements</h2>
    
    <!-- Emoji in Links -->
    <p>Visit our website 🌐: <a href="https://example.com">Go to Example</a></p>
    
    <!-- Emoji in Button -->
    <button type="button">Submit ❀️</button>
    
    <!-- Emoji in Headings -->
    <h1>Welcome to Our Page πŸŽ‰</h1>

</body>
</html>

In this example:

  • Use emojis to make links, buttons, and headings more engaging.

  • Since emojis are Unicode characters, they can be used almost anywhere within text-based HTML elements.

Let's enhance the tutorial by including a table of popular UTF-8 emojis with their hexadecimal and decimal codes. This table will help you easily incorporate specific emojis using their codes.


HTML Emojis with UTF-8 Code Table


UTF-8 Emoji Code Table

Emoji
Hexadecimal Code
Decimal Code

😈

&#x1F608;

&#128520;

πŸ˜‚

&#x1F602;

&#128514;

πŸ‘

&#x1F44D;

&#128077;

😁

&#x1F601;

&#128513;

πŸ˜ƒ

&#x1F603;

&#128515;

πŸ˜‡

&#x1F607;

&#128519;

πŸ˜‰

&#x1F609;

&#128521;

😍

&#x1F60D;

&#128525;

😭

&#x1F62D;

&#128557;

😘

&#x1F618;

&#128536;

😒

&#x1F622;

&#128546;

πŸ™‚

&#x1F642;

&#128578;

πŸ˜ͺ

&#x1F62A;

&#128554;

😷

&#x1F637;

&#128567;


How to Use Emoji Codes in HTML

  1. Hexadecimal Code: Use the format &#xHEXCODE;. For example, &#x1F602; will display πŸ˜‚.

  2. Decimal Code: Use the format &#DECIMALCODE;. For example, &#128514; will also display πŸ˜‚.

Example

Here’s how to use these codes within your HTML:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Using UTF-8 Emoji Codes</title>
</head>
<body>

    <h2>Using Emoji Codes</h2>
    <p>Grinning Face with Smiling Eyes 😁: Hexadecimal - &#x1F601; | Decimal - &#128513;</p>
    <p>Thumbs Up πŸ‘: Hexadecimal - &#x1F44D; | Decimal - &#128077;</p>
    <p>Red Heart ❀️: Hexadecimal - &#x2764; | Decimal - &#10084;</p>
    <p>Face with Tears of Joy πŸ˜‚: Hexadecimal - &#x1F602; | Decimal - &#128514;</p>

</body>
</html>

In this example:

  • Both hexadecimal and decimal codes are used to display emojis.

  • Experiment with codes from the table above to enhance your content with your favorite emojis.

With these UTF-8 emoji codes, you have a flexible, easy way to add expressive characters directly into HTML!


Conclusion

In this tutorial, we explored different methods for adding emojis to HTML:

  1. Unicode for flexible control.

  2. Direct copy-pasting for quick usage.

  3. Images for customized emoji design.

  4. Embedding emojis in various HTML elements for added interaction.

With these techniques, you can use emojis creatively on your website to add visual interest and clarity. Experiment with emojis to enhance your site’s design and engagement!

Happy coding!

Last updated