×

CSS Content Property

Content Property

The content attribute produces dynamic content. It can be applied with any pseudo-element ::after and ::before. These CSS properties are entirely supported inside every browser and applied to include the content over the web page.

It can replace an item with any produces value.

Syntax:

content: normal | none | counter | string | attr | open-quote | close-quote | no-close-quote | no-open-quote | url | initial | inherit;  

 Property Values

This property of CSS has a lot of values which are specified as follows:

ValuesDescription
normalThis value is used as a default value.
noneIt can’t set any content.
counterThis value can be used to set any content as a counter. Generally, it is a number. This value can be shown with counters() or counter() function.
stringThis property value sets the string value. This value must always be wrapped inside quotation masks. These values produce the string before or after any HTML element.
attrThis property value includes any specified element’s value before or after any element. The empty string can be added, if the selectors do not contain any particular attribute.
open-quoteThis value includes any opening quotation mark. It can be used to set the text to be the opening quote.
close-quoteThis value includes any closing quotation mark. It can be used to set the text to be the closing quote.
no-close-quoteWhen a closing quote is specified, it is applied to eliminate the specified closing quote against the text.
no-open-quoteWhen an opening quote is specified, it is applied to eliminate the specified opening quote against the text.
urlThis property value sets the text into the media, which can be audio, video, image, and others.
initialThe initial value sets the Content property to the default value.
inheritThis value acquires the property against its parent item.

Let’s take a few examples of the above-discussed values as below:

Example: none and normal value

In the following example, we use pseudo-element ::before to add the content “Welcome” before a paragraph element. The content can’t be inserted into those elements of a paragraph where we used none and normal values.

<!DOCTYPE html>
<html>
<head>
<title> Content Property </title>
<style>
body
{
text-align: center;
}
p
{
font-size: 25px;
}
p::before
{
content: "Welcome";
}
#para::before
{
content: none;
}
#para1::before
{
content: normal;
}
</style>
</head>
<body>
<h1> Content Property </h1>
<h2> Using content: none; and content: normal; </h2>
<p> to this Page </p>
<p id= "para"> It is the paragraph using <b> none </b> value. </p>
<p id= "para1"> It is the paragraph using <b> normal </b> value. </p>
</body>
</html>

Output:

CSS Content Property

Example: url and string value
In the following example, the content “Hello all!! Welcome” will be inserted with the use of the content attribute and pseudo-element ::before.

<!DOCTYPE html>
<html>
<head>
<title> Content Property </title>
<style>
body
{
text-align: center;
}
p
{
font-size: 25px;
}
p::before
{
content: “Hello all!! Welcome”;
}
#para::before
{
content: url("img.png");
}
#para1::before
{
content: url("img.png");
}
</style>
</head>
<body>
<h1> Content Property </h1>
<h2> Using content: url(); and content: string; </h2>
<p> to this Page </p>
<p id= "para"> It is the paragraph using <b> url() </b> value. </p>
<p id= "para1"> It is another paragraph using <b> url() </b> value. </p>
</body>
</html>

Output:

CSS Content Property

Example:  close-quote and open-quote value

The close-quote can only be applied with the open-quote as follows:

<!DOCTYPE html>
<html>
<head>
<title> Content Property </title>
<style>
body
{
text-align: center;
}
p
{
font-size: 25px;
}
p::before
{
content: open-quote;
}
p::after
{
content: close-quote;
}
</style>
</head>
<body>
<h1> Content Property </h1>
<h2> Using content: open-quote; and content: close-quote; </h2>
<p> Welcome to this Page </p>
<p> It is a paragraph. </p>
</body>
</html>

Output:

CSS Content Property

Example: no-close-quote and no-open-quote value

In the following example, we use the close-quote and the open-quote over the paragraph items, and we use the .para class over the paragraph on the no-close-quote and the no-open-quote.

<!DOCTYPE html>
<html>
<head>
<title> Content Property </title>
<style>
body
{
text-align: center;
}
p
{
font-size: 25px;
}
p::before
{
content: open-quote;
}
p::after
{
content: close-quote;
}
p.para::before
{
content: no-open-quote;
}
p.para::after
{
content: no-close-quote;
}
</style>
</head>
<body>
<h1> Content Property </h1>
<h2> Using content: no-open-quote; and content: no-close-quote; </h2>
<p> Welcome to this Page </p>
<p class= "para"> It is a paragraph. </p>
</body>
</html>

Output:

CSS Content Property

Example: attr() value

The function attr() allows us to add any particular element’s value. If any corresponding item does not include any attribute, any empty string can be returned.

In the following illustration, we are applying the function attr(), the link shown over the screen.

<!DOCTYPE html>
<html>
<head>
<title> Content Property </title>
<style>
body
{
text-align: center;
}
a::after
{
content: attr(href);
}
</style>
</head>
<body>
<h1> Content Property </h1>
<h2> The below link is shown with the use of <b> attr() </b> </h2>
<a href= https://www.tutorialandexample.com> Click Here!
</a>
</body>
</html>

Output:

CSS Content Property

Related Topics

CSS Units

CSS Units In CSS, there are so many units available to show the length’s measurement. A single unit of CSS is applied to examine the size of the property, which the...

5 minutes read.

How to center a button in CSS

How to center a button in CSS? In the tutorial, we will learn how to center a button in CSS. CSS (Cascading Style Sheets) gives an HTML web page the greatest possible...

4 minutes read.

CSS Comments

CSS Comments: Generally, comments in CSS are used to describe our code. Further, it will provide support to many users who are concerned with the code. Somewhat, these are ignored...

2 minutes read.

Difference between HTML and CSS

HTML HTML stands for HyperText Markup Language and is used to create web pages and websites and web applications, which means we can create static web pages. Html is a scripting...

3 minutes read.

CSS Important

CSS Important: CSS !important property is used to provide more importance, as compared to other CSS properties. The meaning of this property is “This is important.” This property enables CSS...

2 minutes read.

CSS Text-Overflow

Introduction: The text-overflow property of CSS is used to format the text which is overflowing the boundaries of the container. This property helps user to clip the text, to display the...

5 minutes read.

CSS Browser Support

The desk underneath lists of all CSS properties and the way each belongs to it is supported in the generally unique browsers: - The quantity to the right of the browser...

2 minutes read.

How to Set Space between the Flexbox

For managing layout on the Web, CSS Flexbox and CSS Grid are two excellent tools. Flexbox handles one-dimensional layouts quite well, whereas CSS Grid manages two-dimensional layouts with columns and...

4 minutes read.

How to get rid/remove of bullet pioints in CSS

We include a list of items on the web pages that were sometimes numbered and sometimes bulleted in various styles. In HTML, there are two kinds of lists: ordered and unordered...

3 minutes read.

CSS Content Property

Content Property The content attribute produces dynamic content. It can be applied with any pseudo-element ::after and ::before. These CSS properties are entirely supported inside every browser and applied to include...

5 minutes read.

CSS Zoom

CSS Zoom: Zoom property in CSS extents the content. This property controls the content’s level of magnification. Rather than the use of this CSS property, we may also apply the...

3 minutes read.

CSS Links

CSS Link is used to create styled link. There are various ways to implement it. Styling Links Link can be styled with CSS properties like color, font-family, background etc. Example: <!DOCTYPE html>   <html>   <head>   <style>   a {       color: red;   }   </style>   </head>   <body>   <p><b><a href="https://www.tutorialandexample.com"    target="_blank">This is a link</a></b></p>   </body>   </html> Try Now There are four...

2 minutes read.

CSS Superscript and Subscript

Superscript and Subscript To specify the superscript and the subscript text, HTML provides us two tags that are <sup> and <sub>. The superscript content looks in the shorter font and half...

2 minutes read.

CSS Letter-spacing

CSS Letter-spacing: Letter-spacing attribute is applied to manage the space among all letters within the block or element of the text. This property sets the behavior of the spacing between...

2 minutes read.

CSS Background Color

It is one of the CSS properties to apply styling to html elements.This property is used to apply the background color to any HTML element.The background of an element includes...

2 minutes read.

CSS @keyframes rule

CSS @keyframes rule It describes the rule of animation that depicts the properties of CSS for the components at every state along with the timeline. We may make the properties of complex...

4 minutes read.

CSS Transition

CSS Transition The transitions in CSS are influenced, included to modify the component from one design to another, without the use of the JavaScript or Flash. We should describe two of the...

2 minutes read.

CSS Text-align

Text-align The text-align property of CSS sets the table-cell box’s horizontal alignment or any block element. The text-align property is the same as the CSS property vertical-align but towards any horizontal...

1 minute read.

CSS Background-clip

CSS Background-clip: The background-clip property describes the background’s painting area. It limits an area where the image or color of the background appears by using any clipping box. Everything will...

2 minutes read.

How to make smooth bounce animation using CSS

The smooth bouncing animation project is done with the help of HTML and CSS. This project gives so much fun and excitement to the users. What is HTML? The HTML or HyperText...

2 minutes read.