×

CSS Functions

CSS functions are used for different CSS properties. Every front-end developer should have knowledge of all CSS functions. It makes the coding easier.

FunctionsExplanation
attr().It returns the value of an attribute of the selected element, which is quite significant.
calc().Allows you to specifically perform calculations to determine CSS property values, kind of contrary to popular belief. Calculate any mathematical functions.
conic - gradient().It creates a conic gradient subtly.
counter().Returns the very current value of the named counter in a major way.
cubic - bezier().Explains a cubic Bezier curve, kind of contrary to popular belief.
hsl().Explains colors using the Hue-Saturation-Lightness model (HSL) subtly. This function describes the level of colors by using hsl.
hsla().Explains colors using the Hue-Saturation-Lightness-Alpha model (HSLA) in a major way.
linear - gradient().This function works as an inbuilt function in CSS which is utilized to set the linear gradient as background picture.
max().Uses the largest value, from a comma-separated list of values, as the property value. Set the max of nos. Given.
min().This function works in css is utilized to extract the mini value from a bunch of comma-separated values. 
repeating - conic - gradient().Repeats a conic gradient, which generally is quite significant.
repeating - linear - gradient().Repeats a linear gradient, definitely contrary to popular belief. 
repeating - radial - gradient().Subtly repeats a radial gradient.  
rgb().Explains colors using the Red-Green-Blue model (RGB) subtly. Describes the level of color.
rgba().Explains colors using the Red-Green-Blue-Alpha model (RGBA). Describes the levels of color.
var().Inserts the value of a custom property, which is fairly significant.
url()Function is used to set list-style, image, cursor, mask, mask-image, background-image, content, list-style-image.
blur()Blur effect is applied by this function.
brightness()The brightness is adjust by this function.
opacity()Opacity of the element is set .
not()Apply the style to image (img) element not having .no-p class.

Some functions for the most part are described/explained using small code(syntax) are as follows :

background: url(“image.png/image.jpg”)

height: calc(90%-50px)

      -    var( <custom-property-name> , <declaration-value>? )

      -    color: rgb(0,0,0)

color: rgba(0,0,0,1)

color: hsl(0,0,0)

.body{
          filter: blur(100px);
              }

.h2{
       filter: brightness(40%);
    }

img {
      filter: opacity(40%);
   }

img:not(.no-p){
           padding: 0;  }

Some examples with its code and output:

1. calc() function-

            code is as follows:

<!DOCTYPE html>
           <html>
           <head>
           <style>
             #div1 
              { position: absolute;
                  left: 45px;
                  width: calc(50% - 50px);
                  border: 1px solid black;
                  background-color: lightgray;
                  padding: 4px;
                  text-align: center;
               }
               </style>
               </head>                       
    <body>
      <h1> The calc() function  in CSS </h1>
      <p> This is the short paragraph which creates div , <br>
             with a 40px gap between both sides of 
             the div and edge of window: </p> 
      <div id=”div1”>write something text here..</div>
      </body>
      </html>

Output 1 for the above calc() code is:

CSS Functions

2. rgb() function-

code is as follows

<!DOCTYPE html>
                 <html>
                 <head>  
<style>
#p1 { background-color: rgb(128 , 0 , 128) ; } 
#p2 { background-color: rgb (255 , 255, 0) ; }
#p3 { background-color: rgb (255, 0 , 255 ) ; }
#p4 { background-color: rgb (192,192 ,192 ) ; }
#p5 { background-color: rgb (0 , 255, 0) ; }
#p6 { background-color: rgb (0 , 128, 128) ; }
#p7 { background-color: rgb ( 255, 127 , 80  ) ; }
</style>
</head>
<body>
<h1>The rgb() Function in CSS </h1>
<p> Different rgb colors : </p> 
< p id=”p1”> Purple </p>
< p id=”p2”> Yellow </p>
< p id=”p3”> Blue  </p>
< p id=”p4”> Silver </p>
< p id=”p5”> Lime </p>
< p id=”p6”> Teal </p>
< p id=”p7”> Coral </p>
</body>
</html>

Output for the above rgb() code is:

CSS Functions

3. rgba() function

code is as follows :

<!DOCTYPE html>
<html>
<head>  
<style>
#p1 { background-color: rgba(198, 0 , 198,0.3 ) ; } 
#p2 { background-color: rgba(20, 214, 20, 0.836); }
#p3 { background-color: rgba(0,0,255,0.3 ); }
#p4 { background-color: rgba(192,192,192,0.3 ) ; }
#p5 { background-color: rgba(255, 255, 0, 0.884) ; }
#p6 { background-color: rgba(240, 84, 12, 0.795) ; }
#p7 { background-color: rgba(255, 0, 0, 0.473) ; }
</style>
</head>
<body>
<h1>The rgb() Function in CSS </h1>
<p> Different rgb colors : </p> 
<p id="p1"> Purple </p>
<p id="p2"> Green </p>
<p id="p3"> Blue </p>
<p id="p4"> Light blue </p>
<p id="p5"> Yellow </p>
<p id="p6"> Orange </p>
<p id="p7"> Pink </p>




</body>
</html>

Output for the above rgba() code is:

CSS Functions

4. blur() function

code is as follows :

<!DOCTYPE html> 
<html> 
<head> 
    <title>The blur() Function in CSS </title> 
 <style>
        h1 {
            color: pink ;
             }
  body {
            text-align:center;
        }
        .blur_effect {
            filter: blur(4px);
        }
</style>
</head> 
<body> 
    <h1>Flower photograph </h1> 
    <h2>CSS blur() function</h2>
   <img class="blur_effect" src = "flower.png"
        alt="Flower image"> 
</body> 
</html>

Output for the above blur() code is:

CSS Functions

Related Topics

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.

How To Use CSS

You can use CSS(Cascading Style Sheet) in four ways. These are given below: The given above CSS type, in which various technique will be used. These are different from each other and...

2 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 Line Height

CSS Line Height: This property in CSS can be used to describe the line box’s minimal height inside the element. It sets-up the distinction among two lines in our content. It...

3 minutes read.

CSS Descendant Selector

Descendant Selector The Descendant selector in CSS is used to match the descendant components of a particular component. The term descendant depicts nested in whatever place, inside a DOM tree. This...

2 minutes read.

CSS Align

CSS Center Align Elements CSS center align is used to create align by using block element. You should specify margin: auto;properties. The element will take up the specified width and the remaining space....

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.

CSS Introduction

CSS stands for Cascading Style Sheet. It is a design language which is used to design the web pages. It was developed by Håkon Wium Lie on October 10, 1994. It provides...

1 minute read.

CSS Display

CSS Display: The CSS Display property is one of an essential property among all other properties of CSS. The display property specifies how the HTML elements should be displayed on...

4 minutes read.

Cascading Style Sheet

CSS refers to the Cascading Style Sheet. CSS is a form of a programming language. In other words, CSS is a language of the style sheet that is utilised for...

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

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.

How to change background color in CSS

How to change background color in CSS? The background-color property in CSS would be used to specify the color of an element's background. As the element's background, it uses solid colors. The...

3 minutes read.

CSS Overlay

CSS Overlay: It measures to cover-up something’s surface along with a coating. CSS overlay sets anything over the top area of other things. It creates a web-page more attractive. The...

8 minutes read.

CSS 3D Transform

Introduction To understand 3D transformation property of transform you need to first understand the difference between 2D and 3D transform. 2D transform is a CSS effect which transforms the elements according to...

6 minutes read.

CSS Width

CSS Width The width property in CSS sets the content width of area of the element. These properties do not provide margin and border features. It is used to set the...

1 minute read.

CSS Lists

CSS Lists: Several properties are available in CSS that are used to manage the lists. Lists are distributed as ordered and unordered kind of lists. The ordered lists provide the...

7 minutes read.

CSS Box-shadow

CSS Box-shadow This property is referred to include effects as shadow-like around an element’s frame. Syntax box-shadow: h-offset v-offset blur spread color |inset|inherit|none; Property values Following are the various property values which can be used...

3 minutes read.

What is Bootstrap CSS?

Bootstrap: - Bootstrap is a CSS framework that is free to use and is used for the front-end development of the website in a faster and easier way. Bootstrap was released as...

3 minutes read.

Internal CSS

What is CSS? CSS stands for Cascading Style Sheet.CSS is used to apply styling the HTML elements.With CSS user can add or change color, font-size and font-family. It also helps user...

4 minutes read.