- CSS Links
- Styling Links
- Example
- Example
- Text Decoration
- Example
- Background Color
- Example
- Link Buttons
- Example
- More Examples
- Example
- Example
- Example
- COLOR PICKER
- Report Error
- Thank You For Helping Us!
- Altering Link CSS When Clicked
- Change Css of Link Upon Click
- How can i change an inline css style when clicking a link?
- Style a clicked link — Any CSS only solution?
- CSS: link is «onClick» underlined (FireFox)
- How to Style Links in CSS
- More on styling in CSS:
CSS Links
With CSS, links can be styled in many different ways.
Styling Links
Links can be styled with any CSS property (e.g. color , font-family , background , etc.).
Example
In addition, links can be styled differently depending on what state they are in.
The four links states are:
- a:link — a normal, unvisited link
- a:visited — a link the user has visited
- a:hover — a link when the user mouses over it
- a:active — a link the moment it is clicked
Example
/* unvisited link */
a:link color: red;
>
/* visited link */
a:visited color: green;
>
/* mouse over link */
a:hover color: hotpink;
>
/* selected link */
a:active color: blue;
>
When setting the style for several link states, there are some order rules:
Text Decoration
The text-decoration property is mostly used to remove underlines from links:
Example
a:visited text-decoration: none;
>
a:hover text-decoration: underline;
>
a:active text-decoration: underline;
>
Background Color
The background-color property can be used to specify a background color for links:
Example
a:link <
background-color: yellow;
>
a:visited background-color: cyan;
>
a:hover background-color: lightgreen;
>
a:active background-color: hotpink;
>
Link Buttons
This example demonstrates a more advanced example where we combine several CSS properties to display links as boxes/buttons:
Example
a:link, a:visited <
background-color: #f44336;
color: white;
padding: 14px 25px;
text-align: center;
text-decoration: none;
display: inline-block;
>
a:hover, a:active background-color: red;
>
More Examples
Example
This example demonstrates how to add other styles to hyperlinks:
Example
Another example of how to create link boxes/buttons:
a:link, a:visited <
background-color: white;
color: black;
border: 2px solid green;
padding: 10px 20px;
text-align: center;
text-decoration: none;
display: inline-block;
>
a:hover, a:active background-color: green;
color: white;
>
Example
This example demonstrates the different types of cursors (can be useful for links):
COLOR PICKER
Report Error
If you want to report an error, or if you want to make a suggestion, do not hesitate to send us an e-mail:
Thank You For Helping Us!
Your message has been sent to W3Schools.
Top Tutorials
Top References
Top Examples
Get Certified
W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.
Altering Link CSS When Clicked
If you are using a CMS or any platform with pre-defined CSS files, it is possible that a browser-specific CSS file is causing the issue, as it can override the primary CSS file. In such cases, it can be challenging to use the «element» to create a consistent design across different browsers using CSS alone. A possible solution could be to modify the CSS file or explore alternative options.
Change Css of Link Upon Click
My goal is to generate link buttons that modify one another’s css styling after being clicked. I came across some instructional materials on accomplishing this task, but the solution is only partially functional, as demonstrated in this fiddle.
Upon clicking the link and loading the page, the css-styling of the link resets back to normal, which is the only issue at hand. However, it is desired that the styling remains intact until another link is pressed.
From my perspective, utilizing javascript is necessary to achieve this effect. However, this particular area of the internet is not where my strengths lie.
Consider utilizing jQuery, which provides a pre-existing set of functions. To address this issue, focus on the .css() category found at http://api.jquery.com/css/.
Your code would resemble the following.
JQuery can be utilized in conjunction with JavaScript, providing a simpler alternative to using pure JavaScript. Afterward, the onclick event can be triggered by invoking a function.
change color of the second button will change color if you click on the first button
Ensure that you declare the JQuery library in the HTML along with other necessary steps.
Just replace the href=»#» with void
This function with no return value prevents the browser from making any query requests.
I resolved the issue independently by incorporating the buttons into an unordered list that already contained the same function.
Implementing link into HTML/CSS button, Dec 21, 2012 at 12:16. Add a comment. 3. If you really need to use the
How can i change an inline css style when clicking a link?
There is an inline-hidden form that contains the code » style=»display: none;» «.
Is there a way to modify the style dynamically to style=»display: inline;» upon clicking a link on the page?
Update
jQuery, a lightweight JavaScript library, enables developers to accomplish many impressive tasks with minimal scripting efforts.
To start with, I recommend reading «How jQuery works?» as it covers all the essentials required to begin using jQuery.
In the fiddle, I will provide an explanation of the code I have written.
First of all the link & form
Keep in mind the id mentioned in the link and form above. This is the method we will use to choose the element in the script, similar to the functionality of document.getElementById() .
Lets hide the form by default
Now lets write the jquery
I hope that this will provide you with a sufficient starting point.
Attach the anchor with a onclick event and configure the form style to display:block . In case you require assistance, refer to this JS fiddle.
To begin, you must locate a method for choosing the form via JavaScript. Assuming your form contains an attribute named id with the value of myform , here is a function you can use.
One way to connect your function to the link’s event is by binding it. Instead of setting the link’s attribute to a specific value, you can use external JavaScript to keep your content and behavior separate.
Onclick go to url Code Example, css onclick go to url; go to link onclick go to url; javascript go to link on click; how to make a button onclick go to a specific url; html element onclick go to page; html on click go to url button; html onclick go to location url; window.open href button; creat Url; javascript on click goes to href; html button url onclick; …
Style a clicked link — Any CSS only solution?
Is there a sole approach to customize a selected CSS with a link that offers user feedback upon link activation?
In order to provide feedback, I have two options: firstly, I can use JavaScript to listen to click events and provide feedback to a desired class. Alternatively, if CSS feedback is sufficient, I can choose to provide only that.
Any pointer would be of great help.
Something like below is desired.
For a demonstration of the desired behavior, kindly consult this pen.
Achieving consistent functionality across various browsers using CSS alone can be challenging when utilizing the a element.
A possible solution to obtain the desired outcome is by utilizing a button with the code radio .
To achieve a desired outcome, one can create a hidden radio button with a label style resembling a hyperlink and apply CSS pseudo :checked .
input[type=radio] < display:none >input[type=radio] + label < color:blue; text-decoration:underline; cursor:pointer >input[type=radio]:checked + label < color:red >input[type=radio]:checked + label:after < content:url('https://forums.adobe.com/images/jive-image-loading.gif') >
Prior to the updated OP, the following was my response.
In CSS, there are various pseudo selectors available for elements. These selectors can be utilized to determine the status of a link, such as if it is being hovered over, clicked, or currently active.
a:link — a normal, unvisited link
a:visited — a link the user has visited
a:hover — a link when the user mouses over it
a:active — a link the moment it is clicked
Check out this fiddle to witness the various selectors in action.
How can i change an inline css style when clicking a link?, A quick and dirty way is to set the link’s onclick attribute to showForm (); return false, but you’ll probably want to do that in external JavaScript to separate your content and behaviour nicely. Share answered Mar 7, 2012 at 3:29 Ry- ♦ 210k 54 440 452 Add a comment 0 Here Are Some More Codez
CSS: link is «onClick» underlined (FireFox)
I am applying CSS to a hyperlink that possesses its own class.
For the removing, I have this:
.myLink, .myLink:active, .myLink:visited
The link works well in IE, however, when clicked in Firefox, it gets underlined. I assumed that defining the «:active» section would resolve the issue, but it did not. Can you provide assistance, please?
It appears that the problem may not be related to CSS, but rather to the browser’s preferences or overrides. One suggestion is to include !important in the text-decoration attribute, though it would be preferable to investigate the root cause. A helpful approach would be to use a tool such as IE’s developer tools or Firefox’ Firebug to determine the origin of the style and find the optimal solution.
It’s possible that a browser specific CSS file is causing the issue if you’re using a CMS or something with pre-defined CSS files because they can override the main CSS file. In case you’re not using a CMS or something with browser specific css files, you can use Firebug in Firefox. It will help you determine the source of the style in the CSS file and which CSS file is producing it.
To avoid any conflict, ensure that your «.myLink, .myLink:active, .myLink:visited» rules are placed after the use of !important.
Html — CSS Style a specific link, There isn’t a way for CSS to sift through content like that, but could use jQuery to find all anchors that have the word «more» in it and change it based on that: $(«a:contains(‘more’)»).css(«font-size», «11pt»); Not a CSS solution, but this is pretty much the only way you could do what you are asking for. Example for you …
How to Style Links in CSS
Links can be styled with any CSS property, such as color , font-family , font-size , and padding . Here is an easy example:
In addition, links can be styled differently depending on what state they are in.
Links also have 4 states, and many programmers style each state differently. The four states are:
- a:link : an unvisited, unclicked link
- a:visited : a visited, clicked link
- a:hover : a link when the user’s mouse is over it
- a:active : a link when it is clicked
The property is responsible for creating URLs and can be modified using a number of CSS styling properties, although it has a few by default:
You can change these by adding changing the color and text-decoration properties.
color: black; text-decoration: none;
You can also style the link based on interaction using these properties, also known as link states:
- a:link — a normal, unvisited link
- a:visited — a link the user has visited
- a:hover — a link when the user mouses over it
- a:active — a link the moment it is clicked
Here is some sample CSS using the 4 states:
a:link < color: red; >a:visited < color: blue; >a:hover < color: green; >a:active
Note that there are some ordering rules for when you are setting the style for link states.
a:active MUST come after a:hover
a:link — a normal, unvisited link a:visited — a link the user has visited a:hover — a link when the user mouses over it a:active — a link the moment it is clicked
/* unvisited link */ a:link < color: red; >/* visited link */ a:visited < color: green; >/* mouse over link */ a:hover < color: hotpink; >/* selected link */ a:active
More on styling in CSS:
If this article was helpful, tweet it .
Learn to code for free. freeCodeCamp’s open source curriculum has helped more than 40,000 people get jobs as developers. Get started
freeCodeCamp is a donor-supported tax-exempt 501(c)(3) charity organization (United States Federal Tax Identification Number: 82-0779546)
Our mission: to help people learn to code for free. We accomplish this by creating thousands of videos, articles, and interactive coding lessons — all freely available to the public. We also have thousands of freeCodeCamp study groups around the world.
Donations to freeCodeCamp go toward our education initiatives, and help pay for servers, services, and staff.