How to Change the Color of a Link in ReactJS ?
Last Updated :
24 Apr, 2025
In this article, we'll see how we can change the color of a link in ReactJS. To change a link's color in React, add a CSS style to the link element using the style attribute in JSX code.
Default link styles in HTML and CSS often include blue color and underlining. However, they may not align with your React app's design. You might need to change the link color to match your app's theme, and branding, or differentiate link states.
Syntax:
<a href="#"> Home </a>
Prerequisites:
Approaches to change the color of link in React JS are:
Steps to Create React Application:
Step 1: Create a react application by using this command
npx create-react-app change-color-project
Step 2: After creating your project folder, i.e. change-color-project, use the following command to navigate to it:
cd change-color-project
Project Structure

To change the color of a link in React using CSS modules, create a CSS file with a unique class name, define the desired color property for that class, and import it into your React component.
CSS modules modularize CSS in React by defining styles in a separate file and importing them into the component.
Example: This example use CSS to change the color of links on hover.
JavaScript
// Filename - App.js
import React from "react";
import "./style.css";
export default function App() {
return (
<nav className="navbar">
<ul className="navMenu">
<li>
<a href="#" className="link">
Home
</a>
</li>
<li>
<a href="#" className="link">
About
</a>
</li>
<li>
<a href="#" className="link">
Contact
</a>
</li>
</ul>
</nav>
);
}
CSS
/* Filename - App.js */
.navbar {
background-color: #333;
display: flex;
justify-content: space-between;
align-items: center;
padding: 10px;
}
.navMenu {
list-style: none;
display: flex;
}
.link {
color: #fff;
text-decoration: none;
padding: 10px;
font-size: 1.4rem;
}
/* Changing the color */
.link:hover {
color: red;
}
Step to Run the Application: To Run Application: Open the terminal and type the following command.
npm start
Output: This output will be visible on the http://localhost:3000/ on the browser window.

To change the color of a link in React using styled-components and import the styled function from the styled-components library. Create a styled component using the styled function and define the desired styles,Â
Styled components in React let you write CSS-in-JS, where a single component can contain both the HTML markup and the corresponding CSS.
Step to Install Module:
npm i styled-components
The updated dependencies in package.json file will look like.
"dependencies": {
"@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "5.0.1",
"styled-components": "^6.1.0",
"web-vitals": "^2.1.4"
}
Example: This example is the same as the previous but the difference is that in the previous example, we use CSS modules but in this example, we used styled components. If you got an error like Can't resolve 'styled-components'. Install the styled-components package by using the command:Â
JavaScript
// Filename - App.js
import React from "react";
import styled from "styled-components";
const Navbar = styled.nav`
background-color: #333;
display: flex;
justify-content: space-between;
align-items: center;
padding: 10px;
font-size:1.4rem;
`;
const NavbarLinks = styled.ul`
list-style: none;
display: flex;
`;
const NavbarLink = styled.a`
color: #fff;
text-decoration: none;
padding: 10px;
/* Changing the color */
&:hover {
color: red;
}
`;
export default function App() {
return (
<div>
<Navbar>
<NavbarLinks>
<li>
<NavbarLink href="#">
Home
</NavbarLink>
</li>
<li>
<NavbarLink href="#">
About
</NavbarLink>
</li>
<li>
<NavbarLink href="#">
Contact
</NavbarLink>
</li>
</NavbarLinks>
</Navbar>
</div>
);
}
Step to Run the Application: To Run Application: Open the terminal and type the following command.
npm start
Output: This output will be visible on the http://localhost:3000/ on the browser window.
Similar Reads
How To Change Placeholder Color In ReactJS ?
In this article, we'll explore two different approaches to changing the placeholder color in ReactJS. To change the color of the placeÂholder text, the CSS ::placÂeholder pseudo-element is primarily utilized. This handy pseudo-element enables us to style the placeÂholder text within an input field.
3 min read
How to Change the Color of Icons using Material-UI in ReactJS?
Changing the icon colors makes us able to keep the webpage according to themes. Material-UI icons is a React based module. React supports more than 1000 Material-UI icons. It is one of the most popular and in-demand frameworks.ApproachTo change the color of icons using the Material UI in React JS we
3 min read
How To Change The Favicon In React JS?
A favicon is a small icon that appears in the browser tab next to the page title. Changing the favicon in a React JS project can help improve the branding of your web application by displaying a custom icon that represents your business or website.In this article, we will explore the following two d
4 min read
How to Change Link Color in CSS?
The default HTML links are in blue color, and when the mouse hovers they get an underline. When the link is visited, it becomes violet. Now, To change the color of a link in CSS, you can use the color property along with the <a> (anchor) tag and its various pseudo-classes like :hover, :visited
2 min read
How to change the navbar color when you scroll in ReactJS ?
On scroll navbar color change in React highlights a sticky responsive navigation bar to navigate through web application pages. It provides an efficient way to navigate multiple pages in a single-page application. The following approach covers how to change the navbar color when you scroll through t
4 min read
How to Set Text Color in ReactJS ?
React provides you the ability to create interactive and dynamic useÂr interfaces. Within these interfaces, the choice of text color holds significant importance as it enhanceÂs the visual appeal and engageÂment for users. A foundational aspect of styling revolveÂs around modifying text color. In t
3 min read
How to Change the Color of Link on Hover using CSS ?
Changing the color of a link on hover can provide visual feedback to users, indicating that the link is interactive. It improves the user experience by helping users understand that the link is clickable. These are the following approaches: Table of Content Using CSS pseudo-classUsing CSS VariablesU
2 min read
How to change the background color of the active nav-item?
In this article, we will learn how we can change the background of the active nav item with the help of CSS and jQuery. Given an HTML document containing a list of items, the task is to change the background color of a particular list item when it is active or clicked. We can change the background c
3 min read
How to create a rating component in ReactJS ?
Creating a rating component in React application allows user to register their review and rate the items using clickable stars. Using a custom rating component enhances the UI and experience of users.Prerequisite:Basic knowledge of npm or yarn.styled-components.Basic Knowledge of useState React hook
3 min read
How to create a Read More component in ReactJS?
Creating a Read More component in React JS refers to hiding and displaying the text content on the page. It can be achieved by setting the state variable and display the content accordingly. PrerequisitesNode.JS and npmReact JSReact JS useState() hookApproachTo create a Read More component in React
3 min read