You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何让Google Font代码在HTML中正常生效?解决Neocities平台字体添加时的“Name entity expected. Got none”错误

Fixing "Name entity expected. Got none" Error with Google Fonts on Neocities

That error almost always boils down to unescaped special characters in your HTML—specifically the & symbol in your Google Fonts URL. Let's break this down and fix it step by step:

Why the error happens

Neocities uses a strict HTML parser that treats & as the start of an HTML entity (like &amp; for & or &lt; for <). In your Google Fonts link, the &display=swap part has an unescaped &, which the parser tries to interpret as an entity... but since there's no valid entity name after it, you get that "Name entity expected" error.

The fix

Escape the & in your Google Fonts URL by replacing it with &amp;. Here's your corrected code:

<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Press+Start+2P&amp;display=swap" rel="stylesheet">

Full working example

Make sure these links go inside your <head> tag, and then reference the font in your CSS like this:

<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>My Neocities Site</title>
  <!-- Corrected Google Fonts links -->
  <link rel="preconnect" href="https://fonts.gstatic.com">
  <link href="https://fonts.googleapis.com/css2?family=Press+Start+2P&amp;display=swap" rel="stylesheet">
  <style>
    /* Use the font in your styles */
    h1, p {
      font-family: 'Press Start 2P', monospace;
    }
  </style>
</head>
<body>
  <h1>Testing Press Start 2P Font!</h1>
  <p>This should now render with your desired font.</p>
</body>
</html>

Quick checks to ensure it works

  • Double-check that all & symbols in any external URLs (not just Google Fonts) are replaced with &amp;
  • Confirm your <link> tags are properly placed inside the <head> section (not in <body> or floating outside)
  • Clear your browser cache if you don't see the font load right away—sometimes old cached styles can interfere

内容的提问来源于stack exchange,提问作者Meganekogekkilove

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.29 08:07:31