![]() |
In web development, setting different text colors for a specific paragraph can be useful for highlighting certain content. We will see how to set different text colors for a specific paragraph using CSS. This can help make certain parts of your text stand out. Tip: Prefer External Stylesheets for easier maintenance and updates. Below are the approaches to set text color for a specific paragraph using CSS: Using Inline CSSWe can use inline CSS to style HTML elements directly. To set text color for a specific paragraph, we add the “style” attribute to the paragraph tag and specify the “color” property. Note: The inline CSS can make your HTML harder to maintain if overused. Syntax:<p style="color: red;">Your text here</p> Example: This example uses inline CSS to set the color for a paragraph.
Output: ![]() Output Using a Class or ID SelectorTo apply specific styles to multiple paragraphs consistently, create a class or ID selector in your CSS file. Assign this selector to the paragraphs in your HTML markup for easy customization. Syntax:<!-- Using class selector --> Example: This example uses class and ID selectors to set colors for paragraphs.
Output: ![]() Output Using :nth-child() pseudo-classThe Syntax:parent Element : nth-child(n) { Example: This Example uses the :nth-child() pseudo-class to set text color for paragraph.
Output: ![]() Output |
Reffered: https://www.geeksforgeeks.org
CSS |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 12 |