Skip to content Skip to sidebar Skip to footer

HTML Wont Link To CSS File In Visual Studio Code

I am trying to link my css formatting to an HTML document. As you can see, my CSS is link is And my CSS file is titled style.css in a folde

Solution 1:

I would add the attribute type and value "text/css" Your link tag would end up like this:

<link rel="stylesheet" href="css/style.css" type="text/css"

Solution 2:

The question is: Where is your html file? Obviously not in the root folder, but probably in another sub folder. Try this

<link rel="stylesheet" href="../css/style.css" />

This navigates one level up and then into the css folder.


Solution 3:

If you have any project structure with seperate subfolders for ".html" file, ".css" file, ".js" file etc and you are trying to link your ".html" file to ".css" file then:

  • In html file, give the path of your ".css" file in href = "../folderName/filename.css"

    such as: "<link rel="stylesheet" href="../css/main.css"/> "


Solution 4:

If you are loading static file into html then you should mention in html code that you are loading static files explicitly. See the below code:

{% load staticfiles %}
<html>

<head lang="en">

    <title>SuperStore DashBoard</title>
    <meta charset="utf-8" />

    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" type="text/css" href="{% static 'css/superstore.css' %}" />
    <link rel="stylesheet" type="text/css" href="{% static 'css/bootstrap.css' %}" />
    <script src="{% static 'js/bundle.js' %}"></script>
    <script src="{% static 'js/superstore.js' %}"></script>

</head>
<body>
</body>

</html>

These two are css static files

href="{% static 'css/superstore.css' %}"
href="{% static 'css/bootstrap.css' %}" 

These are static javascript files

src="{% static 'js/bundle.js' %}"
src="{% static 'js/superstore.js' %}"

css and js are folder name in visual studio code.

{% load staticfiles %}

You have to mention static files before the start of your html code.


Post a Comment for "HTML Wont Link To CSS File In Visual Studio Code"