# How to Change Font Size in HTML: Methods, Units, and What Actually Controls the Result Font size in HTML is one of those topics that looks simple on the surface — until you realize there are half a dozen ways to do it, three different unit systems, and a browser rendering engine with its own opinions. Understanding how each method works helps you write cleaner code and avoid the kind of sizing inconsistencies that make a page look unprofessional. ## The Old Way vs. The Right Way HTML used to handle font size directly through the ` ` tag: ```html This is some text ``` That tag accepted values from 1 to 7 and was deprecated in HTML4. It's effectively dead in modern HTML5. **Don't use it.** Browsers still render it for legacy reasons, but it's not part of the current standard and gives you very little control. The correct approach today is **CSS** — either inline, internal, or external — using the `font-size` property. ## Three Ways to Apply CSS Font Size ### 1. Inline CSS Applied directly to an HTML element using the `style` attribute: ```html

This paragraph is 18 pixels tall.

``` Quick and specific, but hard to maintain at scale. If you need to update sizes across a site, you'll be editing every tag manually. ### 2. Internal CSS (Style Block) Placed inside a ` ``` Better for single-page projects. Keeps your HTML cleaner while keeping everything in one file. ### 3. External CSS Stylesheet Font sizes defined in a separate `.css` file linked to your HTML: ```html ``` In `styles.css`: ```css p { font-size: 18px; } ``` This is the **standard approach for any real project**. It separates content from presentation, keeps your HTML readable, and makes global updates fast. ## CSS Font Size Units: This Is Where It Gets Meaningful 🔍 The unit you choose matters more than the number itself. Different units behave differently depending on context, parent elements, and screen size. | Unit | Type | What It's Relative To | Best Used For | |---|---|---|---| | `px` | Absolute | Screen pixels | Precise, fixed layouts | | `em` | Relative | Parent element's font size | Nested components | | `rem` | Relative | Root element (`html`) font size | Scalable, consistent sizing | | `%` | Relative | Parent element's font size | Fluid, proportional layouts | | `vw` | Relative | Viewport width | Responsive headlines | | `pt` | Absolute | Points (print standard) | Print stylesheets | ### `px` — Pixels The most intuitive unit. `font-size: 16px` means 16 pixels, regardless of anything else. Predictable, but doesn't scale when users adjust browser text settings. ### `em` — Relative to Parent If the parent `
` has `font-size: 20px` and a child `

` is set to `font-size: 1.5em`, the paragraph renders at 30px. This compounds in nested structures, which can cause unexpected results. ### `rem` — Relative to Root `rem` solves `em`'s compounding problem by always referencing the root `` element's font size (typically `16px` by default in browsers). Setting `font-size: 1.5rem` always means 1.5× the root size — regardless of where the element sits in the DOM. ```css html { font-size: 16px; } h1 { font-size: 2rem; /* Always 32px */ } ``` `rem` is widely favored in modern web development for body text and component sizing because it's **predictable and accessible** — users who increase their browser's base font size will see everything scale correctly. ### `vw` — Viewport Width `font-size: 4vw` means the text is 4% of the viewport width. On a 1000px-wide screen, that's 40px. On a 400px phone screen, it's 16px. Useful for large display text that should fill space responsively, though it needs minimum size constraints to stay readable on small screens. ## Targeting Specific HTML Elements You can apply `font-size` to almost any HTML element: ```css h1 { font-size: 2.5rem; } h2 { font-size: 2rem; } h3 { font-size: 1.5rem; } p { font-size: 1rem; } small { font-size: 0.75rem; } ``` Browser defaults give headings progressively larger sizes (`h1` through `h6`), but CSS resets — common in frameworks like Bootstrap or Tailwind — often normalize these. If you're working inside a framework, the default sizes may already be defined and your overrides need to be specific enough to take effect. 💡 ## Inheritance and the Cascade Font size **inherits** by default in CSS. Set `font-size: 18px` on a `` tag and most child elements will inherit it unless overridden. This is useful — you can set a base size once and let it flow through the document. The cascade means specificity determines which rule wins. An inline style beats a class selector beats a tag selector. If your font size changes aren't sticking, a more specific rule somewhere else is likely overriding it. ## Responsive Font Sizing Modern layouts rarely use a single fixed size. A heading that looks right on a desktop might be oversized on a phone. Two approaches handle this well: **Media queries** — change font sizes at defined breakpoints: ```css h1 { font-size: 2rem; } @media (max-width: 600px) { h1 { font-size: 1.4rem; } } ``` **CSS `clamp()`** — sets a minimum, preferred, and maximum size in one line: ```css h1 { font-size: clamp(1.4rem, 4vw, 2.5rem); } ``` This tells the browser: never go below `1.4rem`, scale with the viewport, but never exceed `2.5rem`. Fluid, with guardrails. ## What Shapes Your Actual Result The "right" approach to HTML font sizing depends on several variables specific to your project: - **Project scope** — a single static page versus a multi-page site with a component library - **Framework usage** — working inside Bootstrap, Tailwind, or a custom design system changes what you can and should override - **Accessibility requirements** — whether you need to support browser zoom and user text preferences - **Responsive targets** — how many screen sizes and orientations the layout needs to handle - **Team conventions** — whether a codebase already uses `px`, `em`, or `rem` consistently A developer building a personal blog has different constraints than one maintaining an enterprise CMS. The mechanics of `font-size` are the same — what varies is which combination of methods and units makes sense for a given context. 🎯