content
property in combination with HTML and Unicode to enhance web page design.content
with Textcontent
to Different HTML ElementsThe CSS content
property is used to insert generated content into an element. It is often used with the ::before
and ::after
pseudo - elements. For example, you can use it to add text, images, or other content before or after an existing HTML element without modifying the HTML structure.
p::before {
content: "Note: ";
}
HTML is the standard markup language for creating web pages. It consists of elements, which are represented by tags. For example, the <p>
tag is used to define a paragraph, and the <h1>
tag is used for the main heading of a page.
<h1>My Web Page</h1>
<p>This is a paragraph.</p>
Unicode is a universal character encoding standard that aims to represent every character from every language, as well as symbols, emojis, and more. Each character in Unicode has a unique code point, which can be represented in different forms. For example, the code point for the copyright symbol is U+00A9.
content
with TextYou can use the content
property to add simple text before or after an element.
a::after {
content: " (external link)";
color: gray;
}
<a href="https://example.com">Visit Example</a>
To use Unicode characters in CSS content
, you need to use the escape sequence. The escape sequence for a Unicode character starts with a backslash (\
) followed by the hexadecimal code point.
li::before {
content: "\2022"; /* Unicode code point for bullet point */
color: blue;
margin-right: 5px;
}
<ul>
<li>Item 1</li>
<li>Item 2</li>
</ul>
content
to Different HTML ElementsThe content
property can be applied to various HTML elements. For example, you can use it with headings to add decorative elements.
h2::before {
content: "\27A4"; /* Unicode code point for right - pointing arrow */
margin-right: 10px;
}
<h2>Section Title</h2>
Many common icons can be represented using Unicode characters. For example, you can use Unicode to create a social media icon set.
.social - icon::before {
font - size: 24px;
margin: 5px;
}
.facebook::before {
content: "\f09a"; /* Font Awesome - like Unicode for Facebook icon */
}
.twitter::before {
content: "\f099"; /* Font Awesome - like Unicode for Twitter icon */
}
<div class="social - icon facebook"></div>
<div class="social - icon twitter"></div>
You can use the content
property to create tooltips for elements.
span.tooltip::after {
content: attr(data - tooltip);
display: none;
position: absolute;
background - color: black;
color: white;
padding: 5px;
border - radius: 3px;
}
span.tooltip:hover::after {
display: block;
}
<span class="tooltip" data - tooltip="This is a tooltip">Hover me</span>
As shown earlier, you can use the content
property to generate custom list markers.
ol.custom - list li::before {
content: counter(list - item) ". ";
counter - increment: list - item;
font - weight: bold;
}
<ol class="custom - list">
<li>First item</li>
<li>Second item</li>
</ol>
content
property is meaningful and accessible to screen readers. For example, if you use Unicode icons, provide alternative text.content
property and the Unicode characters you are using. Most modern browsers support these features, but older browsers may have limitations.The combination of CSS content
property, HTML, and Unicode offers a powerful way to enhance the visual appeal and functionality of web pages. By understanding the fundamental concepts, usage methods, common practices, and best practices, developers can create more engaging and accessible web experiences. Whether you are adding simple text, custom icons, or tooltips, these technologies provide a flexible and efficient way to customize your web pages.
content
property:
https://developer.mozilla.org/en-US/docs/Web/CSS/content