JavaScript Document linkColor Property

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

What You’ll Learn

Document.linkColor is a deprecated instance property that gets or sets the color of unvisited links in the document. Learn what it controls, how it fits with legacy vlinkColor and alinkColor, the modern :link CSS replacement, and five examples with try-it labs.

01

Kind

Instance property

02

Type

string color

03

Status

Deprecated

04

Means

Unvisited link

05

Replace

CSS :link

06

Legacy set

vlink / alink

Introduction

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

An unvisited link is a normal hyperlink the browser has not yet marked as visited. Once the user opens the URL, the link moves to the visited state and vlinkColor (or CSS :visited) applies instead.

💡
Learn it, don’t ship it

Study linkColor 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: alinkColor, fgColor, Document constructor.

Understanding Document.linkColor

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

  • Value — a color name (blue, darkgreen) or hex (#0066CC).
  • Unvisited state — links the user has not opened yet in this session.
  • null — assigning null converts to "" (empty string).
  • Firefox default — MDN: blue (#0000ee) in Mozilla Firefox.
  • Deprecated — MDN recommends CSS :link or color on <a> instead.

📝 Syntax

JavaScript
document.linkColor

Get

JavaScript
console.log(document.linkColor);
// e.g. "#0000ee" in Firefox (browser-dependent)

Set

JavaScript
document.linkColor = "blue"; // MDN example
document.linkColor = "#0066CC";
document.linkColor = null; // becomes ""

⚡ Quick Reference

GoalCode / note
Read unvisited colordocument.linkColor
MDN exampledocument.linkColor = "blue"
Set hexdocument.linkColor = "#0066CC"
Clear (legacy)document.linkColor = null""
Modern replacementa:link { color: ... }
MDN statusDeprecated

🔍 At a Glance

Four facts about document.linkColor.

Type
string

Color value

When
unvisited

Not yet opened

Status
deprecated

Legacy API

Use CSS
:link

Modern fix

📋 linkColor vs a:link

document.linkColora:link { 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: linkColor. Open try-it labs to see unvisited link colors where the property still applies.

📚 Getting Started

Read and set the deprecated unvisited-link color.

Example 1 — Read document.linkColor

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

JavaScript
console.log(document.linkColor);
// Firefox default (MDN): "#0000ee"
// 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 — MDN Example: Set "blue"

MDN’s classic assignment sets unvisited links to blue.

JavaScript
document.linkColor = "blue";
console.log(document.linkColor);
// Unvisited links appear blue where the property is honored
Try It Yourself

How It Works

Named colors are valid legacy inputs. Only links not yet visited use this color.

📈 Hex, null & Modern CSS

Other assignment forms and the recommended replacement.

Example 3 — Set a Hex Color

Assign a hex value for precise brand colors on unvisited links.

JavaScript
document.linkColor = "#0066CC";
console.log(document.linkColor);
Try It Yourself

How It Works

Hex colors give designers exact control, but CSS :link is the modern way to apply them.

Example 4 — null Becomes Empty String

MDN: assigning null is equivalent to assigning "".

JavaScript
document.linkColor = null;
console.log(document.linkColor === "");
console.log(JSON.stringify(document.linkColor));
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:link

MDN’s recommended approach—style unvisited 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 unvisited links look blue in Firefox.
  • Not for new apps — do not set global link colors via Document properties.
  • Teaching link states — contrast unvisited vs visited vs active.
  • Pair with accessibility — use visible :focus styles for keyboard users.

🧠 How Unvisited Link Color Works

1

Page loads with links

Hyperlinks start in the unvisited state.

Start
2

Legacy color applies

document.linkColor (where supported) tints unvisited links.

Legacy
3

User visits the link

The browser marks the URL visited; vlinkColor or :visited takes over.

Transition
4

Prefer CSS :link

Define unvisited (and :visited, :hover, :focus) styles in stylesheets for new projects.

📝 Notes

  • linkColor is deprecated in the HTML specification (MDN).
  • Unvisited ≠ hovered — hover uses :hover; linkColor only targets the unvisited state.
  • Firefox default is #0000ee per MDN; other engines may differ.
  • Sibling legacy properties: vlinkColor, alinkColor, fgColor, bgColor.
  • Many modern pages ignore Document color properties if CSS already styles links.
  • Related: alinkColor, fgColor, JavaScript hub.

Legacy Browser Support

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

Deprecated · Legacy

Document.linkColor

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

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

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

Conclusion

Document.linkColor is a deprecated way to control the color of unvisited links in a document. It is useful for understanding legacy pages and migrating them to CSS—not for new features.

Continue with vlinkColor, links, ownerDocument, alinkColor, preferredStyleSheetSet, or the JavaScript hub.

💡 Best Practices

✅ Do

  • Style links with CSS :link, :visited, :hover, :active
  • Add visible :focus styles for keyboard users
  • Replace linkColor 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.linkColor in new production code
  • Confuse unvisited with visited or active states
  • Assume the same default color in every browser
  • Mix deprecated Document colors with design-system CSS blindly
  • Depend on linkColor for accessibility contrast

Key Takeaways

Knowledge Unlocked

Five things to remember about linkColor

Deprecated unvisited-link color — prefer CSS :link.

5
Core concepts
⚠️02

Status

deprecated

Legacy
🔗03

When

unvisited

State
04

Replace

a:link

CSS
🔄05

null

becomes ""

Quirk

❓ Frequently Asked Questions

It gets or sets the color of unvisited links in the document. Unvisited links are hyperlinks the user has not opened yet in the current browsing session.
Yes. MDN marks Document.linkColor as deprecated. It may still exist for compatibility in some browsers, but you should use CSS :link or a { color: ... } in new code.
A string color name (such as blue or darkgreen) or a hexadecimal color (such as #0066CC). Setting null is converted to the empty string per MDN.
MDN notes the default linkColor in Mozilla Firefox is blue (#0000ee in hexadecimal).
linkColor styles unvisited links. vlinkColor styles visited links. alinkColor styles active links while the mouse button is held down. Modern CSS uses :link, :visited, and :active instead.
No. Style links with CSS pseudo-classes — for example a:link { color: ... } — or component styles. Learn linkColor 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: vlinkColor

Learn the deprecated visited-link color property and the CSS :visited replacement.

vlinkColor →

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