hahaha514
hahaha514

Reputation: 45

How to add icon to title bar

I am trying to make web application and i need to add an icon to my title bar with a name.

I am making the web application using empty project in MVC with web form included. I am doing the coding using Visual studio 2017. I have tried my layout as below so far.

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<link href="~/Content/nav.css" rel="stylesheet" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="icon" type="image/svg" href="~/Content/img/download.png" />
<script src="~/Scripts/layout.js"></script>
<title>@ViewBag.Title</title>
</head>

<body>
<navbar>
    <div class="topnav" id="myTopnav">
        <a href="Home/Index">Home</a>
        <a href="Login/login">Login</a>
        <a href="Payment/Payment"> Payment </a>
        <a href="Register/register">Customer Registration</a>
        <a href="javascript:void(0);" class="icon" onclick="myfunction()">
            <i class="fa fa-bars"></i>
        </a>
    </div>
    <div>
        @RenderBody()
    </div>
</navbar>  
</body>
</html>

I have tried to link the image before title but it took a wrong turn. Since I am new to MVC, please give me some method to add an icon to title bar.

Upvotes: 4

Views: 4923

Answers (2)

The problem lays in this code:

<link rel="icon" type="image/svg" href="~/Content/img/download.png" />

You are specifying that the type is image/svg while instead it is a image/png.

Be sure that a png image exists in Content/img folder.

Upvotes: 0

Rob
Rob

Reputation: 11798

What you are looking for is called a favicon. You can generate it from png or whatever and then include it in your page like this:

<link rel="icon" href="/favicon.ico" type="image/x-icon">

Here's a favicon generator (one of many): https://www.favicon-generator.org/

Upvotes: 1

Related Questions