search
HomeWeb Front-endCSS TutorialHow to set the color of html a tag? Summary of color settings for hyperlinks (css style)

Everyone should be familiar with the

hyperlinka tag. This article mainly talks about the basic css style settings of the a tag. It introduces four color changes. I hope you can practice more. Below Let us read this article together

First we need to know the color setting of the html a tag:

We all know that in html the a tag is in the web page What does the default color look like? Now try the code to see:

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>PHP中文网</title>
</head>
<body>
<a href="#">php中文网</a>
</body>
</html>

This is the code for a basic html document. Look at the display effect in the browser:

How to set the color of html a tag? Summary of color settings for hyperlinks (css style)

The unclicked URL above is blue like this, and after being clicked, it is purple. Such a link does not look good. We need to set a color for the a tag. For example, if I want to set a color for unclicked URLs, let's say red. Before being clicked, it is red, and after being clicked, it is black. Let’s do the effect:

<head>
<meta charset="utf-8">
<title>PHP中文网</title>
<style type="text/css">
a:link{color:red;}
a:visited{color:black;}
</style>
</head>
<body>
<a href="#">php中文网</a>
</body>

This is a simple css code, let’s take a look at the effect:

How to set the color of html a tag? Summary of color settings for hyperlinks (css style)

This is The style that has not been accessed is red;

How to set the color of html a tag? Summary of color settings for hyperlinks (css style)

This is the style that has been accessed and is black. Let’s explain the code:

  • a:link: It is an unvisited style. You can add many things to it, such as removing underlines, changing colors and other functions. ;

  • a:visited: It is the style after being clicked. You can also add many elements to it, and you can underline, change color, zoom in and other functions;

  • a:hover: This is the mouse hover style. There will be examples of this later. Let’s get to know it first. You can set the color to change when the mouse is parked at the position of the hyperlink;

  • a:active: This is said to be an activated style. To put it simply, it is a style that will appear instantly when you click the mouse. This style is found on many websites;

Now let’s take a look at an example, the effect of putting all the above four in:

<head>
<meta charset="utf-8">
<title>PHP中文网</title>
<style type="text/css">
a:link{color:red;}
a:visited{color:black;}
a:hover{color:pink;}
a:active{color:#ccc;}
</style>
</head>
<body>
<a href="#">php中文网</a>
</body>

Let’s take a look now at the browser The effect shown in:

How to set the color of html a tag? Summary of color settings for hyperlinks (css style)

This is the effect of mouse hovering, made

How to set the color of html a tag? Summary of color settings for hyperlinks (css style)

This is the click moment Effect. (Want to see more, please click css video tutorial)

Summary of hyperlink a tag:

So there are four types of a tag Now that we have introduced the CSS styles of anchor pseudo-classes, let’s recall the four uses. One is the unclicked style, which is the style that is displayed normally without being clicked. The style after being clicked is the style after you click the tag. , and another one is the mouse hover style, which changes when you put the mouse on it. This effect is very useful. You will know its use later. The last one is the effect at the moment of click. These four This effect can be said to be the four necessary styles for a tags, so the settings can be better.

【Editor’s Recommendation】

html5 What is the usage of datalist tag? Here are usage examples of the datalist tag

#What is the include tag in html? html include implements configuration parsing

The above is the detailed content of How to set the color of html a tag? Summary of color settings for hyperlinks (css style). For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
A Little Reminder That Pseudo Elements are Children, Kinda.A Little Reminder That Pseudo Elements are Children, Kinda.Apr 19, 2025 am 11:39 AM

Here's a container with some child elements:

Menus with 'Dynamic Hit Areas'Menus with 'Dynamic Hit Areas'Apr 19, 2025 am 11:37 AM

Flyout menus! The second you need to implement a menu that uses a hover event to display more menu items, you're in tricky territory. For one, they should

Improving Video Accessibility with WebVTTImproving Video Accessibility with WebVTTApr 19, 2025 am 11:27 AM

"The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect."- Tim Berners-Lee

Weekly Platform News: CSS ::marker pseudo-element, pre-rendering web components, adding Webmention to your siteWeekly Platform News: CSS ::marker pseudo-element, pre-rendering web components, adding Webmention to your siteApr 19, 2025 am 11:25 AM

In this week's roundup: datepickers are giving keyboard users headaches, a new web component compiler that helps fight FOUC, we finally get our hands on styling list item markers, and four steps to getting webmentions on your site.

Making width and flexible items play nice togetherMaking width and flexible items play nice togetherApr 19, 2025 am 11:23 AM

The short answer: flex-shrink and flex-basis are probably what you’re lookin’ for.

Position Sticky and Table HeadersPosition Sticky and Table HeadersApr 19, 2025 am 11:21 AM

You can't position: sticky; a

Weekly Platform News: HTML Inspection in Search Console, Global Scope of Scripts, Babel env Adds defaults QueryWeekly Platform News: HTML Inspection in Search Console, Global Scope of Scripts, Babel env Adds defaults QueryApr 19, 2025 am 11:18 AM

In this week's look around the world of web platform news, Google Search Console makes it easier to view crawled markup, we learn that custom properties

IndieWeb and WebmentionsIndieWeb and WebmentionsApr 19, 2025 am 11:16 AM

The IndieWeb is a thing! They've got a conference coming up and everything. The New Yorker is even writing about it:

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Atom editor mac version download

Atom editor mac version download

The most popular open source editor