JavaScript Document alinkColor Property

Beginner
⏱️ 10 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Deprecated
Instance property

What You’ll Learn

Document.alinkColor is a deprecated instance property that gets or sets the color of an active link—the brief state between mousedown and mouseup. Learn what it controls, how it relates to legacy linkColor / vlinkColor, the modern :active CSS replacement, and five examples with try-it labs.

01

Kind

Instance property

02

Type

string color

03

Status

Deprecated

04

Means

Active link

05

Replace

CSS :active

06

Legacy set

link / vlink

Introduction

Early HTML pages often set global link colors with JavaScript or the obsolete <body alink="..."> attribute. The Document object exposed matching properties: linkColor (unvisited), vlinkColor (visited), and alinkColor (active while pressed).

An active link is not a “currently focused” link—it is the moment the user holds the mouse button down on a hyperlink, between mousedown and mouseup.

💡
Learn it, don’t ship it

Study alinkColor so you can recognize legacy scripts and old tutorials. For new pages, style links with CSS pseudo-classes: :link, :visited, :hover, and :active.

Related Document tutorials: adoptedStyleSheets, activeElement, Document constructor.

Understanding Document.alinkColor

A getter/setter instance property on Document. Reading it returns the active-link color string; writing it changes the color applied to active links in the document body.

  • Value — a color name (blue, darkorange) or hex (#0066CC).
  • Active state — between mousedown and mouseup on a link.
  • null — assigning null converts to "" (empty string).
  • Firefox default — MDN: red (#ee0000) in Mozilla Firefox.
  • Deprecated — MDN recommends CSS :active instead.

📝 Syntax

JavaScript
document.alinkColor

Get

JavaScript
console.log(document.alinkColor);
// e.g. "#ee0000" in Firefox (browser-dependent)

Set

JavaScript
document.alinkColor = "#0066CC";
document.alinkColor = "darkorange";
document.alinkColor = null; // becomes ""

⚡ Quick Reference

GoalCode / note
Read active colordocument.alinkColor
Set hexdocument.alinkColor = "#0066CC"
Set namedocument.alinkColor = "darkorange"
Clear (legacy)document.alinkColor = null""
Modern replacementa:active { color: ... }
MDN statusDeprecated

🔍 At a Glance

Four facts about document.alinkColor.

Type
string

Color value

When
mouse down

On a link

Status
deprecated

Legacy API

Use CSS
:active

Modern fix

📋 alinkColor vs a:active

document.alinkColora:active { color: ... }
ScopeDocument-wide legacy hookPer-stylesheet CSS rule
Recommended?NoYes
MDN statusDeprecatedStandard CSS
Best forReading old codeAll new styling

Examples Gallery

Examples follow MDN Document: alinkColor. Press and hold a link in try-it labs to see the active color where the property still applies.

📚 Getting Started

Read and set the deprecated active-link color.

Example 1 — Read document.alinkColor

Log the current active-link color (browser-dependent).

JavaScript
console.log(document.alinkColor);
// Firefox default (MDN): "#ee0000"
// Other browsers may differ or ignore the property in practice
Try It Yourself

How It Works

The returned string may be a hex code or color name depending on how the browser stores it.

Example 2 — Set a Hex Color

Assign a hex value, then press-and-hold a link to preview the active state.

JavaScript
document.alinkColor = "#0066CC";
console.log(document.alinkColor);
// Hold mouse down on a link to see active color (where supported)
Try It Yourself

How It Works

Legacy property affects document-level active links, not individual elements via modern APIs.

📈 Names, null & Modern CSS

Other assignment forms and the recommended replacement.

Example 3 — Set a Color Name

MDN accepts named colors such as darkorange.

JavaScript
document.alinkColor = "darkorange";
console.log(document.alinkColor);
Try It Yourself

How It Works

Named colors are valid legacy inputs; browsers may normalize them when read back.

Example 4 — null Becomes Empty String

MDN: assigning null is equivalent to assigning "".

JavaScript
document.alinkColor = null;
console.log(document.alinkColor === "");
console.log(JSON.stringify(document.alinkColor));
Try It Yourself

How It Works

This null coercion is a Document property quirk—not something to rely on in new CSS-based styling.

Example 5 — Modern Replacement with a:active

MDN’s recommended approach—style active links in CSS.

JavaScript
a:link { color: #2563eb; }
a:visited { color: #7c3aed; }
a:active { color: #dc2626; }
Try It Yourself

How It Works

CSS gives per-site control, theming, and media queries—without deprecated Document color properties.

🚀 Common Use Cases

  • Reading legacy tutorials — recognize old link-color scripts.
  • Migrating old intranet pages — replace with CSS pseudo-classes.
  • Debugging ancient samples — explain why a link flashes red on mousedown in Firefox.
  • Not for new apps — do not set global link colors via Document properties.
  • Teaching link states — contrast active vs visited vs hover.
  • Pair with accessibility — use visible :focus styles for keyboard users.

🧠 How Active Link Color Works

1

User presses mouse on link

mousedown starts the active link state.

Input
2

Legacy color applies

document.alinkColor (where supported) tints the link.

Legacy
3

Mouse released

mouseup ends active; visited/unvisited styles return.

End
4

Prefer CSS :active

Define active (and :focus) styles in stylesheets for new projects.

📝 Notes

  • alinkColor is deprecated in the HTML specification (MDN).
  • Active ≠ focused — keyboard focus uses :focus styles; active is mouse-down on a link.
  • Firefox default is #ee0000 per MDN; other engines may differ.
  • Sibling legacy properties: linkColor, vlinkColor, fgColor, bgColor.
  • Many modern pages ignore Document color properties if CSS already styles links.
  • Related: adoptedStyleSheets, activeElement, JavaScript hub.

Legacy Browser Support

Document.alinkColor is deprecated but may still exist for compatibility in some browsers. MDN recommends CSS :active instead. Logos use the shared browser-image-sprite.png sprite from this project.

Deprecated · Legacy

Document.alinkColor

Legacy active-link color getter/setter — use CSS :active in new code.

Legacy Compatibility only
Mozilla Firefox Supported · default #ee0000 (MDN)
Legacy support
Google Chrome May expose property · prefer CSS
Legacy / limited
Apple Safari Do not rely on alinkColor
Legacy / limited
Microsoft Edge Chromium · prefer CSS :active
Legacy / limited
Opera Follow Chromium behavior
Legacy / limited
Internet Explorer Legacy Document color APIs
Legacy support
Document.alinkColor Avoid in new code

Bottom line: Recognize alinkColor in old scripts. For new styling, use a:link, a:visited, a:hover, and a:active in CSS — never document.alinkColor.

Conclusion

Document.alinkColor is a deprecated way to control the color of links while the mouse button is held down. It is useful for understanding legacy pages and migrating them to CSS—not for new features.

Continue with all, ownerDocument, adoptedStyleSheets, Document constructor, or the JavaScript hub.

💡 Best Practices

✅ Do

  • Style links with CSS :link, :visited, :hover, :active
  • Add visible :focus styles for keyboard users
  • Replace alinkColor when updating legacy files
  • Learn legacy Document color properties to read old code
  • Test link states in real browsers after migrating to CSS

❌ Don’t

  • Set document.alinkColor in new production code
  • Confuse active (mouse down) with focus or hover
  • Assume the same default color in every browser
  • Mix deprecated Document colors with design-system CSS blindly
  • Depend on alinkColor for accessibility contrast

Key Takeaways

Knowledge Unlocked

Five things to remember about alinkColor

Deprecated active-link color — prefer CSS :active.

5
Core concepts
⚠️02

Status

deprecated

Legacy
🖱03

When

mousedown

State
04

Replace

a:active

CSS
🔄05

null

becomes ""

Quirk

❓ Frequently Asked Questions

It gets or sets the color of an active link in the document body. A link is active between mousedown and mouseup — while the user is pressing the mouse button on it.
Yes. MDN marks Document.alinkColor as deprecated. It may still work in some browsers for compatibility, but you should use CSS :active (or :focus where appropriate) in new code.
A string color name (such as blue or darkorange) or a hexadecimal color (such as #0066CC). Setting null is converted to the empty string.
MDN notes the default alinkColor in Mozilla Firefox is red (#ee0000 in hexadecimal).
Legacy Document properties include linkColor (unvisited), vlinkColor (visited), and alinkColor (active/pressed). Modern CSS uses :link, :visited, and :active pseudo-classes instead.
No. Style links with CSS — for example a:active { color: ... } — or component styles. Learn alinkColor only to read or migrate old scripts.
Did you know?

Old HTML used <body link="" vlink="" alink=""> attributes for the same three link colors. JavaScript document.linkColor, vlinkColor, and alinkColor mirrored those attributes—all superseded today by CSS pseudo-classes.

Next: all

Learn the deprecated HTMLAllCollection behind document.all.

all →

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.

6 people found this page helpful