×

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 Vertical Align

Vertical Align The vertical align CSS property describes the cell box of the table and an inline alignment vertically. This property is a self-explanatory and an essential property in CSS. But,...

2 minutes read.

CSS Variables

CSS Variables These variables of CSS are applied to add the custom property values to our various web-pages. The custom properties are often called as CSS variables or cascading variables. Various...

4 minutes read.

CSS Background-blend-mode

Background-blend-mode The background-blend-mode property sets a blend mode of the component’s every background layer (color/image). It illustrates how the element background image blends well with the element background color. We can...

9 minutes read.

CSS Images

Images in CSS: Images are a critical part of a web application. It includes various types of images in the web application that cannot be recommended. However, it is essential...

4 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.

Divi in CSS

Divi is popular WordPress themes due to its versatility and user-friendly interface. It includes a built-in page builder for sophisticated design options and an assortment of customization features to help...

9 minutes read.

What is CSS

CSS stands for Cascading Style Sheet. It gives an additional style to the HTML document. A cascading style sheet is a language that is designed to define the document formatting...

3 minutes read.

Hover condition for a:before and a:after in CSS

In CSS, :after and :before are used to add content after and before the element. The CSS pseudo-class is used to add some styling effect to the webpage. We can change...

4 minutes read.

CSS Page-break-after Attribute

Page-break-after Attribute As its name implies, the page-break-before property is applied to include page break after any element, at the time of printing a document. It adds the page break after...

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 Pseudo-elements

Pseudo-elements The pseudo-classes in CSS can be represented as any keyword which is connected to the selector that represents any selected element’s unique state. On the other hand, pseudo-elements can be...

6 minutes read.

How to resize an image in CSS

How to resize an image in CSS? The resize image attribute is used in responsive web design to resize images to fit within the div container automatically. The resize image attribute...

3 minutes read.

Css Box Model

Introduction The Box Model property of CSS is used for design and layout of an html page. In CSS, all the elements has a rectangular box around it, you have to...

5 minutes read.

How to center a table in CSS

The table is used to store and arrange the data in tabular format. The data here can be of any form like text, image, links, etc. The table is made...

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 Text-Transform Property

Text-Transform in CSS The text-transform property permits us to alter the text case. It controls the capitalization of the text. This property is employed to design the text appearance in every...

3 minutes read.

CSS User Interface

Introduction User Interface can be defined as series of visual elements like screens, buttons, forms that help the user interact with the software application or hardware device. CSS User Interface allows the...

6 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 Clip

CSS Clip The Clip property in CSS describes the element’s visible area. It applies over the elements which are absolutely positioned (position: absolute ;). Generally, it is used when an image...

2 minutes read.

Grid Vs Flexbox in CSS

Grid: - CSS Grid Layout is a 2D grid-based matrix-based layout method with columns and rows that simplifies web pages created by eliminating the need for floats and placement. A grid layout, like...

4 minutes read.