HTML as Attribute

Beginner
5 min read
Updated: Oct 2026
3 examples
Live preview

Definition and Usage

The as attribute on a <link> tells the browser what kind of resource a preload (or modulepreload) will fetch — for example script, style, font, or image.

It is required with rel="preload" and optional with rel="modulepreload" (defaults to script). Pair it with href, and often type or crossorigin. See also rel.

Baseline · Widely available.

Not deprecated. Stable with rel="preload" across modern browsers (widely available since about January 2021).

Preload ≠ execute.

as="script" only downloads early. You still need a <script> (or dynamic insert) to run the file. For modules, prefer rel="modulepreload".

HTML Syntax

syntax.html
<link rel="preload" href="…" as=" resource_type">

resource_type is a destination keyword such as script, style, font, or image.

Attribute Values

Common as values for rel="preload" (MDN / HTML destinations):

ValueDescriptionTry it
styleCSS stylesheet (also used later via rel="stylesheet")Try it
scriptClassic JavaScript file (preload does not run it)Try it
fontWeb font — requires crossoriginTry it
imageImage file; pair with type for format hintsTry it
fetchFetch/XHR-style resource — requires crossoriginTry it
trackWebVTT track fileTry it

modulepreload may also use destinations like script, worker, or json (defaults to script if omitted).

Live Preview

Pick an as value. The sample markup updates — check DevTools Network on a real page to see the early fetch.

Demo builds a <link rel="preload"> string. Fonts and fetch also need crossorigin.

Generated markup
<link rel="preload" href="/styles/main.css" as="style">

as="style" — good for CSS discovered late

HTML Examples

Short, copy-ready snippets. Use Try It Yourself for a live editor.

Example 1 — Preload CSS and JavaScript

Early-fetch stylesheet and script, then use them normally.

HTML
<head>
  <link rel="preload" href="style.css" as="style">
  <link rel="preload" href="main.js" as="script">

  <link rel="stylesheet" href="style.css">
</head>
<body>
  <h1>Preload demo</h1>
  <script src="main.js" defer></script>
</body>
Try It Yourself

How It Works

  1. rel="preload" starts an early fetch for each resource.
  2. as="style" / as="script" set the correct destination and headers.
  3. A second link / script actually applies or runs the file.
  4. defer keeps script order friendly after HTML parse.

Example 2 — Preload a Font (Needs crossorigin)

Fonts must match CORS mode or the browser may refetch them.

HTML
<link
  rel="preload"
  href="fonts/brand.woff2"
  as="font"
  type="font/woff2"
  crossorigin>

<link rel="stylesheet" href="styles.css">
Try It Yourself

How It Works

  1. as="font" marks the preload as a font destination.
  2. type="font/woff2" lets unsupported browsers skip the download.
  3. crossorigin matches anonymous CORS used by @font-face.
  4. Same for fetch — as="fetch" also needs crossorigin.

Example 3 — Preload an Image with a MIME Hint

Hint a modern format; the browser only preloads if it understands type.

HTML
<head>
  <link rel="preload" href="hero.avif" as="image" type="image/avif">
</head>
<body>
  <picture>
    <source srcset="hero.avif" type="image/avif">
    <img src="hero.jpg" alt="Hero photo of a mountain lake" width="800" height="450">
  </picture>
</body>
Try It Yourself

How It Works

  1. as="image" preloads for later <img> / <picture> use.
  2. type skips formats the browser cannot decode.
  3. Preload one likely format — avoid preloading every alternate.
  4. Always keep alt on the real image (see alt).

Edge Cases & Pitfalls

Most preload bugs come from a missing as, wrong CORS mode, or unused downloads.

required

Omit as and preload may do nothing

For rel="preload", as is required. Without it, many browsers will not fetch the resource.

CORS

font and fetch need crossorigin

Mismatch causes a second download or a wasted preload. Match the real request’s credentials mode.

waste

Do not preload everything

Unused preloads compete for bandwidth. Preload only critical, soon-used assets.

scope

Not for every rel

Skip as on normal stylesheet, icon, or canonical links. It belongs with preload / modulepreload.

modules

Prefer modulepreload for ES modules

rel="modulepreload" fetches, parses, and fills the module map. as is optional there (default script).

Browser Support

as is an HTML attribute on <link> for preload destinations. It is not a Node.js, Deno, or Bun API.

✓ Baseline · Widely available

as

Widely available with rel="preload" since about January 2021. Desktop Chrome, Firefox, Safari, Edge, and Opera support the common destinations.

95% Global support (approx.)
Google Chrome 50+
Full support
Mozilla Firefox 56+
Full support
Apple Safari 11.1+
Full support
Microsoft Edge 79+
Full support
Opera 37+
Full support
Samsung Internet Modern
Full support
Internet Explorer No
Not supported
as (with preload) Widely supported

Bottom line: Safe to use for critical early fetches. Always set as with preload, and add crossorigin for fonts and fetch.

Key Takeaways

  • Role: name the preload destination — script, style, font, image, …
  • Required on rel="preload"; optional on modulepreload.
  • CORS: font and fetch need matching crossorigin.
  • Hint only: preload caches early — it does not apply CSS or run JS by itself.

One line: as tells preload what you are fetching — required for correct priority, headers, and cache reuse.

Frequently Asked Questions

On a link with rel="preload" (or optionally modulepreload), as tells the browser what kind of resource is being fetched — script, style, font, image, and so on — so it can set priority, Accept headers, and CSP correctly.
Yes for rel="preload". Without as, the preload often will not fetch. For rel="modulepreload", as is optional and defaults to script.
The link element, mainly with rel="preload" or rel="modulepreload". Do not set as on ordinary stylesheet or icon links.
Font (and fetch) preloads must use CORS mode that matches the real request. Add crossorigin on the preload link or the font may download twice or fail to reuse the cache.
No. rel="preload" as="script" only downloads and caches the file. You still need a script tag (or dynamic insert) to run it.
No. It is part of modern resource hints and is Baseline widely available with preload.

Next: async

Load external scripts without blocking HTML parsing.

async tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful