How to include another HTML file in an HTML file
Codemia Knowledge Hub ·
To include one HTML file in another, use a server-side include (SSI or PHP) when you want the content served as part of the page, or a client-side method (iframe, object, or JavaScript such as jQuery's load()) when you cannot process pages on the server. Includes are typically used for shared headers, footers and navigation bars so the markup is not duplicated across pages.
Using the iframe element
An iframe (inline frame) embeds another HTML document inside the current one. It suits ads, widgets and other external content.
- Pros: Easy to implement; supports content from different origins.
- Cons: Can slow page performance; less SEO-friendly; may have accessibility issues.
Using the object element
The object element is similar to iframe but offers more generic document embedding.
- Pros: An HTML5 standard approach for embedding different types of content.
- Cons: Limited by cross-origin policies; not as widely adopted for all HTML content types.
Using server-side includes (SSI)
SSI directives are placed in HTML pages and evaluated by the server on request. They work well for content shared across many pages, such as headers, footers or menus.
- Pros: Processed on the server, so it is transparent to the client and reduces client-side requests.
- Cons: Requires server configuration (for example, Apache or Nginx must be set up to handle SSI); works only on servers that support it.
Using JavaScript or jQuery
JavaScript, often with jQuery, can load HTML into the page dynamically without a reload.
- Pros: Flexible; good for single-page applications; works client-side.
- Cons: Requires JavaScript on the client; not SEO-friendly unless rendered server-side first.
Using PHP or another server-side language
PHP includes are one of the most common methods in traditional web development.
- Pros: Very efficient; does not depend on client-side capabilities.
- Cons: Tied to the server-side environment; needs a server that can interpret PHP.
Comparing the methods
| Method | Client/Server-Side | SEO Friendly | Usability & Maintainability |
| iframe | Client-side | Poor | Easy |
| object | Client-side | Poor | Moderate |
| SSI | Server-side | Good | Moderate |
| JavaScript/jQuery | Client-side | Poor | Good |
| PHP | Server-side | Good | Excellent |
Choosing a method
- Performance: client-side solutions may render more slowly than server-side ones.
- SEO: some methods do not serve content in a way search engines can easily read.
- Security: make sure included files do not open vulnerabilities such as cross-site scripting (XSS).
The right choice depends on your server resources, security requirements and expected traffic.
Related reading
- Is it possible to add your own WordNet to a library?
- Is it possible to `Embed` Gecko or Webkit in a Windows Form just like a WebView?
- Is it possible to guess a user's mood based on the structure of text?
- Is it possible to visualize keras embeddings in tensorboard?
- Include jQuery in the JavaScript Console
- Infinite recursion in JavaScript quicksort?
- Is there a diff-like algorithm that handles moving block of lines?
- Is there a fast algorithm to remove repeated substrings in a string?
System design interview problems on this topic
- Design Google Doc: solution and walkthrough
- Design Facebook Messenger: solution and walkthrough
- Design Typeahead Suggestion: solution and walkthrough
- Design an Online Presence Indicator Service: solution and walkthrough
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseNo course covers this one yet
Basis Lab writes one for you from a sentence about what you want to be able to do, then teaches it and checks you understood. Your first course is free.
Build my courseML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.