1. Home
  2. Handbook
  3. Relative paths for offline apps

// handbook · prepare your files

Relative paths: making a website work from inside an APK

On a web server, a path that starts with a slash means "from the top of this website". Inside an app, there is no website root — so those paths point at nothing.

updated · 3 min read · APK Builder team

Short answerInside an HTML/ZIP app, use relative paths: write css/app.css or ./img/logo.png instead of /css/app.css. Relative paths resolve from the current file, so they work wherever the folder is stored. Set your framework's base path to ./ before building.

Absolute vs relative, side by side

Written asOn a web serverInside an APK
/img/logo.pngWorksBreaks — no site root
img/logo.pngWorksWorks
./img/logo.pngWorksWorks
../img/logo.png (from a subfolder)WorksWorks
https://cdn.example.com/lib.jsWorksOnly with internet

Where to look

  • HTML: src=", href=", srcset=", poster=".
  • CSS: url( in backgrounds and @font-face. Paths in CSS are relative to the CSS file, not the page.
  • JavaScript: image paths in strings, fetch(), new Audio('…'), and router links.
  • Manifest and icons: manifest.json and favicon links (harmless, but tidy them).

Framework settings

ToolSetting
Vitebase: './' in vite.config.js
Create React App"homepage": "." in package.json
Vue CLIpublicPath: './'
Angularng build --base-href ./
Astro / static generatorsRelative links or a build plugin; check the output HTML

Single-page apps should also use hash routing (#/about) instead of history routing (/about), because there is no server to send every path back to index.html.

Link to files, not folders: about.html or about/index.html, never about/. A web server quietly adds index.html for you; an app's file loader may not.

Find absolute paths quickly

Search your project for these patterns; every match is a candidate to fix:

src="/        href="/        url(/        url("/
fetch('/      fetch("/       import '/      "/assets/

Most code editors can search a whole folder at once. Replace "/ with " (or "./) only where the path points to your own files — leave https:// links alone.

Pages in subfolders

Relative paths are relative to the page that uses them. A page at guides/start.html must reach the stylesheet with ../css/app.css, not css/app.css. If your site has many folders, keep all pages at the top level, or use a static-site generator option that writes relative links for you.

Letter case matters on phones

Windows and macOS usually ignore letter case in file names, so Logo.png and logo.png are the same file on your computer. Inside an APK they are different, and the wrong one simply doesn't load. Rename everything to lower case and match the paths exactly — this one change fixes a surprising number of "works on my computer" reports.

Test the way the app will load it

Open index.html by double-clicking it rather than through a local server. If every image, font and page loads from the plain file, it will load inside the app too.

Questions

Why do relative paths work in an APK when absolute ones don't?

Absolute paths start from the website root, which doesn't exist inside an app. Relative paths start from the current file, so they work wherever the folder lives.

Are paths in CSS relative to the page?

No. url() in a CSS file is relative to the CSS file itself.

Should a React or Vue app use hash routing in an APK?

Yes. Hash routes (#/page) work without a server; history routes need one.

Read next

// ready when you are

Build your APK — free.

No Android Studio, no code, no watermark. Pick your input: