How to change the font and font size in HTML (CSS font-family)
font-family and font-size on the page, a heading and a word, safe font stacks, px vs rem vs em, loading a Google Font, and fixes when the font will not change.
To change the font in HTML, set the CSS font-family property; to change the size, set font-size. For the whole page: <body style="font-family: Georgia, serif; font-size: 18px;">. The old <font face="Arial" size="4"> tag was removed from the HTML standard, so use CSS instead.
The whole page
Put a <style> block in the <head> and set both on body. Headings, paragraphs and lists inherit them:
<style> body { font-family: Arial, Helvetica, sans-serif; font-size: 18px; line-height: 1.5; } </style>
Buttons, inputs and text areas do not inherit the font by default. Add button, input, textarea, select { font: inherit; } so forms match the rest of the page.
One heading, paragraph or word
- ✓All headings: h1, h2, h3 { font-family: Georgia, serif; }.
- ✓One heading: <h1 style="font-size: 40px;">Spring menu</h1>.
- ✓A group of elements with a class: <style> .note { font-family: "Courier New", monospace; font-size: 14px; } </style> then <p class="note">…</p>.
- ✓One word: <span style="font-size: 1.25em;">today</span>. For code, the <code> tag already uses a monospace font.
Font stacks: always list a fallback
font-family takes a list. The browser uses the first font that is installed on the device and moves down the list if it is missing. End every list with a generic family: serif, sans-serif or monospace.
Put quotes around names with spaces: font-family: "Times New Roman", Times, serif;.
- ✓Clean, modern: font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; (uses each device's own interface font).
- ✓Classic print look: font-family: Georgia, "Times New Roman", serif;.
- ✓Code or tables of numbers: font-family: Menlo, Consolas, monospace;.
Font size units: px, rem, em, %
- ✓px: a fixed size. font-size: 16px; is the browser default for body text.
- ✓rem: relative to the root size (usually 16px), so 1.5rem is 24px. Text set in rem grows when a reader raises the default size in browser settings, which helps people who need larger text.
- ✓em: relative to the parent element. Inside a 20px paragraph, 0.8em is 16px. Nested em sizes multiply, which is why lists inside lists can shrink.
- ✓Keywords: small, medium, large, x-large. Quick, but less precise.
- ✓Responsive headings: font-size: clamp(28px, 5vw, 48px); shrinks on phones and caps on wide screens.
Use a Google Font
Pick a font on fonts.google.com, copy the <link> tags it gives you into the <head>, then use the name in font-family with a fallback: font-family: "Inter", sans-serif;. The page needs an internet connection to load the font; offline it falls back to the next font in the list. For font files you host yourself (.woff2) and @font-face, see use a custom font in a shared HTML page.
When the font or size does not change
- ✓The font is not on this device: font-family: "Helvetica Neue" works on a Mac and silently falls back on Windows. Use a web font or a stack with fallbacks.
- ✓Missing quotes or comma: font-family: Times New Roman serif; is read as one invalid name. Write "Times New Roman", serif.
- ✓Another rule wins: a more specific selector or a later rule overrides yours. Right-click, choose Inspect, and look for your rule crossed out in the Styles panel. The Computed tab shows the font actually used.
- ✓A class from a framework sets it: on Tailwind pages, text-sm or font-serif on the element beats a rule on body.
- ✓Size set in em inside em: nested elements multiply. Switch to rem.
- ✓Phone shows larger text than expected: iOS Safari can enlarge text in landscape. Add html { -webkit-text-size-adjust: 100%; }.
- ✓Cached file: reload with Ctrl+Shift+R (Cmd+Shift+R on a Mac).
Pages made with AI tools
Pages from Claude, ChatGPT and other tools often use Tailwind, where the font is a class such as font-sans, font-serif or font-mono and the size is text-sm, text-lg or text-4xl. Swap the class on the element instead of adding a style attribute. If the page loads a Google Font, the <link> tag is near the top of the <head>; change the family name in both the link and the CSS.
Share the page as a link
Fonts are the thing most likely to look different on someone else's computer, so check the page on another device before you send it. With FileShare Pro you upload the .html file from the dashboard (or a folder with your font files in it), copy the link and send it; it opens as a page in any browser and the person opening it needs no account. To change the font after you send it, fix the file and upload it to the same link. Related: how to change text color in HTML and how to bold text in HTML. Sign up free to share your first page.
Frequently asked
Add <style> body { font-family: Arial, Helvetica, sans-serif; } </style> in the <head>, or put style="font-family: …" on the <body> tag.
Use the CSS font-size property, for example <p style="font-size: 18px;"> or h1 { font-size: 2.5rem; } in a <style> block.
Most browsers still render it, but it is obsolete in HTML. Use font-family and font-size in CSS instead.
font-family only uses fonts installed on the viewer's device. If the font is missing, the browser uses the next one in the list. Load a web font such as a Google Font to get the same font everywhere.
Drop the file, copy the link — live in seconds, free plan included.
Start sharing free