0

I have a basic index.html file in a folder, as well as many, many other files. I want them all to use the same CSS file, without having to manually add to every file. I was wondering if you renamed the file index.css or something like that it would automatically load into every HTML file in the folder? Out of curiosity, is there also a Javascript method for this too?

4
  • 3
    No, there's no magical file name that would include your CSS file in your HTML files. Commented May 8, 2017 at 16:14
  • 2
    is there also a Javascript method for this too - this would only replace your current problem with a new one: Adding javascript code to every single html file Commented May 8, 2017 at 16:15
  • Webpack's extract text plugin inserts a style tag into your index.html file as part of the bundling process. I have never used this with multiple html files as I mainly work with SAPS / components. Maybe look it up? probably overkill for what you are looking for though! Commented May 8, 2017 at 16:19
  • The best ways that are available would be using include or doing a bulk search and replace I guess. Commented May 8, 2017 at 16:50

2 Answers 2

1

Bad news my friend No. There is no magical tool that will import the CSS into all of your files. You have to do it yourself. Also it's really easy

  1. Get the CSS file
  2. Import the CSS File

See it's that easy. Was it so hard to do it?

Sign up to request clarification or add additional context in comments.

2 Comments

Partials to the rescue ;)
I mostly wanted just to see if it is possible. I'm fine to copy paste, but it would be useful in some cases.
1

You can't do that with simple HTML.

Do a PHP template instead, basically with:

  • head
  • header
  • nav menu
  • a content/container div/section
  • footer

Then, include your HTML/PHP page in your content.

For instance, use $_GET or $_POST to know which page to include.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.