Ask coding questions

← Back to all posts
html question
paulinbacana (1)

Hello guys, can someone tell me if i can create one .html file and call this file to my index.html??? (sorry for bad english 😅)

notGilbert (121)

You need to use <a> (anchor) not the <link> tag.

<link> is basically metadata to include things like preloading and stylesheets

<a href="/path/to/file.html">This is a link</a>

this would create a clickable link that will bring you to another page

paulinbacana (1)

@notGilbert I'm not tring to do this, but thanks to try help me :)

notGilbert (121)

@paulinbacana ohh.. do you mean like copying and pasting the file into index.html?

You can:

  • use a web framework like ejs or danjo (requires extra setup)

  • use some Javascript:

// this is the element to put the HTML in
const element = document.querySelector('body');

// this will fetch the HTML from the file and then put it inside that element
fetch('/path/to/file.html').then(async r => {
  element.innerHTML = await r.text();

Uh no... you can put all your html in one file. If you want to use html extending like you seem to be trying to do here, you can use a web framework, like flask or django, and use html extending from there.

paulinbacana (1)

@LAMAQDAHODWALA I don't know how to do this, so i'm thinking to put the body tag in the index.html file