---
title: "How to change color after select a text or line?"  
description: "How to change color after select a text or line?"  
author: "Ravi Vishwakarma"  
published: 2021-07-19  
canonical: https://answers.mindstick.com/qa/93782/how-to-change-color-after-select-a-text-or-line  
category: "web application"  
tags: ["javascript", "css cascading style sheets", "html5", "web application development"]  
reading_time: 3 minutes  

---

# How to change color after select a text or line?

How to change [color](https://www.mindstick.com/articles/77/how-to-split-form-background-color-in-c-sharp) after [select](https://www.mindstick.com/forum/34066/use-select-operator-in-linq) a [text](https://yourviews.mindstick.com/view/80730/video-content-rising-over-text-content) or line?

## Answers

### Answer by Ethan Karla

**::selection** use to select a paragraph and then change the color The ::selection pseudo-element matches the portion of an element that is selected by a user. The following CSS properties can be applied to ::selection: color, background, cursor, and outline. The following example makes the selected text white on a orange background:

```
<!DOCTYPE html>
<html lang='en' xmlns='http://www.w3.org/1999/xhtml'>
<head>
    <meta charset='utf-8' />
    <title></title>
    <style>
        ::selection {
            background-color:orange;
            color:white;
        }
    </style>
</head>
<body>
    <p><strong>Note : </strong> Select some data of text</p>
    <b>Windows App Development Solution</b><br />
MindStick is examining enhanced ideas to create user interference more fertile with our enthralled windows application development services.
    Although inadequate, windows have a faithful user base, growing mobile apps for this program unleashes vast business possibilities.
     we are identified for producing reliable and results-oriented Windows Phone Apps Development solutions.
     Our Windows developer team is centered to create windows mobile apps that will deliver user experience and interaction enlightening, connected, and supportive.
</body>
</html>
```

\

### Answer by Steilla Mitchel

```html
<!DOCTYPE html>
<html>
<head>
<style>
::-moz-selection { /* Code for Firefox */
  color: red;
  background: yellow;
}

::selection {
  color: red;
  background: yellow;
}
</style>
</head>
<body>

<h1>Select some text on this page:</h1>

<p>This is a paragraph.</p>
<div>This is some text in a div element.</div>

<p><strong>Note:</strong> ::selection is not supported in Internet Explorer 8 and earlier versions.</p>
<p><strong>Note:</strong> Firefox supports an alternative, the ::-moz-selection property.</p>

</body>
</html>
```

## Output

![How to change color after select a text or line?](https://answers.mindstick.com/questionanswer/cb8cd851-038d-442a-a0f5-67184c0cd49c/images/259dfbb1-600d-442d-b283-0c6751966911.png)

### Answer by Ravi Misra

The color of selected text can be easily changed by using the CSS | ::selection Selector. In the below code, we have used **CSS ::selection** on **<h1>** and **<p>** element and set its colour as yellow with green background.

Below example implements the above approach:

## Example:

```html
<!DOCTYPE html>
<html lang='en'>

<head>
	<title>
		How to change the color of selected text using CSS?
	</title>

	<style>

		h1::selection {
			background: yellow;
			color: yellow;
		}

		p::selection {
			background: red;
			color: yellow;
		}
	</style>
</head>

<body>
	<div class='geeks'>

<h1>This is heading</h1>
		<p>
			केसरी (केसरी का मतलब संस्कृत में शेर होता है)की स्थापना तिलक ने 1881 में की थी। केसरी एक महान प्रोजेक्टर और भारतीय राष्ट्रीय स्वतंत्रता आंदोलन का संदेशवाहक साबित हुआ। यह राजसी अखबार जो कई ज्वार-भाटे(उतार-चढ़ाव) को पार कर चुका है, अभी भी द डेली केसरी(The Daily Kesari) के नाम से चल रहा है। मराठा को भी तिलक द्वारा तत्कालीन राष्ट्र में प्रचलित विभिन्न स्थितियों को अपने लोगों के सामने उजागर करने के लिए शुरू किया था। पत्रिकाओं का मुख्य उद्देश्य लोगों के मन को स्व-शासन की आवश्यकता के लिए प्रेरित और प्रज्वलित करना था और उनके अधिकारों के लिए लड़ना था।

इन अखबारों को शुरू कराने में बहुत से लेखकों का योगदान रहा है जैसे - निबन्धमाला के लेखक विष्णुशास्त्री चिपलूनकर, लोकमान्य बाल गंगाधर तिलक और गोपाल गणेश अगरकर के साथ महादेव बल्लाल नामजोशी, वामन एस आप्टे और गणेश के. गर्दे आदि महान विभूतियों ने मिलकर यह समाचार पत्र की शुरुआत –
		</p>
	</div>
</body>

</html>
```


---

Original Source: https://answers.mindstick.com/qa/93782/how-to-change-color-after-select-a-text-or-line

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
