CSS Introduction

CSS Tutorial What is CSS CSS Syntax CSS Selector How to include CSS CSS Comments

CSS Attributes

CSS Background CSS Border CSS Display CSS Float CSS Font CSS Color CSS Hover CSS Important CSS Line-height CSS Margin CSS Opacity CSS Filter CSS Images CSS Overflow CSS Padding CSS Position CSS Vertical align CSS White space CSS Width Word-wrap in CSS Box-shadow in CSS Text-transform in CSS CSS Outline CSS Visibility CSS Counters CSS Clear fix CSS Icons CSS Justify-content Text-decoration in CSS CSS Lists CSS nth selector CSS Sticky CSS Background-clip CSS Checkbox-style CSS Letter-spacing CSS Navigation bar CSS Overlay CSS Root CSS Specificity CSS Text-indent CSS Text-stroke CSS Zoom CSS Order CSS Descendent selector CSS Clip CSS calc() CSS Background-blend-mode CSS radio-button CSS Superscript and subscript CSS Text-effects CSS Text-align CSS Variables CSS Page-break-before CSS Page-break-inside CSS Page-break-after CSS Content property CSS Word-spacing CSS Animation CSS @keyframes rules CSS Pseudo-classes CSS Pseudo-elements CSS Radial-gradient CSS Translate CSS Gradients CSS z-index CSS Loaders CSS Units CSS Transition CSS Masking CSS Arrow CSS Pagination

Questions

What is Bootstrap CSS What is CSS used for How to center a table in CSS What is a CSS File How to center a button in CSS How to change background color in CSS How to change the font in CSS How to change font size in CSS How to resize an image in CSS How to get rid of bullet pioints in CSS Is CSS a programming language How to edit CSS in WordPress How to use google fonts in CSS How to create blinking text using CSS How to Set Space between the Flexbox Is CSS a Programming Language

Difference

Difference between HTML and CSS Grid Vs Flexbox in CSS Difference between CSS Grid and CSS Flexbox

Misc

Create a 3D text effect using HTML and CSS Hover condition for a:before and a:after in CSS Bem CSS Boder Types CSS Features of CSS Font Face CSS Image Overlay CSS B Tag CSS Carousel CSS CSS Arrow CSS Focus Flex Grow in CSS Bem CSS Features of CSS Font Face CSS

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