Skip to main content

Fast foundations

HTML Performance Foundations Before JavaScript

Markup determines which resources the browser discovers, how early it discovers them, and whether space is reserved before they arrive.

HTMLbeginner4 min readWeb performance

Learning overview

Estimated time
4 minutes
Difficulty
Beginner
Prerequisites
No prior experience required
Learning outcome
Explain html using a clear mental model · Apply html in practical HTML work
Last updated
July 18, 2026

Reserve space and deliver appropriate media

Width and height attributes let the browser calculate an image’s aspect ratio before download, reducing layout shifts. Srcset and sizes help it choose an appropriately sized source instead of downloading a desktop image for every phone.

responsive-image.html
<img
  src="/images/course-800.webp"
  srcset="/images/course-400.webp 400w,
          /images/course-800.webp 800w,
          /images/course-1200.webp 1200w"
  sizes="(max-width: 640px) 100vw, 800px"
  alt="Visual lesson showing the CSS box model"
  width="800"
  height="450">

Match loading priority to user experience

Do not lazy-load the likely largest image above the fold. Lazy-load offscreen images and iframes. Preload only a small number of critical resources whose early discovery genuinely improves rendering; excessive preload competes for bandwidth.

  • Load the primary visible image normally
  • Use loading="lazy" for offscreen images
  • Use fetchpriority sparingly and based on measurement
  • Avoid autoplaying heavy media

Prevent scripts from blocking parsing unnecessarily

A classic script without async or defer blocks HTML parsing while it downloads and executes. Defer preserves document order and runs after parsing. Async runs as soon as available, so it suits independent scripts that do not depend on document order.

scripts.html
<script src="/js/navigation.js" defer></script>
<script src="https://example.com/independent-analytics.js" async></script>

Measure the result

Use browser network and performance tools to verify discovery order, transfer size, blocking time, largest contentful paint, and layout shifts. Keep markup changes only when evidence confirms they improve the target experience.

Frequently asked questions

Should every image use lazy loading?

No. Images visible in the initial viewport, especially the likely LCP image, should generally load immediately. Lazy loading is most useful below the fold.

What is the difference between async and defer?

Both avoid blocking download during parsing. Deferred scripts run after parsing in document order; async scripts execute whenever ready without preserving order.

Topic graph

A taxonomy-generated path through this subject.

  1. HTML
  2. Web performance
  3. html
  4. performance
  5. images
  6. core-web-vitals
  7. What Is HTML in Programming?
  8. Learn HTML: From First Page to Semantic Websites
  9. HTML Tutorial: Build a Complete Semantic Web Page

Recommended automatically from shared technologies, topics, intent, and difficulty.

Hand-picked companion pages that deepen this topic.

Your next steps

Continue learning

  1. 1glossaryWhat Is HTML in Programming?
  2. 2guidesLearn HTML: From First Page to Semantic Websites
  3. 3guidesHTML Tutorial: Build a Complete Semantic Web Page
  4. 4cheatsheetsHTML Cheatsheet: Semantic Elements, Forms, and Metadata