Search code examples
htmlcssbootstrap-4font-awesome-5

How can we use Font Awesome Icon in CSS? I want to display an icon after heading


How can we use Font Awesome Icon in CSS? I want to display an icon after heading. I want to customize my headings a little bit so it would have an icon after the heading.

Here is My Code

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="https://pro.fontawesome.com/releases/v5.10.0/css/all.css"
        integrity="sha384-AYmEC3Yw5cVb3ZcuHtOA93w35dYTsvhLPVnYs9eStHfGJvOvKxVfELGroGkvsg+p" crossorigin="anonymous" />

    <title>Test</title>

    <style>
        * {
            margin: 0;
            padding: 0%;
            box-sizing: border-box;
        }

        .main-div {
            width: 100vw;
            height: 100vh;
            padding-top: 100px;
            text-align: center;
        }

        h1 {
            color: #2980b9;
            font-size: 5rem;
        }

        h1::after {
            font-family: "Font Awesome 5 Free";
            font-weight: 900;
            content: "\f007";
            width: 20vh;
            height: 25px;
            color: #1abc9c;
            font-size: 3rem;
            display: inline-block;
            margin: 0 auto;
        }
    </style>
</head>

<body>
    <section class="main-div">
        <h1>Test</h1>
    </section>
</body>

</html> 

But, the icon is not showing up. Also, how to display that icon using css?

Any help would be highly appreciated!


Solution

  • You can replace Font Awesome 5 Free by Font Awesome 5 Pro

    Your code look like that :

    <!DOCTYPE html>
    <html lang="en">
    
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <link rel="stylesheet" href="https://pro.fontawesome.com/releases/v5.10.0/css/all.css"
            integrity="sha384-AYmEC3Yw5cVb3ZcuHtOA93w35dYTsvhLPVnYs9eStHfGJvOvKxVfELGroGkvsg+p" crossorigin="anonymous" />
    
        <title>Test</title>
    
        <style>
            * {
                margin: 0;
                padding: 0%;
                box-sizing: border-box;
            }
    
            .main-div {
                width: 100vw;
                height: 100vh;
                padding-top: 100px;
                text-align: center;
            }
    
            h1 {
                color: #2980b9;
                font-size: 5rem;
            }
    
            h1::after {
                font-family: "Font Awesome 5 Pro";
                font-weight: 900;
                content: "\f007";
                width: 20vh;
                height: 25px;
                color: #1abc9c;
                font-size: 3rem;
                display: inline-block;
                margin: 0 auto;
            }
        </style>
    </head>
    
    <body>
        <section class="main-div">
            <h1>Test</h1>
        </section>
    </body>
    
    </html>