
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Adding HTML Entities Using CSS Content
Adding HTML entities using CSS content allows you to insert special characters or symbols without changing HTML structure directly. In HTML and CSS, entities are special characters that have reserved meanings or representations. They are typically used to display characters that are not readily available on a standard keyboard or, to represent special symbols or characters with specific semantic meanings.
CSS provides a way to add HTML entities using the content property. The content property is primarily used with pseudo-elements, such as ::before and ::after selectors, to insert content before or after an element. In this article, we are having some text written in our HTML document, our task is to add HTML entities using CSS content property.
Steps to ADD HTML Entities Using CSS content
We will be following below mentioned steps to Add HTML entities with the CSS content property:
- First, we need to create an HTML file, then use the <body> tag and add some content in any text tags such <p> and <h1>.
- Then add CSS using the ::after and ::before pseudo-elements. Then add the content property.
- Then we can either use HTML entity or their unicode to add HTML entities.
Example 1
In the following example, we are adding HTML entity "<" (greater than) and ">" (less than) with the CSS content property.
<html> <head> <title> Adding HTML entities using CSS content </title> <style> p::before { content: '<'; background-color: #04af2f; color: white; font-weight: bold; } p::after { content: '>'; background-color: #04af2f; color: white; font-weight: bold; } p { color: #04af2f; } </style> </head> <body> <h3> Adding HTML entities using CSS content </h3> <p>Tutorialspoint</p> </body> </html>
Example 2
Here, we are adding the same HTML entities as in the previous example with their corresponding Unicode.
<html> <head> <title> Adding HTML entities using CSS content </title> <style> p::before { content: '\003C'; background-color: #04af2f; color: white; font-weight: bold; } p::after { content: '\003E'; background-color: #04af2f; color: white; font-weight: bold; } p { color: #04af2f; } </style> </head> <body> <h3> Adding HTML entities using CSS content </h3> <p>Tutorialspoint</p> </body> </html>
Conclusion
In this article we understood how we can add HTML entities using CSS content property. It is a very simple process where we use content property with either HTML entities or their corresponding Unicode to add HTML entity.