I cannot save web pages correctly as HTML or MHTML files if the page contains icons or other glyphs that appear in DevTools as follows, for example: <span class="webicon"> ::before </span> .webicon::before { content: ""; } When I open a saved HTML/MHTML file in a browser (Edge), there is always an empty square where the icon should be. Please tell me how I can save a website as HTML/MHTML so that the icons mentioned above are displayed correctly when I open the saved HTML/MHTML file in a browser. Note: I don't want to use browser add-ons or other external tools, only the native features of the browser and Windows 10.
PHIND-70B MODELThe issue you're experiencing occurs because pseudo-elements with custom Unicode characters (like ) require specific font loading conditions that aren't preserved when saving pages normally. Here are several methods to ensure these icons display correctly:
Method 1: Manual Font Embedding
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">@font-face {
font-family: 'WebIcons';
src: url('path/to/font-file.eot');
/* Add other formats if available */
}Method 2: Base64 Encoding
$base64 = [Convert]::ToBase64String((Get-Content -Path "font-file.ttf" -Encoding Byte))@font-face {
font-family: 'WebIcons';
src: url(data:font/truetype;charset=utf-8;base64,$base64);
}Method 3: Local Font Override
Important Notes:
- Always verify the correct character encoding is specified
- Ensure the font files are accessible locally
- Test the saved pages in multiple browsers
- Some websites may require additional resources beyond just fonts
These methods work without requiring browser add-ons or external tools, using only native Windows 10 features. The base64 method is particularly reliable as it embeds the font directly in the file, eliminating dependency on external resources.
Sources
In Microsoft Edge there is no way to save web pages and html...
learn.microsoft.comRight-click a file name and then select 'Save for overrides'...
learn.microsoft.comIf I wanted to save the font files used by the website as local fonts files, how would I need to change the method #1?
PHIND-70B MODELTo save font files locally using Method #1, here's how to modify the process:
Modified Steps for Method #1
- Right-click → Save as...
- Choose a location (e.g.,
C:\Fonts\WebsiteFonts) - Name it appropriately (e.g.,
site-icons.ttf)
<head>
<!-- Add early in head -->
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style>
@font-face {
font-family: 'SiteIcons';
src: local('SiteIcons'),
url('./site-icons.ttf') format('truetype'),
url('./site-icons.woff2') format('woff2'),
url('./site-icons.woff') format('woff');
}
.webicon::before {
font-family: 'SiteIcons';
content: "";
}
</style>
</head>Directory Structure
your-saved-page/
├── index.mhtml
├── site-icons.ttf
├── site-icons.woff2
└── site-icons.woffImportant Considerations
- Font Format Support:
- Include multiple formats for better browser compatibility
- WOFF2 is recommended for modern browsers
- TTF/EOT for older browser support
- Font Loading Strategy:
local('SiteIcons')tries system fonts first- Falls back to local files if needed
- Always test in multiple browsers
- Troubleshooting Tips:
- Verify font file permissions
- Check file path case sensitivity
- Ensure correct MIME types in CSS
- Test with different browsers
Excuse me, but if I save the fonts in the C:\Fonts\WebsiteFonts folder and the web page in a different folder, don't I have to include the full directory paths in the @font-face URL specifications? For example, url('C:/Fonts/WebsiteFonts/site-icons.ttf') format('truetype')) instead of url('./site-icons.ttf') format('truetype')?
PHIND-70B MODELYes, you're absolutely right! When storing fonts in a separate directory like C:\Fonts\WebsiteFonts, you'll need to specify the complete path in your @font-face declaration. Let me show you both approaches side-by-side:
Using Absolute Path
SuggestedOPTION 1@font-face {
font-family: 'SiteIcons';
src: local('SiteIcons'),
url('C:/Fonts/WebsiteFonts/site-icons.ttf') format('truetype'),
url('C:/Fonts/WebsiteFonts/site-icons.woff2') format('woff2'),
url('C:/Fonts/WebsiteFonts/site-icons.woff') format('woff');
}
.webicon::before {
font-family: 'SiteIcons';
content: "";
}Pros
- Works regardless of HTML file location
- More maintainable if moving HTML files
- Clearer where fonts are coming from
Cons
- Less portable across systems
- Requires updating paths if moving to another machine
- Windows-specific path syntax
Using absolute paths ensures the browser can find the fonts regardless of where your HTML file is located. The forward slashes (/) work fine in URLs even on Windows, though you could use double backslashes (\\\) if needed.
Using Relative Path
OPTION 2/* Assuming HTML file is in C:\Projects\MySite\index.html */
@font-face {
font-family: 'SiteIcons';
src: local('SiteIcons'),
url('../../Fonts/WebsiteFonts/site-icons.ttf') format('truetype'),
url('../../Fonts/WebsiteFonts/site-icons.woff2') format('woff2'),
url('../../Fonts/WebsiteFonts/site-icons.woff') format('woff');
}
.webicon::before {
font-family: 'SiteIcons';
content: "";
}Pros
- More portable across systems
- Easier to move entire project
- Follows web development best practices
Cons
- Requires careful tracking of relative paths
- Can break if project structure changes
- May not work across drives
Relative paths are calculated from the HTML file's location. While more portable, they become impractical when crossing drive boundaries or dealing with deeply nested structures.
For your specific case with fonts in C:\Fonts\WebsiteFonts, using absolute paths is the most reliable approach. Just remember to escape any backslashes if needed (though forward slashes work perfectly well too).