Search code examples
htmlcsshyperlinkhref

How to use href attribute in a link tag accurately in android?


Im trying to link a css file to my html file in android, but when I check the style, it is not being loaded and applied.

I have the css and html files in the same folder, and I have tried with absolute and relative paths, with apostrophes and quotes, but nothing works.

I have tested by providing a link to a stylesheet on the internet.

It works with https, but it does not with files.

I am testing with a Xiaomi Redmi note 5 running Android 9, no frameworks, just loading the HTML file directly into the browser.

HTML FILE:

<html>
<head>
    <title>CSS E</title>
    <link rel="stylesheet" href="main.css">
</head>
<body>
    <p class="par1">
        Sample web page
    </p>
</body>
</html>

CSS FILE:

.par1 {
    color: blue;
}

I've tried additional paths including ./main.css, main.css, file://sdcard/html/main.css and more.

When I load the file in the browser, the search bar shows the next:

content://com.mi.android.globalFileexplorer.myprovider/external_files/HTML/main.html


Solution

  • Your css file is in correct place just load html file from this url:

    file:///sdcard/HTML/main.html